Solved Bold and colored?

Discussion in 'Plugin Development' started by TechAttax, Jul 11, 2014.

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

    TechAttax

    When I try to make somthing colored and bold it gives an error.

    Here is my code that gives the error!:

    Code:java
    1. sender.sendMessage(ChatColor.GREEN + ChatColor.BOLD + "FastLeave V0.3 help.");


    It gives the error: The operator + is undefined for the argument type(s) org.bukkit.ChatColor, org.bukkit.ChatColor
     
  2. Offline

    Necrodoom

    This is because java wise it reads your code and first attempts to append ChatColor with ChatColor, which, as it says, is invalid, and it doesnt know you want a string. Either put a + "" + in between to append each one to a string, or cast them to string first with a .toString().
     
  3. Offline

    RRServer

    Alternately, I prefer using this setup for doing colored/bold/magic messages in my plugins.

    Code:java
    1. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a&lFastLeave V0.3 help."));
     
  4. Offline

    teej107

    RRServer What ever works for you. I just like using ChatColor because the enum name tells the color. And if Minecraft ever happens to change its color coding format, the ChatColor enum will change with it too eventually.
    TechAttax Use .toString() on the ChatColors.
     
  5. Offline

    Akye

    TechAttax Try doing
    Code:
     sender.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN +"FastLeave V0.3 help."); 
    it should work :D
     
  6. Offline

    Monkey_Swag

    TechAttax alt + 21 =
    §
    Never use ChatColor. ever again <3
     
  7. Offline

    teej107

    Monkey_Swag
     
  8. Offline

    Monkey_Swag

    teej107 where did you get that from? :confused:
     
  9. Offline

    xTigerRebornx

    Monkey_Swag I believe I said that, there was a whole talk we had about using that symbol vs ChatColor.
    I simply stated that it provides cross-version compatibility in case color codes were to ever change in any way what-so-ever
     
  10. Offline

    Necrodoom

    I'm just wondering why everyone had to duplicate the answer of the second post.
     
  11. Offline

    teej107

    Monkey_Swag I said it in this post. I may have read it from xTigerRebornx in another thread but there is a good point in using ChatColor. I wouldn't expect Bukkit to drop support for ChatColor if the format changes.

    EDIT:
    Backing up peoples explanation. But I never said to use quotation marks because I think it'll make that string look messy. Using .toString() looks a lot cleaner to me.
     
  12. Offline

    fireblast709

    The moment MC changes the format, bukkit can fix it for all plugins that use ChatColor, the rest will be broken :3
     
  13. Offline

    macboinc

    Look at this.
    Instead of using '&' use this symbol: §
     
  14. Offline

    ZodiacTheories

    macboinc Monkey_Swag

    Why should we ignore the fact that the Bukkit team made a ChatColor enum for us to help us developing plugins? If Mojang changes the Alt + 21 symbol (Cannot do it :mad: ) then your plugins will break. Also, the Bukkit team provided us with this resource, so why not make use of it if it is better practice to use it?
     
  15. Offline

    Necrodoom

    Or use the ChatColor enum that is made for this purpose, and was already used by the OP, making all the answers telling him to use & and § useless.
     
Thread Status:
Not open for further replies.

Share This Page