[snippet]TellRaw workaround

Discussion in 'Resources' started by BlockCat, Dec 3, 2013.

Thread Status:
Not open for further replies.
  1. Hello everyone,

    I decided to play around a bit with the new code.

    and came to this:
    Code:java
    1. IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"Hi\",\"color\":\"white\",\"extra\":[{\"text\":\"<Clik It>\",\"color\":\"yellow\",\"bold\":\"false\",\"italic\":\"true\",\"underlined\":\"false\",\"strikethrough\":\"false\",\"obfuscated\":\"false\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/achievement give <stat_name> [player]\"}}]}");
    2. PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
    3. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
     
    FisheyLP, uTerrian, hellboyPS and 2 others like this.
  2. Offline

    xTrollxDudex

    samosaara likes this.
  3. Offline

    Ultimate_n00b

    player.sendRawMessage() ?

    If you're going to offer this as a resource, could you tell me why it's better than the above?
     
  4. Offline

    Pik0

    what's the difference between sendRawMessage and sendMessage?
     
  5. Offline

    Cirno

    I believe sendRawMessage just strips ChatColor's; it doesn't actually "send raw data".
     
  6. Offline

    itsCrafted


    I believe it does send "raw data", actually, though I'm unsure (and likely wrong).
    edit: Misread, nevermind. :p
     
    sgtcaze likes this.
  7. Offline

    Alectriciti

    I was looking for this to send raw custom messages. That Json is a pain. If bukkit supported this in their API that'd be awesome. Thanks! :)
     
    Dysko likes this.
  8. Offline

    jusjus112

    BlockCat
    How do i use 2 actions at the same text? I have an hoverEvent and an clickEvent, but only one event works.
    But how i set two?
    i have:
    Code:java
    1. IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"An watershow has started!\","
    2. + "\"color\":\"gold\","
    3. + "\"extra\":[{\"text\":\"[Click to Teleport]\","
    4. + "\"color\":\"gray\","
    5. + "\"bold\":\"true\","
    6. + "\"italic\":\"true\",\"underlined\":\"false\","
    7. + "\"strikethrough\":\"false\","
    8. + "\"obfuscated\":\"false\","
    9. + "\"hoverEvent\":{\"action\":\"show_text\","
    10. + "\"value\":\"hey this is an test\"}}]}");
    11. PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
    12. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);

    And i will this in my code:
    Code:java
    1. + "\"clickEvent\":{\"action\":\"run_command\","
    2. + "\"value\":\"/ride jusjus\"}}]}");

    But i cant get it work with two!
     
  9. Offline

    Garris0n

    Jhtzb and spoljo666 like this.
  10. Offline

    jusjus112

  11. Offline

    Garris0n

  12. Offline

    jusjus112

    Garris0n
    But i cant use the hoverEvent with that
     
  13. Offline

    Garris0n

    It's .tooltip.
     
  14. Offline

    jusjus112

    Garris0n
    But when i use it, it spam vol with this:
    HTML:
    {"text":"","extra":[{"text":"Player ","color":"dark_red"},{"text":"jusjus","color":"red","italic":true},{"text":" changed ","color":"dark_red"},{"text":"413000","color":"aqua"},{"text":" blocks. ","color":"dark_red"},{"text":"Roll back?","color":"gold","underline":true,"clickEvent":{"action":"suggest_command","value":"/ride jusjus"},"hoverEvent":{"action":"show_text","value":"Be careful, this might undo legitimate edits!"}},{"text":" "},{"text":"Ban?","color":"red","underline":true,"clickEvent":{"action":"suggest_command","value":"/ride jusjus"},"hoverEvent":{"action":"show_text","value":"Remember: only ban if you have photographic evidence of grief."}}]}
    01.04 20:15:41 [Server] INFO {"text":"","extra":[{"text":"Visit ","color":"green"},{"text":"our website","color":"yellow","underline":true,"clickEvent":{"action":"open_url","value":"http://awesome-server.net"},"hoverEvent":{"action":"show_text","value":"AwesomeServer Forums"}},{"text":" to win ","color":"green"},{"text":"big prizes!","color":"aqua","bold":true,"hoverEvent":{"action":"show_text","value":"Terms and conditions may apply. Offer not valid in Sweden."}}]}
    01.04 20:15:41 [Server] INFO {"text":"","extra":[{"text":"Hello, ","color":"yellow"},{"text":"jusjus112","color":"light_purple","italic":true,"underline":true},{"text":"!","color":"yellow","italic":true}]}
    And i have this:
    Code:java
    1. public static void main() {
    2. Bukkit.getServer().broadcastMessage(welcome("jusjus112"));
    3. Bukkit.getServer().broadcastMessage(advertisement());
    4. Bukkit.getServer().broadcastMessage(gui("jusjus", 413000));
    5. }
    6.  
    7. static String welcome(String playername) {
    8. return new FancyMessage("Hello, ")
    9. .color(ChatColor.YELLOW)
    10. .then(playername)
    11. .color(ChatColor.LIGHT_PURPLE)
    12. .style(ChatColor.ITALIC, ChatColor.UNDERLINE)
    13. .then("!")
    14. .color(ChatColor.YELLOW)
    15. .style(ChatColor.ITALIC)
    16. .toJSONString();
    17. }
    18.  
    19. static String advertisement() {
    20. return new FancyMessage("Visit ")
    21. .color(ChatColor.GREEN)
    22. .then("our website")
    23. .color(ChatColor.YELLOW)
    24. .style(ChatColor.UNDERLINE)
    25. .link("[url]http://awesome-server.net[/url]")
    26. .tooltip("AwesomeServer Forums")
    27. .then(" to win ")
    28. .color(ChatColor.GREEN)
    29. .then("big prizes!")
    30. .color(ChatColor.AQUA)
    31. .style(ChatColor.BOLD)
    32. .tooltip("Terms and conditions may apply. Offer not valid in Sweden.")
    33. .toJSONString();
    34. }
    35.  
    36. static String gui(String playername, int blocksEdited) {
    37. return new FancyMessage("Player ")
    38. .color(ChatColor.DARK_RED)
    39. .then(playername)
    40. .color(ChatColor.RED)
    41. .style(ChatColor.ITALIC)
    42. .then(" changed ").color(ChatColor.DARK_RED)
    43. .then(blocksEdited).color(ChatColor.AQUA)
    44. .then(" blocks. ").color(ChatColor.DARK_RED)
    45. .then("Roll back?")
    46. .color(ChatColor.GOLD)
    47. .style(ChatColor.UNDERLINE)
    48. .suggest("/ride " + playername)
    49. .tooltip("Be careful, this might undo legitimate edits!")
    50. .then(" ")
    51. .then("Ban?")
    52. .color(ChatColor.RED)
    53. .style(ChatColor.UNDERLINE)
    54. .suggest("/ride " + playername)
    55. .tooltip("Remember: only ban if you have photographic evidence of grief.")
    56. .toJSONString();
    57. }
     
  15. Offline

    Garris0n

    jusjus112 Make a thread in Plugin Development and post the code you're using (more than just that).

    Edit: Wait, I didn't see the entire post until I quoted it. You have to use .send() so it can correctly send the json, it does not work with any bukkit methods.
     
  16. Offline

    jusjus112

    @BlockCat
    But is there not an way to use the two at an text?
     
    joeygallegos likes this.
Thread Status:
Not open for further replies.

Share This Page