Solved Translate ChatColor into Color

Discussion in 'Spigot Plugin Development' started by TheL0w3R, Jun 23, 2016.

  1. Hi, is there a method to translate, for example ChatColor.GREEN to Color.LIME? Color.GREEN equals ChatColor.DARK_GREEN, it's very confusing.

    Hope I explained it well and thanks!! :)
     
  2. There is not a method directly available in the Spigot API (iirc).
    You have to make your own translation method like shown below, which might need modification depending on your taste on the ChatColor to Color.

    Code (Text):
        public static Color translateChatColorToColor(ChatColor chatColor)
        {
            switch (chatColor) {
                case AQUA:
                    return Color.AQUA;
                case BLACK:
                    return Color.BLACK;
                case BLUE:
                    return Color.BLUE;
                case DARK_AQUA:
                    return Color.BLUE;
                case DARK_BLUE:
                    return Color.BLUE;
                case DARK_GRAY:
                    return Color.GRAY;
                case DARK_GREEN:
                    return Color.GREEN;
                case DARK_PURPLE:
                    return Color.PURPLE;
                case DARK_RED:
                    return Color.RED;
                case GOLD:
                    return Color.YELLOW;
                case GRAY:
                    return Color.GRAY;
                case GREEN:
                    return Color.GREEN;
                case LIGHT_PURPLE:
                    return Color.PURPLE;
                case RED:
                    return Color.RED;
                case WHITE:
                    return Color.WHITE;
                case YELLOW:
                    return Color.YELLOW;
                default:
                break;
            }
           
            return null;
        }
     
  3. I'm guessing this is for a config, so you might want to do something like this:


    Code (Text):
    player.sendMessage(translation(configString) + "Woah");

    public ChatColor translation(String config){
    If(config.equalsignorecase("color.green") return ChatColor.GREEN;
    }
    I don't really get want you want :p. I wrote this on a phone, so it's gonna look awful. Also, I've been on vacation for the past 3 weeks, so I'm quite rusty :oops:.
     
    #3 tokyojack, Jun 23, 2016
    Last edited: Jun 23, 2016
  4. May I just ask, why you need this? Just a small question :3
     
    • Agree Agree x 1
  5. ^
     
    1. Create final class with a private constructor
    2. Add Map field and translate method
    3. Register mappings in static initialiser
    4. Invoke translate when required
    5. ???
    6. Profit
     
  6. Make a class that implements the ChatColor methods
     
  7. I need it because I need to get the same color of a ChatColor to send fireworks, as them doesn't work with ChatColors, If ChatColor had a method like getRGB() I could use it to create a new Color from them, guess I'll need to translate them with a switch statement :/
    Anyways, thanks :)
     
  8. use the Color class not the ChatColor enum for launching the fireworks. As you can see ChatColor.
     
  9. There's no method that I'm aware of. But if your problem is to launch a firework with the exact same color as the colors on the chat, you can simply use this table as reference.
    Having the values, you can create a color with Color#fromRGB and set it to your firework.
     
  10. Heres something to help you find the RGB & hex values for each chat color I made so I can get particle colors to match chat colors:

    [​IMG]
     
  11. Thanks a lot, fixed my problem! :D