Getting a ChatColor from a String

Discussion in 'Plugin Development' started by oyasunadev, Sep 29, 2011.

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

    oyasunadev

    EDIT: FIGURED IT OUT!

    Code:
    String[] colors = {"aqua", "black", "blue", "darkaqua", "darkblue", "darkgray", "darkgreen", "darkpurple",
                                "darkred", "gold", "gray", "green", "lightpurple", "red", "white", "yellow"};
                        ChatColor[] colorsC = {ChatColor.AQUA, ChatColor.BLACK, ChatColor.BLUE, ChatColor.DARK_AQUA,
                                ChatColor.DARK_BLUE, ChatColor.DARK_GRAY, ChatColor.DARK_GREEN, ChatColor.DARK_PURPLE,
                                ChatColor.DARK_RED, ChatColor.GOLD, ChatColor.GRAY, ChatColor.GREEN,
                                ChatColor.LIGHT_PURPLE, ChatColor.RED, ChatColor.WHITE, ChatColor.YELLOW};
                        int i = 0;
    
                        if(player.hasPermission("ic.setname.allow"))
                        {
                            String format = args[1];
    
                            for(final String s : colors)
                            {
                                if(player.hasPermission("ic.setname." + s) || player.hasPermission("ic.setname.allcol"))
                                {
                                    format = format.replaceAll("%" + s + "%", colorsC[i].toString());
    
                                    i = i + 1;
                                }
                            }
     
  2. replaceAll is for regular expressions. I don't remember if % is a special char in a Java Regex, but you should still use replace(String, String) for basic Strings.
    Also, I don't think you need to strip colors on your self-defined Strings that only contain color names.
     
  3. Offline

    Feed_Dante

    sohardhun15 likes this.
  4. Please edit the title :)
     
Thread Status:
Not open for further replies.

Share This Page