Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jsonMessage(json: string, player: player):
- set {_jsonmsg} to {_json} parsed as jsonobject
- if {_jsonmsg} is not set:
- send "&4Error: &cFailed convert to JSON. &7(%{_json}%)" to console
- stop
- else if {_jsonmsg} is set:
- set {_packet} to new play_server_chat packet
- set "chatcomponent" pjson 0 of {_packet} to {_jsonmsg}
- set byte pnum 0 of {_packet} to 0
- send {_player} packet {_packet}
- function removeSideChar(text: string, option: integer, removecharcount: integer) :: string:
- set {_splits::*} to split {_text} by ""
- set {_number} to size of {_splits::*}
- delete {_splits::%{_number}%}
- if {_option} is 1:
- loop {_removecharcount} times:
- delete {_splits::%loop-number%}
- else if {_option} is 2:
- loop {_removecharcount} times:
- set {_number} to size of {_splits::*}
- delete {_splits::%{_number}%}
- else if {_option} is 3:
- loop {_removecharcount} times:
- set {_number} to size of {_splits::*}
- delete {_splits::%{_number}%}
- loop {_removecharcount} times:
- delete {_splits::%loop-number%}
- loop {_splits::*}:
- set {_returnvalue} to loop-value
- stop loop
- set {_loopcount} to 0
- loop {_splits::*}:
- if {_loopcount} is 0:
- add 1 to {_loopcount}
- else if {_loopcount} >= 1:
- {_loopcount} < size of {_splits::*}
- add 1 to {_loopcount}
- set {_returnvalue} to "%{_returnvalue}%%loop-value%"
- return {_returnvalue}
- function convert_to_jsonformat(text: string) :: string:
- set {_splits1::*} to split {_text} by " "
- loop {_splits1::*}:
- delete {_splits2::*}
- set {_splits2::*} to split loop-value by ""
- set {_number} to size of {_splits2::*}
- delete {_splits2::%{_number}%}
- set {_number} to size of {_splits2::*}
- if {_splits2::1} is "§":
- if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%" is "https://":
- {_splits2::11} is set
- 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""}}}"
- else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%" is "http://":
- {_splits2::10} is set
- 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""}}}"
- else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%%{_splits2::11}%%{_splits2::%{_number}%}%" is "(https://)":
- {_splits2::12} is set
- 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""}}}"
- else if "%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::10}%%{_splits2::%{_number}%}%" is "(http://)":
- {_splits2::11} is set
- 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""}}}"
- else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%" is "https://":
- {_splits2::9} is set
- 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""}}}"
- else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%" is "http://":
- {_splits2::8} is set
- 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""}}}"
- else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::9}%%{_splits2::%{_number}%}%" is "(https://)":
- {_splits2::10} is set
- 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""}}}"
- else if "%{_splits2::1}%%{_splits2::2}%%{_splits2::3}%%{_splits2::4}%%{_splits2::5}%%{_splits2::6}%%{_splits2::7}%%{_splits2::8}%%{_splits2::%{_number}%}%" is "(http://)":
- {_splits2::9} is set
- 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""}}}"
- if {_jsonsplits::%loop-index%} is not set:
- set {_jsonsplits::%loop-index%} to "{""text"":""%loop-value%""}"
- set {_loopcount} to 0
- loop {_jsonsplits::*}:
- if {_loopcount} is 0:
- set {_messagejson} to loop-value
- add 1 to {_loopcount}
- else if {_loopcount} >= 1:
- set {_messagejson} to "%{_messagejson}%,{""text"":"" ""},%loop-value%"
- add 1 to {_loopcount}
- set {_messagejson} to "{""extra"":[%{_messagejson}%],""text"":""""}"
- return {_messagejson}
- on chat:
- cancel event
- send "&7%player%: %message%" to console
- loop all players:
- jsonMessage(convert_to_jsonformat("&7%player%: %message%"), loop-player)
Advertisement
Add Comment
Please, Sign In to add comment