I got an error with JSON.sk, whenever I try to write something in chat, nothing happens, and this is what it gives me in Console.
Here is my Script:
code_language.skript:
Invalid json: Unterminated object at line 1 column 14
Here is my Script:
code_language.skript:
on chat:
player has permission "test.member"
cancel event
set {_to} to "%player%"
set {_msg} to "test||sgt:/messg %player% || &3%player%&1 %message%||sgt:/messg %player% "
json({_to}, {_msg})
code_language.skript:
function removeColor(msg: text) :: text:
set {_m::*} to {_msg} split at ""
set {_color-codes} to "{@codes}"
set {_colors::*} to {_color-codes} split at "|"
set {_new} to ""
loop {_m::*}:
set {_char} to loop-value
set {_prev} to the last character of {_new}
if {_prev} is "&":
loop {_colors::*}:
if loop-value-2 is {_char}:
set {_skip} to true
if {_skip} is set:
delete {_skip}
else:
set {_new} to "%{_new}%%{_char}%"
return {_new}
function jsonColorize(msg: text, default-color: text = "&r") :: text:
set {_m::*} to {_msg} split at ""
set {_color-codes} to "{@codes}"
set {_colors::*} to {_color-codes} split at "|"
set {_color} to colored {_default-color}
set {_code} to the first character of {_color}
set {_new} to ""
set {_skip} to 0
loop amount of {_m::*} times:
if {_skip} is more than or equal to 1:
subtract 1 from {_skip}
else:
set {_char} to {_m::%loop-number%}
set {_next} to {_m::%loop-number + 1%}
if {@debug} is true:
broadcast "&a[Character Check] &r%loop-number%: &7%{_char}% &r&onext: &8%{_next}% &r[%{_color}%color&r]"
if {_char} is "&" or {_code}:
if {@debug} is true:
broadcast "&a[Color Check] &rFOUND: &o%{_char}%%{_next}% &7&m<--&7&o is it valid?"
loop {_colors::*}:
if loop-value-2 is {_next}:
set {_color} to "%{_color}%%{_code}%%{_next}%"
if {_next} is "r":
set {_color} to {_default-color}
set {_new} to "%{_new}%%{_color}%"
set {_skip} to 1
if {_skip} is less than or equal to 0:
set {_new} to "%{_new}%%{_char}%"
else if {_char} is " ":
set {_new} to "%{_new}% %{_color}%"
else:
set {_new} to "%{_new}%%{_char}%"
return {_new}
function jsonSanitize(msg: text) :: text:
if {@debug} is true:
broadcast "&a[Sanitize] &7&oSanitizing input..."
set {_m::*} to {_msg} split at ""
loop {_m::*}:
if loop-value is """":
set {_m::%loop-index%} to "\""" # """
else if loop-value is "\":
set {_m::%loop-index%} to "\\"
set {_new} to join {_m::*} with ""
return {_new}
function jsonFormat(msg: text, color: boolean = true) :: text:
set {_m::*} to {_msg} split at "||"
set {_current} to 1
loop {_m::*}:
if {_clusters::%{_current}%} is not set:
set {_clusters::%{_current}%} to ""
if {_clusters::%{_current}%::text} is not set:
set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
else:
set {_tag} to the first 4 characters of loop-value
set {_value} to subtext of loop-value from characters 5 to the length of loop-value
if {_tag} is "ttp:":
set {_clusters::%{_current}%::tooltip} to jsonSanitize({_value})
else if {_tag} is "cmd:":
set {_clusters::%{_current}%::command} to jsonSanitize({_value})
else if {_tag} is "sgt:":
set {_clusters::%{_current}%::suggest} to jsonSanitize({_value})
else if {_tag} is "url:":
if {_value} doesn't contain "http://" or "https://":
set {_value} to "http://%{_value}%"
set {_clusters::%{_current}%::url} to jsonSanitize({_value})
else if {_tag} is "ins:":
set {_clusters::%{_current}%::insertion} to jsonSanitize({_value})
else:
add 1 to {_current}
set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
set {_clusters::%{_current}%} to ""
if {@debug} is true:
broadcast "&a[Tag Check] &3cluster:&b%{_current}% &8(&f&o%{_tag}%&8)"
loop {_clusters::*}:
if {@debug} is true:
broadcast "&a[Cluster Check] &7&oCluster ##%loop-index% exists."
set {_i} to loop-index
set {_text} to {_clusters::%{_i}%::text}
if {_color} is true:
set {_text} to jsonColorize({_text})
if {_json} is not set:
set {_json} to "{""text"":""%{_text}%"""
else:
set {_json} to "%{_json}%,{""text"":""%{_text}%"""
if {_clusters::%{_i}%::tooltip} is set:
if {_color} is true:
set {_tooltip} to jsonColorize({_clusters::%{_i}%::tooltip})
else:
set {_tooltip} to {_clusters::%{_i}%::tooltip}
set {_json} to "%{_json}%,""hoverEvent"":{""action"": ""show_text"",""value"": ""%{_tooltip}%""}"
if {_clusters::%{_i}%::insertion} is set:
set {_json} to "%{_json}%,""insertion"":""%{_clusters::%{_i}%::insertion}%"",""obfuscated"":false"
if {_clusters::%{_i}%::command} is set:
set {_clickable} to "%{_json}%,""clickEvent"":{""action"":""run_command"",""value"":""%{_clusters::%{_i}%::command}%""}"
if {_clusters::%{_i}%::suggest} is set:
set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""suggest_command"",""value"": ""%{_clusters::%{_i}%::suggest}%""}"
if {_clusters::%{_i}%::url} is set:
set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""open_url"",""value"": ""%{_clusters::%{_i}%::url}%""}"
if {_clickable} is set:
set {_json} to "%{_clickable}%}"
delete {_clickable}
else:
set {_json} to "%{_json}%}"
return "{""text"":"""", ""extra"":[%{_json}%]}"
function json(to: text, msg: text, color: boolean = false):
set {_msg} to jsonFormat({_msg}, {_color})
execute console command "/tellraw @a %{_msg}%"
if {@debug} is true:
set {_player} to {_to} parsed as offline player
if {_player} is online:
send uncolored {_msg} to {_player}