Converts a chat component json to a human-readable text.
function asSkriptColor(color: text) :: text:
if {_color} contains "_":
replace all "_" with " " in {_color}
return {_color}
else if {_color} isn't "black", "white", "yellow" or "gold":
return "light %{_color}%"
else:
return {_color}
function asReadableText(json: jsonobject) :: text:
put json {_json} in listvar {_json::*}
loop tree of {_json::extra::*}:
if branch contains "color":
set {_color} to asSkriptColor("%loop-value%")
set {_color} to "<%{_color}%>"
else if branch contains "text":
if {_color} isn't set:
set {_color} to ""
add "%{_color}%%loop-value%" to {_full-text::*}
return join {_full-text::*} by ""
on skript load:
add "<red><bold>Hey! <grey>you aren not permitted to enter this area." to {deniedMessages::*} #WorldGuard message
add "You created the faction " to {deniedMessages::*} #Factions message
on packet event play_server_chat:
set {_last-message} to asReadableText(chatcomponent pjson 0 of event-packet)
loop {deniedMessages::*}:
if {_last-message} contains loop-value:
replace all loop-value with "..." in {_last-message}
cancel event
set chatcomponent pjson 0 of event-packet to asComponent({_last-message}) # Uses the message to component function