Skip to content

Commit

Permalink
add new routine to translate &color codes in config to in-game chatco…
Browse files Browse the repository at this point in the history
…lor codes.
  • Loading branch information
msudol committed Nov 5, 2018
1 parent 88757e0 commit d9a6a0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: com.pwn9.PwnChickenLay.PwnChickenLay
name: PwnChickenLay
version: 1.7
version: 1.8
author: tremor77
description: Control the chicken egg drop event and replace it with anything you want.
website: http://pwn9.com
Expand Down
13 changes: 13 additions & 0 deletions src/com/pwn9/PwnChickenLay/PwnChickenLay.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.util.List;
import java.util.Random;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -122,4 +124,15 @@ public static String getDate()
return s;
}

// function to colorize strings from the config
public static String colorize(String message)
{
return ChatColor.translateAlternateColorCodes('&', message);
}

// function to colorize strings from the config
public static List<String> colorize(List<String> message)
{
return message.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ public void doReplacement(World eworld, Location eLoc, String randomReplacement
getSpecialName = plugin.getConfig().getString("special."+specialReplacement+".name");

// set item meta display name
im.setDisplayName(getSpecialName);
im.setDisplayName(PwnChickenLay.colorize(getSpecialName));
}

// Lore
if (plugin.getConfig().isSet("special."+specialReplacement+".lore"))
{
getSpecialLore = plugin.getConfig().getStringList("special."+specialReplacement+".lore");

// set item meta lore
im.setLore(getSpecialLore);
// set item meta lore - colorize with list string
im.setLore(PwnChickenLay.colorize(getSpecialLore));
}

// Colors (if leather)
Expand Down

0 comments on commit d9a6a0a

Please sign in to comment.