Sign colors

Discussion in 'Plugin Development' started by Wingas, Jul 12, 2014.

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

    Wingas

    How to make sign colors, like green text on sign
     
  2. Offline

    Pizza371

    Wingas I think the ChatColor enum works on signs. Try it?
     
  3. Offline

    macboinc

    It doesn't
     
  4. Offline

    Pizza371

    then can you give this poor guy an answer? :p
     
  5. Offline

    macboinc

  6. Offline

    Necrodoom

    macboinc apprentally you don't know how the chatcolor enum works then.
    The enum works fine, use it.
     
  7. Offline

    Wingas

    i want to make like if i on sign write [Hello], then its changes text and color, its hard?
     
  8. Offline

    macboinc

    Stop judging people you don't even know. And yes, I use that chatcolor enum all the time.
    Like so:
    Code:java
    1. Player p = Bukkit.getServer().getPlayer("Necrodoom");
    2.  
    3. p.sendMessage(ChatColor.RED + "Hey, " + ChatColor.YELLOW + "Necrodoom," + ChatColor.RED + " Why don't you stop being presumptuous and impetuous");
     
  9. Offline

    CynutsBR

    Just use §number or ChatColor.COLOR
    I'm felling the fight hehehe
     
  10. Offline

    Necrodoom

    macboinc Then you should already know that ChatColor already uses §, and thus works fine on signs.
     
  11. Offline

    macboinc

    I personally like '§' better, so [​IMG]?
     
  12. Offline

    Necrodoom

    macboinc Yes, because, you told Pizza371 that it doesnt actually work, when in fact it does, and just because you like it, doesnt mean you need to enforce bad practice on people.
     
    mythbusterma likes this.
  13. Offline

    mythbusterma

    macboinc

    Yes, because there are objective reasons that ChatColor.<color> is better, namely:
    1. It is implementation independant, i.e. if Minecraft were to change the color codes, Bukkit would update, and your code would still work fine, whereas the section character implementation would break.
    2. Using the section character decreases code readability, making code harder to maintain, and meaning less obvious, also requiring anyone else looking at the code to look the color code each time they want to use it.

    So yes, encouraging bad programming practices and telling people things don't work when actually they do is considered bad practice.

    Ninja'd by Necrodoom
     
  14. Offline

    ZanderMan9

    Hm? I though it would be colorless even with the section sign unless you used ChatColor.translateAlternateColorCodes and added it as the character...
     
  15. Offline

    Necrodoom

    ZanderMan9 That basically turns a symbol to §
     
  16. Offline

    ZanderMan9

    Necrodoom I'm not sure I understand what you're getting at...
    But if you want to color signs ingame, you'll need to listen on SignChangeEvent and set each line to formatted version.
    Use this I guess:
    Code:java
    1. ChatColor.translateAlternateColorCodes('&', message);
     
    mythbusterma likes this.
  17. Offline

    mythbusterma

    ZanderMan9

    What he's saying is that all translateAlternateColorCodes(Character char, String message) does is:

    message.replace(char, "§");
     
  18. Offline

    Necrodoom

    ZanderMan9 What i meant is, if you want to write a message on a sign, these 3 things would be identical, but the first one would be the best practice one if you make a new message, and the third if you take an existing message:
    String message;
    message = ChatColor.RED + "Hello!";
    message = "§cHello!";
    message = ChatColor.translateAlternateColorCodes('&', "&cHello!");
     
  19. Offline

    ZanderMan9

    So wait... All chars would become the string you enter?
    I've been using it in a completely different way....
    Player uses a command, I take and build the args into a string, use translateAlt.... on it and then broadcast it....
    And if they say &6Message it comes out as Message. The code is the same as I posted above...

    Edit: Excuse me, what you said just confused me further... I've been doing it right all along ;)
     
  20. Offline

    Necrodoom

    ZanderMan9 Yeah, basically use either 1 or 3 based on the context of what you need.
     
Thread Status:
Not open for further replies.

Share This Page