Chat Component Converter
Converts a chat component json to a human-readable text.
Code
string property skript color[s]:
get:
if expression-1 contains "_":
replace all "_" with " " in {_color}
return {_color}
else if {_color} isn't "black", "white", "yellow" or "gold":
return "light %{_color}%"
else:
return {_color}
expression %jsonobjects% (as|to) [human-]readable text:
get:
loop expressions-1:
put json loop-value in listvar {_json::%loop-index%::*}
loop tree of {_json::%loop-index%::extra::*}:
if branch contains "color":
set {_color} to loop-value-2's skript color
set {_color} to "<%{_color}%>"
else if branch contains "text":
if {_color} isn't set:
set {_color} to ""
add "%{_color}%%loop-value-2%" to {_full-text::%loop-index-1%::*}
add join {_full-text::%loop-index-1%::*} by "" to {_output::*}
return {_output::*}
Usage
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 chatcomponent pjson 0 of event-packet as readable text
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 {_last-message} as chat component # Uses the message to component expression