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

    Taco

    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

    r0306

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

    Taco

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

    Wundark

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

    To do this...
    Code:
    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

    Taco

    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

    Wundark

    Ok, I see. From what you have said, We need to detect the Color Char so, (https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java) shows us that the COLOR_CHAT is '\u00A7'.

    So we can search the sign for that by using...
    Code:
    //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

    Taco

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

Share This Page