[&6] Color Support in Config.yml file

Discussion in 'Plugin Development' started by SeanyJo, Sep 19, 2013.

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

    SeanyJo

    Hi, I'm wondering how to add color support in the config file, and when a player is talking in chat, when they do &4hi, it shows up in dark red as hi, the same with the config and broadcasting messages.
     
  2. Offline

    chasechocolate

    You can use: ChatColor.translateAlternateColorCodes('&', "&cSome string").
     
  3. Offline

    SeanyJo

    so, I could do this in the main class:
    ChatColor.translateAlternateColorCodes(&c.ChatColor.RED, &6.ChatColor.GOLD); ?
     
  4. Offline

    chasechocolate

    SeanyJo no, the "&" is the code for the color (e.g. &c, &a, &b, if you had the code set to "=" it would be =c, =a, =b, etc.). The second argument is the string to convert.
     
  5. Offline

    SeanyJo

    so,
    ChatColor.translateAlternateColorCodes(&c, &6); would give me the colors?
    Sorry,i'm a beginner in Java and Bukkit Coding..
     
  6. Offline

    chasechocolate

  7. Offline

    SeanyJo

  8. Offline

    chasechocolate

    SeanyJo nope. String colored = ChatColor.translateAlternateColorCodes('&', "&cYour string to colorize").
     
  9. Offline

    SeanyJo


    String colored = ChatColor.translateAlternateColorCodes('&', "&c");
    I feel like I'm missing the ChatColor.<color> in there. where does it go?
     
  10. Offline

    WauloK

    You don't need ChatColor because the &c picks the colour to change it to and the ChatColor.translateAlternateColorCodes changes &c to the colour you want instead.
     
  11. Offline

    SeanyJo

    where do you put the color you want?
     
  12. Offline

    WauloK

    &c represents the colour you want
     
  13. Offline

    SeanyJo

    how does it know what color to output with &c?

    String colored = ChatColor.translateAlternateColorCodes('&', "ChatColor.RED");
    or

    String colored = ChatColor.translateAlternateColorCodes('&', "&c");
     
  14. Offline

    WauloK

  15. Offline

    Gater12

    SeanyJo Ok, you are making this way too complicated.
    ChatColor.translateAlternateColorCodes('&', "string") is what it is. It is basically changing the &c or &whatever code to color in the "string". So like if I wanted it to translate &cHello I would put ChatColor.translateAlternateColorCodes('&', "&cHello) and then it will translate what &c means. And it means red so it would put Hello in red.
     
  16. Offline

    SeanyJo

    that helped, thanks.
    But now, i have the event listener, and i'm lost. In the listener class, I have:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
    event.setMessage(ChatColor.translateAlternateColorCodes('&', "&c"));
    }

    }
    And in the main class:

    String colored = ChatColor.translateAlternateColorCodes('&', "&c");

    How do you make it so anything would be red, not just hello?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  17. Offline

    chasechocolate

    SeanyJo sounds like you don't understand java. I would recommend learning the basics. Change it to: evt.setMessage(ChatColor.translateAlternateColorCodes('&', evt.getMessage())).
     
    WauloK likes this.
  18. Offline

    SeanyJo

    it still doesn't work. I'll pick up a java tutorial tomorrow evening.
     
  19. SeanyJo Just use the minecraft colour codes. They get translated automagically. So if you would a text be purple then just use §d. No need to translate it then.

    SeanyJo Also that always work, just do what chasechocolate told you. Or show us your code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  20. Offline

    SeanyJo

  21. Offline

    The_Doctor_123

    SeanyJo
    Meh.. that method in ChatColor, in my opinion, is pointless. If it's giving you grief, use this:

    Code:java
    1. myString.replace('&', '§');
     
  22. Offline

    SeanyJo

    where do I put it? Also, what do I replace myString with?
     
  23. Offline

    The_Doctor_123

    The String you're trying to change..
     
  24. Offline

    SeanyJo

    in my main class, i have:

    public static String colored = ChatColor.translateAlternateColorCodes('&', "§");
    and in the chat class:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
    if(event.getMessage().contains("&"));
    TigreGames.colored.replace("&", "§");
    }

    }
     
  25. Offline

    AoH_Ruthless

    SeanyJo
    What are you trying to accomplish exactly? If I'm correct, that's just going to replace the '&' with the symbol that I forget the alt code for.
     
  26. Offline

    Janmm14

    SeanyJo
    do
    Code:
    @EventHandler
    public void onPlayerChat(AsynxPlayerChatEvent e) {
        e.setMessage(ChatColor.translafeAlternateColorCodes('&',e.gerMessage()));
    }
     
  27. Offline

    SeanyJo

    doesn't work... I fixed the spelling mistakes. I also removed the method in the main class.
     
  28. Offline

    Janmm14

    SeanyJo
    Sorry for the spelling mistakes.

    Add this to your onEnable() method:
    Bukkit.getPluginManager().registerEvents(this, this);

    maybe you have to add this at the top after public class ???:
    implements Listener
     
  29. Offline

    SeanyJo

    i added those, and I added this also:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    if(e.getMessage().contains("&"));
    e.setMessage(ChatColor.translateAlternateColorCodes('&',e.getMessage()));
    }

    }
     
  30. Offline

    Janmm14


    That is NOT needed!

    Edit: Please use [ code] and [/code ]
     
Thread Status:
Not open for further replies.

Share This Page