Get a color from a configuration file

Discussion in 'Plugin Development' started by NewDevOnTheBlock, Jun 3, 2015.

Thread Status:
Not open for further replies.
  1. Hi,

    Could anyone help me with getting a color from a configuration file?
    Code:
    color: SILVER
    That is an example of how I want to get the color. I have tried:
    Code:
    getConfig().getColor( "path" );
    getConfig().getColor( "path", Color default );
    I have also tried creating an instance of of Color by doing:
    Code:
    Color color = getConfig().getColor( "path" );
    But sadly none of this works.

    I was looking through the forum threads related to getColor, and some people suggest using getRGB. I can think of a way to use a HashMap to have the user put in something like SILVER, and convert it to its correct RGB color, but I'm also not sure how to store an RGB in a HashMap. Would that be considered a String if I were to do that?

    Thank you for reading and the help!
     
    Last edited: Jun 3, 2015
  2. Offline

    caderape

  3. @caderape Thank you for responding, but I'm looking for something more like
    Code:
    Color.valueOf( String );
    Which doesn't exist...

    This looks a little promising... As I think I would now be able to store this in a HashMap. Something like...
    Code:
    Map<String, Integer> map = new HashMap<Color, Integer>();
    for( Map.Entry<String, Integer> color : colors.entrySet() {
        //Magic
    }
    Color.fromRBG ( int RBG );
     
    Last edited: Jun 3, 2015
  4. Offline

    caderape

  5. Offline

    BagduFagdu

  6. @caderape Ok, so I was looking really hard at the Bukkit 1.8.3 API and Minecraft Formatting Codes. The RGB color it takes is actually a "complex" version of a Hexadecimal code.

    Take for instance the color WHITE. It's RGB code is 0xFF,0xFF,0xFF. #FFFFFF is white in Hex. Now a tougher one... NAVY which is 0x00,0x00,0x80 translates to #0000AA. I can figure all of them out, besides SILVER... So I guess I'll make a crazy algorithm to replace a String like NAVY to its correct color scheme.

    If anyone else has an idea on how to solve this that isn't as weird as the idea above then post it!
     
Thread Status:
Not open for further replies.

Share This Page