Last active
April 15, 2018 23:00
-
-
Save Snow-Pyon/9c3695929ac3e0939240147767535689 to your computer and use it in GitHub Desktop.
Convert a ChatComponent JSON message to a readable text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ChatComponent Converter by Snow-Pyon | |
# Requires: | |
# - MundoSK (and ProtocolLib with it) | |
# - skript-json (for the toJsonText function) | |
function toSkriptColor(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 toReadableText(json: jsonobject) :: text: | |
put json {_json} in listvar {_json::*} | |
loop tree of {_json::extra::*}: | |
if branch contains "color": | |
set {_color} to toSkriptColor("%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 "" | |
function toJsonText(messages: texts) :: jsonobjects: | |
loop {_messages::*}: | |
set {_message::text} to {_message} | |
set {_json::extra::1} to "%json of listvar {_json::*}%" | |
set {_json::text} to "" | |
set {_output::%loop-index%} to json of listvar {_json::*} | |
return {_output::*} | |
#Example | |
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 toReadableText("chatcomponent" pjson 0 of event-packet) | |
loop {deniedMessages::*}: | |
if {_last-message} contains loop-value: | |
cancel event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment