Guest User

JsonAPI

a guest
May 5th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import static org.bukkit.Bukkit.getServer;
  2. import static org.bukkit.Bukkit.getConsoleSender;
  3.  
  4. /**
  5. * @author Mior
  6. * @version 1.0
  7. * @category utils
  8. */
  9.  
  10. public class Json {
  11.  
  12. /*
  13. * Texts with extra text in the message.
  14. */
  15.  
  16. public static void sendText(String player, String message, String extra) {
  17. String rawText = "{\"text\":\""+message+"\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+extra+"\"}}";
  18. sendJsonMessage(player,rawText);
  19. }
  20.  
  21. public static void sendTextWithUrl(String player, String message, String extra, String url) {
  22. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""+url+"\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+extra+"\"}}";
  23. sendJsonMessage(player,rawText);
  24. }
  25.  
  26. public static void sendTextWithCommand(String player, String message, String extra, String command) {
  27. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\""+command+"\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+extra+"\"}}";
  28. sendJsonMessage(player,rawText);
  29. }
  30.  
  31. public static void sendTextWithSuggestCommand(String player, String message, String extra, String suggestCommand) {
  32. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\""+suggestCommand+"\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""+extra+"\"}}";
  33. sendJsonMessage(player,rawText);
  34. }
  35.  
  36. /*
  37. * Texts without extra text in the message.
  38. */
  39.  
  40. public static void sendTextWithUrl(String player, String message, String url) {
  41. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""+url+"\"}}";
  42. sendJsonMessage(player,rawText);
  43. }
  44.  
  45. public static void sendTextWithCommand(String player, String message, String command) {
  46. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\""+command+"\"}}";
  47. sendJsonMessage(player,rawText);
  48. }
  49.  
  50. public static void sendTextWithSuggestCommand(String player, String message, String suggestCommand) {
  51. String rawText = "{\"text\":\""+message+"\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\""+suggestCommand+"\"}}";
  52. sendJsonMessage(player,rawText);
  53. }
  54.  
  55. /*
  56. * Method used to send a message
  57. */
  58.  
  59. static void sendJsonMessage(String player, String rawText) {
  60. getServer().dispatchCommand(getConsoleSender(), "tellraw " + player + " " + rawText);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment