Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options:
- debug: false
- codes: 0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|k|l|m|n|o|r
- #
- # FUNCTION: Remove all `&` color codes.
- # -> Usage:
- # Geneal purpose function to remove color codes.
- # This function will not remove color codes already converted.
- #
- 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: Replace all `&` color codes with valid JSON color codes.
- # -> Usage:
- # Used by json functions to convert color codes.
- #
- 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: Replace all json-breaking characters.
- # -> Usage:
- # Used by json functions to avoid errors.
- # Allows usage of quotes and back-slashes in your json.
- #
- 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: Generate a new /tellraw json object from a json.sk-notation string.
- # -> Usage:
- # See the top of this skript, listed under general usage.
- #
- 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: Send a json message with json.sk-notation.
- # -> Usage:
- # See the top of this skript, listed under general usage.
- #
- function json(to: text, msg: text, color: boolean = true):
- set {_msg} to jsonFormat({_msg}, {_color})
- execute console command "/tellraw %{_to}% %{_msg}%"
- if {@debug} is true:
- set {_player} to {_to} parsed as offline player
- if {_player} is online:
- send uncolored {_msg} to {_player}
- #
- # FUNCTION: Broadcast a json message with json.sk-notation.
- #
- options:
- prefix: &c&lSTAFFS
- server: MassivePvP
- script options:
- $ db url jdbc:mysql://customer.iqu.dk:3306/609_61
- $ db username
- $ db password
- on script load:
- update "CREATE TABLE IF NOT EXISTS `staffs` (`uuid` varchar(255) NOT NULL, `ign` varchar(255) NOT NULL, `group` varchar(255) NOT NULL, online tinyint(1) DEFAULT 1 NOT NULL, lastseen varchar(255), server varchar(255));"
- function isStaff(uuid: object) :: boolean:
- set {_staffs::*} to objects in column "uuid" from result of query "SELECT uuid FROM staffs" and close
- loop {_staffs::*}:
- if loop-value is {_uuid}:
- return true
- return false
- function isOnline(uuid: object) :: boolean:
- set {_online::*} to objects in column "online" from result of query "SELECT online FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
- if {_online::1} is true:
- return true
- return false
- function getIgn(uuid: object) :: text:
- set {_ign::*} to objects in column "ign" from result of query "SELECT ign FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
- return {_ign::1}
- function getServer(uuid: object) :: text:
- set {_server::*} to objects in column "server" from result of query "SELECT server FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
- return {_server::1}
- function lastSeen(uuid: object) :: text:
- set {_lastSeen::*} to objects in column "lastseen" from result of query "SELECT lastseen FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
- return {_lastSeen::1}
- on join:
- if isStaff(uuid of player) is true:
- wait 1 second
- update "UPDATE `staffs` SET `ign`=""%player%"", `online`=1, `server`=""{@server}"" WHERE `uuid`=""%uuid of player%"""
- on quit:
- if isStaff(uuid of player) is true:
- update "UPDATE `staffs` SET `online`=0, `lastseen`=""%now%"" WHERE `uuid`=""%uuid of player%"""
- command /staffs [<text>] [<text>] [<text>]:
- aliases: /stafflist
- trigger:
- wait 3 ticks
- set {_groups::*} to "ejer", "med-ejer", "head-admin", "admin", "manager", "tekniker", "mod" and "hjælper"
- if arg 1 isn't set:
- loop {_groups::*}:
- set {_group} to loop-value
- set {_%{_group}%::*} to objects in column "uuid" from result of query "SELECT uuid FROM `staffs` WHERE `group`=""%{_group}%""" and close
- send "&8&m---------+=&8( {@prefix} &8)&8&m=+---------"
- send ""
- loop {_ejer::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&4Ejer&8] &4%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&4Ejer&8] &4%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_med-ejer::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&4Med-Ejer&8] &4%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&4Med-Ejer&8] &4%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_head-admin::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&cHead-Admin&8] &c%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&cHead-Admin&8] &c%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_admin::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&5Admin&8] &5%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&5Admin&8] &5%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_manager::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&3Manager&8] &3%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&3Manager&8] &3%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_tekniker::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&eTekniker&8] &3%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&eTekniker&8] &e%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_mod::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&dMod&8] &d%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&dMod&8] &d%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- loop {_hjælper::*}:
- if isOnline(loop-value) is true:
- json("%player%", "&8[&9Hjælper&8] &9%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
- else:
- json("%player%", "&8[&9Hjælper&8] &9%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
- send ""
- set {_online} to 0
- set {_total} to 0
- set {_online::*} to objects in column "online" from result of query "SELECT online FROM staffs" and close
- loop {_online::*}:
- if loop-value is true:
- add 1 to {_online}
- add 1 to {_total}
- send "&7Der i alt &b%{_online}%&8/&b%{_total}%&7 staffs online&8."
- send ""
- send "&8&m---------+=&8( {@prefix} &8)&8&m=+---------"
- else if player has permission "*":
- if arg 1 is "addstaff":
- if arg 2 parsed as a offline player is set:
- if isStaff(uuid of arg 2 parsed as a offline player) is false:
- if arg 3 is set:
- loop {_groups::*}:
- if loop-value is arg 3:
- update "INSERT INTO `staffs` (`uuid`, `ign`, `group`, `online`, lastseen, server) VALUES (""%uuid of arg 2 parsed as a offline player%"", ""%arg 2%"", ""%arg 3%"", 0, ""%now%"", ""{@server}"")"
- send "{@prefix} &8» &bDu har tilføjet &3%arg 2%&b til gruppen &3%arg 3%&b!"
- stop
- send "{@prefix} &8» &bGruppen &3%arg 3%&b findes ikke.."
- else:
- send "{@prefix} &8» &bVenligst definér en gruppe.."
- else:
- send "{@prefix} &8» &3%arg 2%&b er allerede staff.."
- else:
- send "{@prefix} &8» &bVenligst angiv en spiller.."
- else if arg 1 is "remstaff" or "delstaff":
- if arg 2 parsed as a offline player is set:
- if isStaff(uuid of arg 2 parsed as a offline player) is true:
- update "DELETE FROM `staffs` WHERE `uuid`=""%uuid of arg 2 parsed as a offline player%"""
- send "{@prefix} &8» &bDu har fjernet &3%arg 2%&b fra databasen!"
- else:
- send "{@prefix} &8» &3%arg 2%&b er ikke staff.."
- else:
- send "{@prefix} &8» &bVenligst angiv en spiller.."
- else:
- execute player command "/staff"
- else:
- execute player command "/staff"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement