Solved How to convert String to Color

Discussion in 'Plugin Development' started by FluffyNarwhals, Apr 26, 2013.

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

    FluffyNarwhals

    In my plugin, I give the user the ability to change the colors of things in the config file. How do I take the String (whatever they put in (Ex. blue)), and make it a Color? Thanks!
     
  2. Offline

    ZeusAllMighty11

    If color is an enum, then
    Color.valueOf(String)
     
  3. Offline

    Tirelessly

    String colored = ChatColor.translateAlternateColorCodes("&", stringWithCodes)
     
  4. Offline

    FluffyNarwhals

    I need to convert a string, like "blue", to a Color.BLUE or whatever

    I need to convert a string, like "blue", to a Color.BLUE or whatever

    NEVER MIND! I FIXED IT! All I did is created a method that returned a Color and inputted a String, and it will check the config file option that has that string input, and return the color it equals! That's confusing:
    Code:
    if(config.equalsIgnoreCase("black")){
                   
                    return Color.BLACK;
                   
                }
    Something like that!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  5. FluffyNarwhals I do not know if you still need it and if you are still active but if you were trying to get a color from a config file, you can use config.getColor(path);
     
  6. Offline

    tremor

    Lionhard - i'm trying to use this config.getColor(path) myself, having trouble getting it to work.. what goes in the config part?
    lets say path is mycolor
    config.yml
    mycolor: WhatGoesHere?
     
  7. Offline

    Garris0n

    Try config.setColor() and see what it does.
     
  8. Offline

    tremor

    no setColor method for configuration files sadly. I believe its an enum of some kind but.. i've literally tried everything and nothing works.
     
  9. tremor There goes either BLUE fo r example or ChatColor.BLUE or Color.BLUE i suppose.
     
  10. Offline

    tremor

    Lionhard - I solved my issue, turns out I needed the hex equivalent with the leading 0x###### to do it the way I was trying.
     
  11. tremor lolz, ok. Good that it works for you now. ;)
     
Thread Status:
Not open for further replies.

Share This Page