jessefjxm

Untitled

Aug 8th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. // Format.java
  2.  
  3. // Extented part
  4.  
  5. public static String convertToJson(ChatMessage lastChatMessage) {
  6. MineverseChatPlayer icp = MineverseChatAPI.getMineverseChatPlayer(lastChatMessage.getSender());
  7. JsonFormat formatName = MineverseChat.jfInfo.getJsonFormatName(icp.getJsonFormatName());
  8. JsonFormat formatPrefix = MineverseChat.jfInfo.getJsonFormatPrefix(icp.getJsonFormatPrefix());
  9. JsonFormat formatSuffix = MineverseChat.jfInfo.getJsonFormatSuffix(icp.getJsonFormatSuffix());
  10. String f = lastChatMessage.getFormat().replace("\\", "\\\\").replace("\"", "\\\"");
  11. String c = lastChatMessage.getChat().replace("\\", "\\\\").replace("\"", "\\\"");
  12. String json = "[\"\",{\"text\":\"\",\"extra\":[";
  13. String prefix = "";
  14. String suffix = "";
  15. try {
  16. prefix = FormatStringAll(MineverseChat.chat.getPlayerPrefix(icp.getPlayer()));
  17. suffix = FormatStringAll(MineverseChat.chat.getPlayerSuffix(icp.getPlayer()));
  18. if (suffix.equals("")) {
  19. suffix = "venturechat_no_suffix_code";
  20. }
  21. if (prefix.equals(""))
  22. prefix = "venturechat_no_prefix_code";
  23. } catch (Exception e) {
  24. if (plugin.getConfig().getString("loglevel", "info").equals("debug")) {
  25. System.out.println("[" + plugin.getConfig().getString("pluginname", "MineverseChat")
  26. + "] Prefix and / or suffix don't exist, setting to nothing.");
  27. }
  28. }
  29. String nickname = "";
  30. if (icp.getPlayer() != null) {
  31. nickname = FormatStringAll(icp.getPlayer().getDisplayName());
  32. }
  33.  
  34. json = json + convertPlaceholders(f, formatName, formatPrefix, formatSuffix, prefix, nickname, suffix, icp);
  35. json = json + "]}";
  36. json = json + "," + convertLinks(c);
  37. json = json + "]";
  38. if (plugin.getConfig().getString("loglevel", "info").equals("debug")) {
  39. System.out.println(json);
  40. }
  41. return json;
  42. }
  43.  
  44. private static String convertPlaceholders(String s, JsonFormat formatName, JsonFormat formatPrefix,
  45. JsonFormat formatSuffix, String prefix, String nickname, String suffix, MineverseChatPlayer icp) {
  46. String remaining = s;
  47. String temp = "";
  48. int indexStart = -1;
  49. int indexEnd = -1;
  50. String placeholder = "";
  51. String lastCode = "§f";
  52. while (true) {
  53. Pattern pattern = Pattern.compile("("
  54. + prefix.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}")
  55. .replace("(", "\\(").replace(")", "\\)")
  56. + "|"
  57. + nickname.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}")
  58. .replace("(", "\\(").replace(")", "\\)")
  59. + "|" + suffix.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}")
  60. .replace("(", "\\(").replace(")", "\\)")
  61. + ")");
  62. Matcher matcher = pattern.matcher(remaining);
  63. if (!matcher.find())
  64. break;
  65. indexStart = matcher.start();
  66. indexEnd = matcher.end();
  67. placeholder = remaining.substring(indexStart, indexEnd);
  68. temp = temp + convertToJsonColors(
  69. new StringBuilder(String.valueOf(lastCode)).append(remaining.substring(0, indexStart)).toString())
  70. + ",";
  71. lastCode = getLastCode(lastCode + remaining.substring(0, indexStart));
  72. String action = "";
  73. if (placeholder.contains(nickname))
  74. action = formatName.getClickName();
  75. if (placeholder.contains(prefix))
  76. action = formatPrefix.getClickPrefix();
  77. if (placeholder.contains(suffix))
  78. action = formatSuffix.getClickSuffix();
  79. String text = "";
  80. if (placeholder.contains(nickname))
  81. text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), formatName.getClickNameText());
  82. if (placeholder.contains(prefix))
  83. text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), formatPrefix.getClickPrefixText());
  84. if (placeholder.contains(suffix))
  85. text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), formatSuffix.getClickSuffixText());
  86. String hover = "";
  87. if (placeholder.contains(nickname)) {
  88. hover = "";
  89. for (String st : formatName.getHoverTextName()) {
  90. hover = hover + FormatStringAll(st) + "\n";
  91. }
  92. }
  93. if (placeholder.contains(prefix)) {
  94. hover = "";
  95. for (String st : formatPrefix.getHoverTextPrefix()) {
  96. hover = hover + FormatStringAll(st) + "\n";
  97. }
  98. }
  99. if (placeholder.contains(suffix)) {
  100. hover = "";
  101. for (String st : formatSuffix.getHoverTextSuffix()) {
  102. hover = hover + FormatStringAll(st) + "\n";
  103. }
  104. }
  105. hover = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1));
  106. temp = temp
  107. + convertToJsonColors(new StringBuilder(String.valueOf(lastCode)).append(placeholder).toString(),
  108. new StringBuilder(",\"clickEvent\":{\"action\":\"").append(action).append("\",\"value\":\"")
  109. .append(text)
  110. .append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[")
  111. .append(convertToJsonColors(hover)).append("]}}").toString())
  112. + ",";
  113. lastCode = getLastCode(lastCode + placeholder);
  114. remaining = remaining.substring(indexEnd);
  115. }
  116.  
  117. temp = temp + convertToJsonColors(new StringBuilder(String.valueOf(lastCode)).append(remaining).toString());
  118.  
  119. return temp;
  120. }
  121.  
  122. // Ended extented part
Advertisement
Add Comment
Please, Sign In to add comment