How to see if line on sign has color?

Discussion in 'Plugin Development' started by Milkywayz, Apr 3, 2012.

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

    Milkywayz

    Hey my new plugin checks if someone wrote [LevelUp] on the first line and after some other stuff it sets the sign color to blue by "&1[LevelUp]". I need to use:
    PHP:
    if(s.getLine(0).equalsIgnoreCase("[LevelUp]")){  
    To make sure when they right click the sign its the right sign. And when i used this, it didnt work. When i tried:
    PHP:
    if(s.getLine(0).equalsIgnoreCase("&1[LevelUp]")){  
    It still didnt work. I've seen how essentials does it but it uses a weird format built into their essentials api.
     
  2. Offline

    Taco

    Try changing this:

    Code:
    if(s.getLine(0).equalsIgnoreCase("&1[LevelUp]"))
    To this:

    Code:
    if(s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[LevelUp]"))
     
  3. Offline

    PandazNWafflez

    You could make it so it uses the Essentials API, and disables that feature if the server doesn't have Essentials like this:

    Code:
     
    Plugin e = getServer().getPluginManager().getPlugin("Essentials");
     
    if (e != null) {
      //Essentials method
    } else {
      event.getPlayer().sendMessage("This feature is disabled without Essentials!");
    }
     
    
    Also, it might be helpful if I could see more of your code, I can't see some of the things that might influence it there.

    EDIT: Or what Taco said would probably work, he posted his while I was typing mine lol.
     
  4. I recommend using
    if(ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("[LevelUp]"))

    That ignores all colors.
     
  5. Offline

    Milkywayz

    Thanks. i was thinking since it was a sign chat color wouldn't work, for obvious reasons.

    Yeah that didnt work. Im using color on signs, not color in chat.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  6. Offline

    Double0negative

    try
    Code:
    String  str = s.getLine(0).replaceAll("(\u00A7$2([a-f0-9]))", "");
     
    if(str.equalsIgnoreCase("[LevelUp]")){
     
     
    }
     
    
    note, im horrible with regex some im not entirely sure this will work
     
  7. Offline

    Milkywayz

    Its alright ill test this and get back to you
     
  8. Offline

    Sir Savary

    Milkywayz

    ChatColor is a sort of global color enum (I think, could be wrong with my terms). So, no matter what you're using (Chat, Signs, Console) you will always use ChatColor. So therefore, @Pandemoneus was right when he said to use:
    Code:java
    1. if(ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("[LevelUp]"))
     
  9. If everything fails I would just System.out.println(s.getLine(0)) to see what you are actually getting from your sign.
     
  10. Offline

    Milkywayz

    Yeah I tested that and it still didnt work :(
     
  11. Mind posting your whole code and the System.out.println you get on the console?
     
  12. Offline

    Sorroko

    Here is a working regex for removing ascii colors:
    Code:
    .replaceAll("(\\u001B\\[[0-9][0-9]?m)","");
    Hope that helps...
     
Thread Status:
Not open for further replies.

Share This Page