Config Colors

Discussion in 'Plugin Development' started by plarsootje, Jun 15, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    plarsootje

    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 senderCommand cmdString CommandLabelString[] args) {
            if(
    CommandLabel.equalsIgnoreCase("rules")){
                List<
    Stringrules 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
    
     
  2. Offline

    ferrybig

    ChatColor.translateAlternateColorCodes('&', textToTranslate)
     
  3. Offline

    plarsootje

    and wath i need to put by textToTranslate
    ?
     
  4. Offline

    ferrybig

    the string where &<char> must be converted to the color string
     
  5. Offline

    plarsootje

    yeah and how can i do that for a list becuase there are a few strings
     
  6. Offline

    ferrybig

    it replaces al coler codes in the same invoction of the methode
     
  7. Offline

    plarsootje

    so like &<string>
    i just don't get it :S
     
  8. Offline

    ferrybig

    this code:
    Code:java
    1.  
    2. public String colorizeText(String string) {
    3. string = string.replaceAll("&0", ChatColor.BLACK+"");
    4. string = string.replaceAll("&1", ChatColor.DARK_BLUE+"");
    5. string = string.replaceAll("&2", ChatColor.DARK_GREEN+"");
    6. string = string.replaceAll("&3", ChatColor.DARK_AQUA+"");
    7. string = string.replaceAll("&4", ChatColor.DARK_RED+"");
    8. string = string.replaceAll("&5", ChatColor.DARK_PURPLE+"");
    9. string = string.replaceAll("&6", ChatColor.GOLD+"");
    10. string = string.replaceAll("&7", ChatColor.GRAY+"");
    11. string = string.replaceAll("&8", ChatColor.DARK_GRAY+"");
    12. string = string.replaceAll("&9", ChatColor.BLUE+"");
    13. string = string.replaceAll("&a", ChatColor.GREEN+"");
    14. string = string.replaceAll("&b", ChatColor.AQUA+"");
    15. string = string.replaceAll("&c", ChatColor.RED+"");
    16. string = string.replaceAll("&d", ChatColor.LIGHT_PURPLE+"");
    17. string = string.replaceAll("&e", ChatColor.YELLOW+"");
    18. string = string.replaceAll("&f", ChatColor.WHITE+"");
    19. return string;
    20. }
    21.  
    can be replaced by:
    Code:java
    1.  
    2. public String colorizeText(String string) {
    3. return ChatColor.translateAlternateColorCodes('&',string) ;
    4. }
    5.  
     
  9. Offline

    plarsootje

    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
     
  10. Offline

    plarsootje

    please someone help
     
  11. Offline

    Monowii

    Delete class : colorizeText
    And in rules command set :
    sender.sendMessage(s.replaceAll("(&([a-f0-9]))", "§$2"));
     
  12. Offline

    plarsootje

    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
     
  13. Offline

    ferrybig

    you know there is an "null" inside the config? if you mean the java "null" it would throw an exception
     
  14. Offline

    plarsootje

    i don't know but the string i changed changes to null but i don't have a error in the console
     
  15. Offline

    ferrybig

    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
     
  16. Offline

    plarsootje

    so when i change something in my config like &6hello the &6hello changes to null
     
  17. Offline

    ferrybig

    can you get the &6hallo good?
     
  18. Offline

    plarsootje

    How do you mean can you get the &6hallo good?
    he just turns the string to nulll
     
  19. Offline

    Monowii

  20. Offline

    plarsootje

  21. Offline

    plarsootje

    can someone help me ?
     
Thread Status:
Not open for further replies.

Share This Page