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

    billywhiteMC

    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:
    Code:
            e.getPlayer().sendMessage(ChatColor.RED + ChatColor.STRIKETHROUGH + "====================================================="); 

    Please help.. anyone?
     
  2. Offline

    ferrybig

    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

    billywhiteMC

    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

    fireblast709

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

    billywhiteMC

    fireblast709 As I said, I am new... is it really necessary to ask stupid, pointless questions like this?
     
  6. Offline

    ferrybig

    billywhiteMC
    adding .toString() isn't eally hard to do, examples that contains .toString:
    Code:java
    1. player.toString();

    Code:java
    1. world.toString();

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

    adventuretc

    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

    fireblast709

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

    billywhiteMC

  10. Offline

    ChipDev

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

    Dudemister1999

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

    Code:java
    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