akon1248

Untitled

Jan 9th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. function jsonMessage(json: string, player: player):
  2. set {_jsonmsg} to {_json} parsed as jsonobject
  3. if {_jsonmsg} is not set:
  4. send "&4Error: &cFailed convert to JSON. &7(%{_json}%)" to console
  5. stop
  6. else if {_jsonmsg} is set:
  7. set {_packet} to new play_server_chat packet
  8. set "chatcomponent" pjson 0 of {_packet} to {_jsonmsg}
  9. set byte pnum 0 of {_packet} to 0
  10. send {_player} packet {_packet}
  11. function removeSideChar(text: string, option: integer, removecharcount: integer) :: string:
  12. set {_splits::*} to split {_text} by ""
  13. set {_number} to size of {_splits::*}
  14. delete {_splits::%{_number}%}
  15. if {_option} is 1:
  16. loop {_removecharcount} times:
  17. delete {_splits::%loop-number%}
  18. else if {_option} is 2:
  19. loop {_removecharcount} times:
  20. set {_number} to size of {_splits::*}
  21. delete {_splits::%{_number}%}
  22. else if {_option} is 3:
  23. loop {_removecharcount} times:
  24. set {_number} to size of {_splits::*}
  25. delete {_splits::%{_number}%}
  26. loop {_removecharcount} times:
  27. delete {_splits::%loop-number%}
  28. loop {_splits::*}:
  29. set {_returnvalue} to loop-value
  30. stop loop
  31. set {_loopcount} to 0
  32. loop {_splits::*}:
  33. if {_loopcount} is 0:
  34. add 1 to {_loopcount}
  35. else if {_loopcount} >= 1:
  36. {_loopcount} < size of {_splits::*}
  37. add 1 to {_loopcount}
  38. set {_returnvalue} to "%{_returnvalue}%%loop-value%"
  39. return {_returnvalue}
  40. function convert_to_jsonformat(text: string) :: string:
  41. set {_splits1::*} to split {_text} by " "
  42. loop {_splits1::*}:
  43. delete {_splits2::*}
  44. set {_splits2::*} to split loop-value by ""
  45. set {_number} to size of {_splits2::*}
  46. delete {_splits2::%{_number}%}
  47. set {_number} to size of {_splits2::*}
  48. if {_splits2::1} is "§":
  49. if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%" is "https://":
  50. {_splits2::11} is set
  51. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(loop-value, 1, 2)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(loop-value, 1, 2)%"",""color"":""aqua""}}}"
  52. else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%" is "http://":
  53. {_splits2::10} is set
  54. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(loop-value, 1, 2)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(loop-value, 1, 2)%"",""color"":""aqua""}}}"
  55. else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%%{_splits2::11}%%{_splits2::%{_number}%}%" is "(https://)":
  56. {_splits2::12} is set
  57. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(removeSideChar(loop-value, 1, 2), 3, 1)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(removeSideChar(loop-value, 1, 2), 3, 1)%"",""color"":""aqua""}}}"
  58. else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%%{_splits2::%{_number}%}%" is "(http://)":
  59. {_splits2::11} is set
  60. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(removeSideChar(loop-value, 1, 2), 3, 1)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(removeSideChar(loop-value, 1, 2), 3, 1)%"",""color"":""aqua""}}}"
  61. else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%" is "https://":
  62. {_splits2::9} is set
  63. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%loop-value%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%loop-value%"",""color"":""aqua""}}}"
  64. else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%" is "http://":
  65. {_splits2::8} is set
  66. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%loop-value%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%loop-value%"",""color"":""aqua""}}}"
  67. else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::%{_number}%}%" is "(https://)":
  68. {_splits2::10} is set
  69. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(loop-value, 3, 1)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(loop-value, 3, 1)%"",""color"":""aqua""}}}"
  70. else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::%{_number}%}%" is "(http://)":
  71. {_splits2::9} is set
  72. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%"",""clickEvent"":{""action"":""open_url"",""value"":""%removeSideChar(loop-value, 3, 1)%""},""hoverEvent"":{""action"":""show_text"",""value"":{""text"":""%removeSideChar(loop-value, 3, 1)%"",""color"":""aqua""}}}"
  73. if {_jsonsplits::%loop-index%} is not set:
  74. set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%""}"
  75. set {_loopcount} to 0
  76. loop {_jsonsplits::*}:
  77. if {_loopcount} is 0:
  78. set {_messagejson} to loop-value
  79. add 1 to {_loopcount}
  80. else if {_loopcount} >= 1:
  81. set {_messagejson} to "%{_messagejson}%,{""text"":"" ""},%loop-value%"
  82. add 1 to {_loopcount}
  83. set {_messagejson} to "{""extra"":[%{_messagejson}%],""text"":""""}"
  84. return {_messagejson}
  85. on chat:
  86. cancel event
  87. send "&7%player%: %message%" to console
  88. loop all players:
  89. jsonMessage(convert_to_jsonformat("&7%player%: %message%"), loop-player)
Advertisement
Add Comment
Please, Sign In to add comment