How can i get color codes i tried with this code but the string changes to null can someone give me a working code i gonna post my main class command class and config below. thanks by advance main class: PHP: package me.test.main; import java.util.Arrays;import java.util.logging.Logger; import org.bukkit.configuration.file.FileConfiguration;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class ConfigTest extends JavaPlugin { public final Logger logger = Logger.getLogger("minecraft"); @Override public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Has been Disabled!"); } @Override public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled."); String[] rule = { "Rule1", "Rule2", "Rule3", "rule4", "rule5", "rule6" }; getConfig().options().copyDefaults(true); final FileConfiguration config = this.getConfig(); config.addDefault("Rules", Arrays.asList(rule)); config.addDefault("OnPlayerJoin", "Welcome to our server"); saveConfig(); } } command class : PHP: package me.test.main; import java.util.List; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.configuration.Configuration;import org.bukkit.entity.Player; public class CommandRules implements CommandExecutor { private ConfigTest plugin; public String colorizeText(String string) { string = string.replaceAll("&0", ChatColor.BLACK+""); string = string.replaceAll("&1", ChatColor.DARK_BLUE+""); string = string.replaceAll("&2", ChatColor.DARK_GREEN+""); string = string.replaceAll("&3", ChatColor.DARK_AQUA+""); string = string.replaceAll("&4", ChatColor.DARK_RED+""); string = string.replaceAll("&5", ChatColor.DARK_PURPLE+""); string = string.replaceAll("&6", ChatColor.GOLD+""); string = string.replaceAll("&7", ChatColor.GRAY+""); string = string.replaceAll("&8", ChatColor.DARK_GRAY+""); string = string.replaceAll("&9", ChatColor.BLUE+""); string = string.replaceAll("&a", ChatColor.GREEN+""); string = string.replaceAll("&b", ChatColor.AQUA+""); string = string.replaceAll("&c", ChatColor.RED+""); string = string.replaceAll("&d", ChatColor.LIGHT_PURPLE+""); string = string.replaceAll("&e", ChatColor.YELLOW+""); string = string.replaceAll("&f", ChatColor.WHITE+""); return string; } public CommandRules(ConfigTest plugin) { this.plugin = plugin; } public static Player p; Configuration config; @Override public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) { if(CommandLabel.equalsIgnoreCase("rules")){ List<String> rules = plugin.getConfig().getStringList("Rules"); for (String s : rules){ sender.sendMessage(colorizeText(s)); } } return false; } } config : HTML: TEXT1: hallo Rules: - Rule1 - Rule2 - null - rule4 - rule5 - rule6 OnPlayerJoin: Welcome to our server
this code: Code:java public String colorizeText(String string) { string = string.replaceAll("&0", ChatColor.BLACK+""); string = string.replaceAll("&1", ChatColor.DARK_BLUE+""); string = string.replaceAll("&2", ChatColor.DARK_GREEN+""); string = string.replaceAll("&3", ChatColor.DARK_AQUA+""); string = string.replaceAll("&4", ChatColor.DARK_RED+""); string = string.replaceAll("&5", ChatColor.DARK_PURPLE+""); string = string.replaceAll("&6", ChatColor.GOLD+""); string = string.replaceAll("&7", ChatColor.GRAY+""); string = string.replaceAll("&8", ChatColor.DARK_GRAY+""); string = string.replaceAll("&9", ChatColor.BLUE+""); string = string.replaceAll("&a", ChatColor.GREEN+""); string = string.replaceAll("&b", ChatColor.AQUA+""); string = string.replaceAll("&c", ChatColor.RED+""); string = string.replaceAll("&d", ChatColor.LIGHT_PURPLE+""); string = string.replaceAll("&e", ChatColor.YELLOW+""); string = string.replaceAll("&f", ChatColor.WHITE+""); return string; } can be replaced by: Code:java public String colorizeText(String string) { return ChatColor.translateAlternateColorCodes('&',string) ; }
I have place it in my code but again the string changes to null in my config maby there is something with my main class
Delete class : colorizeText And in rules command set : sender.sendMessage(s.replaceAll("(&([a-f0-9]))", "§$2"));
no it's still turns to null maby there is something with my main class? and i tried with a normal string and there it deletes the word after the color code in the config
you know there is an "null" inside the config? if you mean the java "null" it would throw an exception
is it null when you get it from config? EDIT: also, you returning false, even the command itzelf succeded, thats not good behavor for other plougins that hook into your plugin
Easy way : http://pastie.org/private/aoljmfgfruzr060rmpiha And in config.yml : http://pastie.org/private/yau3fxwspst3jyxdjspugg