· 7 years ago · Feb 26, 2019, 07:08 PM
1options:
2 debug: false
3 codes: 0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|k|l|m|n|o|r
4
5#
6# FUNCTION: Remove all `&` color codes.
7# -> Usage:
8# Geneal purpose function to remove color codes.
9# This function will not remove color codes already converted.
10#
11
12function removeColor(msg: text) :: text:
13 set {_m::*} to {_msg} split at ""
14
15 set {_color-codes} to "{@codes}"
16 set {_colors::*} to {_color-codes} split at "|"
17
18 set {_new} to ""
19
20 loop {_m::*}:
21 set {_char} to loop-value
22 set {_prev} to the last character of {_new}
23
24 if {_prev} is "&":
25
26 loop {_colors::*}:
27
28 if loop-value-2 is {_char}:
29 set {_skip} to true
30
31 if {_skip} is set:
32 delete {_skip}
33
34 else:
35 set {_new} to "%{_new}%%{_char}%"
36
37 return {_new}
38
39#
40# FUNCTION: Replace all `&` color codes with valid JSON color codes.
41# -> Usage:
42# Used by json functions to convert color codes.
43#
44
45function jsonColorize(msg: text, default-color: text = "&r") :: text:
46 set {_m::*} to {_msg} split at ""
47
48 set {_color-codes} to "{@codes}"
49 set {_colors::*} to {_color-codes} split at "|"
50
51 set {_color} to colored {_default-color}
52 set {_code} to the first character of {_color}
53
54 set {_new} to ""
55 set {_skip} to 0
56
57 loop amount of {_m::*} times:
58
59 if {_skip} is more than or equal to 1:
60 subtract 1 from {_skip}
61
62 else:
63 set {_char} to {_m::%loop-number%}
64 set {_next} to {_m::%loop-number + 1%}
65
66 if {@debug} is true:
67 broadcast "&a[Character Check] &r%loop-number%: &7%{_char}% &r&onext: &8%{_next}% &r[%{_color}%color&r]"
68
69 if {_char} is "&" or {_code}:
70
71 if {@debug} is true:
72 broadcast "&a[Color Check] &rFOUND: &o%{_char}%%{_next}% &7&m<--&7&o is it valid?"
73
74 loop {_colors::*}:
75
76 if loop-value-2 is {_next}:
77 set {_color} to "%{_color}%%{_code}%%{_next}%"
78
79 if {_next} is "r":
80 set {_color} to {_default-color}
81
82 set {_new} to "%{_new}%%{_color}%"
83 set {_skip} to 1
84
85 if {_skip} is less than or equal to 0:
86 set {_new} to "%{_new}%%{_char}%"
87
88 else if {_char} is " ":
89 set {_new} to "%{_new}% %{_color}%"
90
91 else:
92 set {_new} to "%{_new}%%{_char}%"
93
94 return {_new}
95
96#
97# FUNCTION: Replace all json-breaking characters.
98# -> Usage:
99# Used by json functions to avoid errors.
100# Allows usage of quotes and back-slashes in your json.
101#
102
103function jsonSanitize(msg: text) :: text:
104 if {@debug} is true:
105 broadcast "&a[Sanitize] &7&oSanitizing input..."
106
107 set {_m::*} to {_msg} split at ""
108
109 loop {_m::*}:
110
111 if loop-value is """":
112 set {_m::%loop-index%} to "\""" # """
113
114 else if loop-value is "\":
115 set {_m::%loop-index%} to "\\"
116
117 set {_new} to join {_m::*} with ""
118 return {_new}
119
120#
121# FUNCTION: Generate a new /tellraw json object from a json.sk-notation string.
122# -> Usage:
123# See the top of this skript, listed under general usage.
124#
125
126function jsonFormat(msg: text, color: boolean = true) :: text:
127 set {_m::*} to {_msg} split at "||"
128
129 set {_current} to 1
130
131 loop {_m::*}:
132 if {_clusters::%{_current}%} is not set:
133 set {_clusters::%{_current}%} to ""
134
135 if {_clusters::%{_current}%::text} is not set:
136 set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
137
138 else:
139 set {_tag} to the first 4 characters of loop-value
140 set {_value} to subtext of loop-value from characters 5 to the length of loop-value
141
142 if {_tag} is "ttp:":
143 set {_clusters::%{_current}%::tooltip} to jsonSanitize({_value})
144
145 else if {_tag} is "cmd:":
146 set {_clusters::%{_current}%::command} to jsonSanitize({_value})
147
148 else if {_tag} is "sgt:":
149 set {_clusters::%{_current}%::suggest} to jsonSanitize({_value})
150
151 else if {_tag} is "url:":
152
153 if {_value} doesn't contain "http://" or "https://":
154 set {_value} to "http://%{_value}%"
155
156 set {_clusters::%{_current}%::url} to jsonSanitize({_value})
157
158 else if {_tag} is "ins:":
159 set {_clusters::%{_current}%::insertion} to jsonSanitize({_value})
160
161 else:
162 add 1 to {_current}
163 set {_clusters::%{_current}%::text} to jsonSanitize(loop-value)
164 set {_clusters::%{_current}%} to ""
165
166 if {@debug} is true:
167 broadcast "&a[Tag Check] &3cluster:&b%{_current}% &8(&f&o%{_tag}%&8)"
168
169 loop {_clusters::*}:
170
171 if {@debug} is true:
172 broadcast "&a[Cluster Check] &7&oCluster ##%loop-index% exists."
173
174 set {_i} to loop-index
175
176 set {_text} to {_clusters::%{_i}%::text}
177
178 if {_color} is true:
179 set {_text} to jsonColorize({_text})
180
181 if {_json} is not set:
182 set {_json} to "{""text"":""%{_text}%"""
183 else:
184 set {_json} to "%{_json}%,{""text"":""%{_text}%"""
185
186 if {_clusters::%{_i}%::tooltip} is set:
187
188 if {_color} is true:
189 set {_tooltip} to jsonColorize({_clusters::%{_i}%::tooltip})
190
191 else:
192 set {_tooltip} to {_clusters::%{_i}%::tooltip}
193
194 set {_json} to "%{_json}%,""hoverEvent"":{""action"": ""show_text"",""value"": ""%{_tooltip}%""}"
195
196 if {_clusters::%{_i}%::insertion} is set:
197 set {_json} to "%{_json}%,""insertion"":""%{_clusters::%{_i}%::insertion}%"",""obfuscated"":false"
198
199 if {_clusters::%{_i}%::command} is set:
200 set {_clickable} to "%{_json}%,""clickEvent"":{""action"":""run_command"",""value"":""%{_clusters::%{_i}%::command}%""}"
201
202 if {_clusters::%{_i}%::suggest} is set:
203 set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""suggest_command"",""value"": ""%{_clusters::%{_i}%::suggest}%""}"
204
205 if {_clusters::%{_i}%::url} is set:
206 set {_clickable} to "%{_json}%,""clickEvent"":{""action"": ""open_url"",""value"": ""%{_clusters::%{_i}%::url}%""}"
207
208 if {_clickable} is set:
209 set {_json} to "%{_clickable}%}"
210 delete {_clickable}
211
212 else:
213 set {_json} to "%{_json}%}"
214
215 return "{""text"":"""", ""extra"":[%{_json}%]}"
216
217#
218# FUNCTION: Send a json message with json.sk-notation.
219# -> Usage:
220# See the top of this skript, listed under general usage.
221#
222
223function json(to: text, msg: text, color: boolean = true):
224 set {_msg} to jsonFormat({_msg}, {_color})
225 execute console command "/tellraw %{_to}% %{_msg}%"
226
227 if {@debug} is true:
228 set {_player} to {_to} parsed as offline player
229 if {_player} is online:
230 send uncolored {_msg} to {_player}
231
232#
233# FUNCTION: Broadcast a json message with json.sk-notation.
234#
235
236options:
237 prefix: &c&lSTAFFS
238 server: MassivePvP
239
240script options:
241 $ db url jdbc:mysql://customer.iqu.dk:3306/609_61
242 $ db username
243 $ db password
244
245on script load:
246 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));"
247
248function isStaff(uuid: object) :: boolean:
249 set {_staffs::*} to objects in column "uuid" from result of query "SELECT uuid FROM staffs" and close
250 loop {_staffs::*}:
251 if loop-value is {_uuid}:
252 return true
253 return false
254
255function isOnline(uuid: object) :: boolean:
256 set {_online::*} to objects in column "online" from result of query "SELECT online FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
257 if {_online::1} is true:
258 return true
259 return false
260
261function getIgn(uuid: object) :: text:
262 set {_ign::*} to objects in column "ign" from result of query "SELECT ign FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
263 return {_ign::1}
264
265function getServer(uuid: object) :: text:
266 set {_server::*} to objects in column "server" from result of query "SELECT server FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
267 return {_server::1}
268
269function lastSeen(uuid: object) :: text:
270 set {_lastSeen::*} to objects in column "lastseen" from result of query "SELECT lastseen FROM staffs WHERE `uuid`=""%{_uuid}%""" and close
271 return {_lastSeen::1}
272
273on join:
274 if isStaff(uuid of player) is true:
275 wait 1 second
276 update "UPDATE `staffs` SET `ign`=""%player%"", `online`=1, `server`=""{@server}"" WHERE `uuid`=""%uuid of player%"""
277
278on quit:
279 if isStaff(uuid of player) is true:
280 update "UPDATE `staffs` SET `online`=0, `lastseen`=""%now%"" WHERE `uuid`=""%uuid of player%"""
281
282command /staffs [<text>] [<text>] [<text>]:
283 aliases: /stafflist
284 trigger:
285 wait 3 ticks
286 set {_groups::*} to "ejer", "med-ejer", "head-admin", "admin", "manager", "tekniker", "mod" and "hjælper"
287 if arg 1 isn't set:
288 loop {_groups::*}:
289 set {_group} to loop-value
290 set {_%{_group}%::*} to objects in column "uuid" from result of query "SELECT uuid FROM `staffs` WHERE `group`=""%{_group}%""" and close
291
292 send "&8&m---------+=&8( {@prefix} &8)&8&m=+---------"
293 send ""
294 loop {_ejer::*}:
295 if isOnline(loop-value) is true:
296 json("%player%", "&8[&4Ejer&8] &4%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
297 else:
298 json("%player%", "&8[&4Ejer&8] &4%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
299 send ""
300 loop {_med-ejer::*}:
301 if isOnline(loop-value) is true:
302 json("%player%", "&8[&4Med-Ejer&8] &4%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
303 else:
304 json("%player%", "&8[&4Med-Ejer&8] &4%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
305 send ""
306 loop {_head-admin::*}:
307 if isOnline(loop-value) is true:
308 json("%player%", "&8[&cHead-Admin&8] &c%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
309 else:
310 json("%player%", "&8[&cHead-Admin&8] &c%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
311 send ""
312 loop {_admin::*}:
313 if isOnline(loop-value) is true:
314 json("%player%", "&8[&5Admin&8] &5%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
315 else:
316 json("%player%", "&8[&5Admin&8] &5%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
317 send ""
318 loop {_manager::*}:
319 if isOnline(loop-value) is true:
320 json("%player%", "&8[&3Manager&8] &3%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
321 else:
322 json("%player%", "&8[&3Manager&8] &3%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
323 send ""
324 loop {_tekniker::*}:
325 if isOnline(loop-value) is true:
326 json("%player%", "&8[&eTekniker&8] &3%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
327 else:
328 json("%player%", "&8[&eTekniker&8] &e%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
329 send ""
330 loop {_mod::*}:
331 if isOnline(loop-value) is true:
332 json("%player%", "&8[&dMod&8] &d%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
333 else:
334 json("%player%", "&8[&dMod&8] &d%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
335 send ""
336 loop {_hjælper::*}:
337 if isOnline(loop-value) is true:
338 json("%player%", "&8[&9Hjælper&8] &9%getIgn(loop-value)% &8(&aOnline&8)||ttp:&3%getServer(loop-value)%")
339 else:
340 json("%player%", "&8[&9Hjælper&8] &9%getIgn(loop-value)% &8(&cOffline&8)||ttp:&3%lastSeen(loop-value)%")
341 send ""
342 set {_online} to 0
343 set {_total} to 0
344 set {_online::*} to objects in column "online" from result of query "SELECT online FROM staffs" and close
345 loop {_online::*}:
346 if loop-value is true:
347 add 1 to {_online}
348 add 1 to {_total}
349 send "&7Der i alt &b%{_online}%&8/&b%{_total}%&7 staffs online&8."
350 send ""
351 send "&8&m---------+=&8( {@prefix} &8)&8&m=+---------"
352
353 else if player has permission "*":
354 if arg 1 is "addstaff":
355 if arg 2 parsed as a offline player is set:
356 if isStaff(uuid of arg 2 parsed as a offline player) is false:
357 if arg 3 is set:
358 loop {_groups::*}:
359 if loop-value is arg 3:
360 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}"")"
361 send "{@prefix} &8» &bDu har tilføjet &3%arg 2%&b til gruppen &3%arg 3%&b!"
362 stop
363 send "{@prefix} &8» &bGruppen &3%arg 3%&b findes ikke.."
364 else:
365 send "{@prefix} &8» &bVenligst definér en gruppe.."
366 else:
367 send "{@prefix} &8» &3%arg 2%&b er allerede staff.."
368 else:
369 send "{@prefix} &8» &bVenligst angiv en spiller.."
370
371 else if arg 1 is "remstaff" or "delstaff":
372 if arg 2 parsed as a offline player is set:
373 if isStaff(uuid of arg 2 parsed as a offline player) is true:
374 update "DELETE FROM `staffs` WHERE `uuid`=""%uuid of arg 2 parsed as a offline player%"""
375 send "{@prefix} &8» &bDu har fjernet &3%arg 2%&b fra databasen!"
376 else:
377 send "{@prefix} &8» &3%arg 2%&b er ikke staff.."
378 else:
379 send "{@prefix} &8» &bVenligst angiv en spiller.."
380
381 else:
382 execute player command "/staff"
383 else:
384 execute player command "/staff"