MisterBasic

Untitled

Feb 18th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. options:
  2. debug: false
  3. codes: 0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|k|l|m|n|o|r
  4.  
  5. function removeColor(msg: text) :: text:
  6. set {_m::*} to {_msg} split at ""
  7.  
  8. set {_color-codes} to "{@codes}"
  9. set {_colors::*} to {_color-codes} split at "|"
  10.  
  11. set {_new} to ""
  12.  
  13. loop {_m::*}:
  14. set {_char} to loop-value
  15. set {_prev} to the last character of {_new}
  16.  
  17. if {_prev} is "&":
  18.  
  19. loop {_colors::*}:
  20.  
  21. if loop-value-2 is {_char}:
  22. set {_skip} to true
  23.  
  24. if {_skip} is set:
  25. delete {_skip}
  26.  
  27. else:
  28. set {_new} to "%{_new}%%{_char}%"
  29.  
  30. return {_new}
  31.  
  32. function jsonColorize(msg: text, default-color: text = "&r") :: text:
  33. set {_m::*} to {_msg} split at ""
  34.  
  35. set {_color-codes} to "{@codes}"
  36. set {_colors::*} to {_color-codes} split at "|"
  37.  
  38. set {_color} to colored {_default-color}
  39. set {_code} to the first character of {_color}
  40.  
  41. set {_new} to ""
  42. set {_skip} to 0
  43.  
  44. loop amount of {_m::*} times:
  45.  
  46. if {_skip} is more than or equal to 1:
  47. subtract 1 from {_skip}
  48.  
  49. else:
  50. set {_char} to {_m::%loop-number%}
  51. set {_next} to {_m::%loop-number + 1%}
  52.  
  53. if {@debug} is true:
  54. broadcast "&a[Character Check] &r%loop-number%: &7%{_char}% &r&onext: &8%{_next}% &r[%{_color}%color&r]"
  55.  
  56. if {_char} is "&" or {_code}:
  57.  
  58. if {@debug} is true:
  59. broadcast "&a[Color Check] &rFOUND: &o%{_char}%%{_next}% &7&m<--&7&o is it valid?"
  60.  
  61. loop {_colors::*}:
  62.  
  63. if loop-value-2 is {_next}:
  64. set {_color} to "%{_color}%%{_code}%%{_next}%"
  65.  
  66. if {_next} is "r":
  67. set {_color} to {_default-color}
  68.  
  69. set {_new} to "%{_new}%%{_color}%"
  70. set {_skip} to 1
  71.  
  72. if {_skip} is less than or equal to 0:
  73. set {_new} to "%{_new}%%{_char}%"
  74.  
  75. else if {_char} is " ":
  76. set {_new} to "%{_new}% %{_color}%"
  77.  
  78. else:
  79. set {_new} to "%{_new}%%{_char}%"
  80.  
  81. return {_new}
  82.  
  83. function jsonSanitize(msg: text) :: text:
  84. if {@debug} is true:
  85. broadcast "&a[Sanitize] &7&oSanitizing input..."
  86.  
  87. set {_m::*} to {_msg} split at ""
  88.  
  89. loop {_m::*}:
  90.  
  91. if loop-value is """":
  92. set {_m::%loop-index%} to "\""" # """
  93.  
  94. else if loop-value is "\":
  95. set {_m::%loop-index%} to "\\"
  96.  
  97. set {_new} to join {_m::*} with ""
  98. return {_new}
  99.  
  100. function jsonFormat(msg: text, color: boolean = true) :: text:
  101. set {_m::*} to {_msg} split at "||"
  102.  
  103. set {_current} to 1
  104.  
  105. loop {_m::*}:
  106. if {_clusters::%{_current}%} is not set:
  107. set {_clusters::%{_current}%} to ""
  108.  
  109. if {_clusters::%{_current}%::text} is not set:
  110. set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
  111.  
  112. else:
  113. set {_tag} to the first 4 characters of loop-value
  114. set {_value} to subtext of loop-value from characters 5 to the length of loop-value
  115.  
  116. if {_tag} is "ttp:":
  117. set {_clusters::%{_current}%::tooltip} to jsonSanitize({_value})
  118.  
  119. else if {_tag} is "cmd:":
  120. set {_clusters::%{_current}%::command} to jsonSanitize({_value})
  121.  
  122. else if {_tag} is "sgt:":
  123. set {_clusters::%{_current}%::suggest} to jsonSanitize({_value})
  124.  
  125. else if {_tag} is "url:":
  126.  
  127. if {_value} doesn't contain "http://" or "https://":
  128. set {_value} to "http://%{_value}%"
  129.  
  130. set {_clusters::%{_current}%::url} to jsonSanitize({_value})
  131.  
  132. else if {_tag} is "ins:":
  133. set {_clusters::%{_current}%::insertion} to jsonSanitize({_value})
  134.  
  135. else:
  136. add 1 to {_current}
  137. set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
  138. set {_clusters::%{_current}%} to ""
  139.  
  140. if {@debug} is true:
  141. broadcast "&a[Tag Check] &3cluster:&b%{_current}% &8(&f&o%{_tag}%&8)"
  142.  
  143. loop {_clusters::*}:
  144.  
  145. if {@debug} is true:
  146. broadcast "&a[Cluster Check] &7&oCluster ##%loop-index% exists."
  147.  
  148. set {_i} to loop-index
  149.  
  150. set {_text} to {_clusters::%{_i}%::text}
  151.  
  152. if {_color} is true:
  153. set {_text} to jsonColorize({_text})
  154.  
  155. if {_json} is not set:
  156. set {_json} to "{""text"":""%{_text}%"""
  157. else:
  158. set {_json} to "%{_json}%,{""text"":""%{_text}%"""
  159.  
  160. if {_clusters::%{_i}%::tooltip} is set:
  161.  
  162. if {_color} is true:
  163. set {_tooltip} to jsonColorize({_clusters::%{_i}%::tooltip})
  164.  
  165. else:
  166. set {_tooltip} to {_clusters::%{_i}%::tooltip}
  167.  
  168. set {_json} to "%{_json}%,""hoverEvent"":{""action"": ""show_text"",""value"": ""%{_tooltip}%""}"
  169.  
  170. if {_clusters::%{_i}%::insertion} is set:
  171. set {_json} to "%{_json}%,""insertion"":""%{_clusters::%{_i}%::insertion}%"",""obfuscated"":false"
  172.  
  173. if {_clusters::%{_i}%::command} is set:
  174. set {_clickable} to "%{_json}%,""clickEvent"":{""action"":""run_command"",""value"":""%{_clusters::%{_i}%::command}%""}"
  175.  
  176. if {_clusters::%{_i}%::suggest} is set:
  177. set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""suggest_command"",""value"": ""%{_clusters::%{_i}%::suggest}%""}"
  178.  
  179. if {_clusters::%{_i}%::url} is set:
  180. set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""open_url"",""value"": ""%{_clusters::%{_i}%::url}%""}"
  181.  
  182. if {_clickable} is set:
  183. set {_json} to "%{_clickable}%}"
  184. delete {_clickable}
  185.  
  186. else:
  187. set {_json} to "%{_json}%}"
  188.  
  189. return "{""text"":"""", ""extra"":[%{_json}%]}"
  190.  
  191. function json(to: text, msg: text, color: boolean = true):
  192. set {_msg} to jsonFormat({_msg}, {_color})
  193. execute console command "/tellraw %{_to}% %{_msg}%"
  194.  
  195. if {@debug} is true:
  196. set {_player} to {_to} parsed as offline player
  197. if {_player} is online:
  198. send uncolored {_msg} to {_player}
  199.  
  200. function jsonBroadcast(msg: text, color: boolean = true):
  201. json("@a", {_msg}, {_color})
  202.  
  203.  
  204. command /json [<text>] [<text>]:
  205. permission: "is.op"
  206. trigger:
  207. set {_to} to arg 1
  208. set {_msg} to arg 2
  209.  
  210. if arg 1 is not set:
  211. set {_to} to "%player%"
  212. if arg 2 is not set:
  213. set {_msg} to "This is a json message! &c&oClick here for no reason!||ttp:&lReally, click your mouse!||cmd:/json @a %{_to}% clicked their mouse on json..."
  214.  
  215. json({_to}, {_msg})
Advertisement
Add Comment
Please, Sign In to add comment