Add strikethrough and colour to sendMessage?

Discussion in 'Plugin Development' started by billywhiteMC, Sep 20, 2014.

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


    Hi guys,

    I'm trying to add a strike through and red colour to a message sent to a player on my bukkit plugin, this is what I have attempted but it hasn't worked.

    I'm getting the error line 'The operator + is undefined for the argument type(s) org.bukkit.ChatColor, org.bukkit.ChatColor"

    This is my line of code:
            e.getPlayer().sendMessage(ChatColor.RED + ChatColor.STRIKETHROUGH + "====================================================="); 

    Please help.. anyone?
  2. call .toString() on the first chatcolor, java normally does this behind the scenes because it knows how to handle the + with a Object and String, but it fails now because it doesn't know how to do Object + Object
  3. Offline


    ferrybig Sorry I'm very new to java. I don't really know what you mean, so could you please paste an example, A) So I can fix this problem and B) So I can learn for future references.
  4. Offline


    billywhiteMC what is so hard about calling .toString on a ChatColor?
  5. Offline


    fireblast709 As I said, I am new... is it really necessary to ask stupid, pointless questions like this?
  6. billywhiteMC
    adding .toString() isn't eally hard to do, examples that contains .toString:
    1. player.toString();

    1. world.toString();

    In your case, you want to do:
    1. ChatColor.RED.toString() + ChatColor.STRIKETHROUGH + "====================================================="
    billywhiteMC likes this.
  7. Code:java
    1. e.getPlayer().sendMessage("" + ChatColor.RED + ChatColor.STRIKETHROUGH + "=====================================================");

    Another solution. The "" creates a String object and from that point onwards the result is always a String.
  8. Offline


    Yes. Being new doesn't exclude you from learning Java :p
    billywhiteMC likes this.
  9. Offline


  10. Offline


    Erm. ChatColor.BLUE + "" + ChatColor.STRIKETHROUGH is what I use.
  11. Offline


    billywhiteMC Another method (If you don't like the one you now use), you may do this as well:

    1. ChatColor.translateAlternateColorCode('&', "&1&mDark Blue and Strikethrough text!");

    Note that may not be the exact method name, I am currently without an IDE.
Thread Status:
Not open for further replies.

Share This Page