Getting the color of text on a sign.

Discussion in 'Plugin Development' started by Taco, May 28, 2012.

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


    This has me stumped. I cannot for the life of me figure out how to get the color on a sign. I've tried ChatColor.getLastColor() and it always seems to yield something different. Any help?
  2. Offline


    Use this:
    String line = sign.getLine(linenumber);
    if (line.contains("ChatColor."){
    //process colors here
  3. Offline


    I'm fairly certain that this won't work.
  4. Offline


    Are you trying to convert text on a Sign to color? EG. "&4Welcome" , will convert to "(RED)Welcome"

    To do this...
    String signToColor = ChatColor.translateAlternateColorCodes('&', sign.getLine(0))
    sign.setLine(0, signToColr);
    This code only works for the top like and can be easily converted to loop through the lines on a Sign.
  5. Offline


    I'm trying to get what color is already on the sign. Say if the sign has blue text, I want to detect the text as being blue.
  6. Offline


    Ok, I see. From what you have said, We need to detect the Color Char so, ( shows us that the COLOR_CHAT is '\u00A7'.

    So we can search the sign for that by using...
    //Try and Find the COLOR_CHAR
    Integer index = sign.getLine(0).indexOf(ChatColor.COLOR_CHAR.toString())
    if(index == -1) //Not Found
    //Get the Color after the COLOR_CHAR.
    String signColor = sign.getLine(0).substring(index, index+1);
    ^ This is 100% experimental, feel free to experiment with it. I remember using it some time ago.
  7. Offline


    I'll give that a shot. Thanks for the help!
Thread Status:
Not open for further replies.

Share This Page