options: #marudaChat - wydanie trzecie dir: plugins/Skript/Maruda Chat/ config: plugins/Skript/Maruda Chat/config.yml messages: plugins/Skript/Maruda Chat/messages.yml #permissions: plugins/Skript/Maruda Chat/permission.txt #players: plugins/Skript/Maruda Chat/players/ #-------------------(funkcje)------------------- #funkcja tworzy zmienne na podstawie ich zawartości z konfiguracji yaml function setVariables(path: string, name: string): set {_yamlPath} to {_path} replace "." with "::" in {_path} if skript-yaml list {_yamlPath} from {_name} is set: loop skript-yaml list {_yamlPath} from {_name}: add (formatted "%loop-value%") to {marudaChat::%{_name}%::%{_path}%::*} else: if skript-yaml value {_yamlPath} from {_name} is a text: add formatted (skript-yaml value {_yamlPath} from {_name}) to {marudaChat::%{_name}%::%{_path}%::*} else: set {marudaChat::%{_name}%::%{_path}%} to skript-yaml value {_yamlPath} from {_name} #funkcja pobiera zawartość konfiguracji i ustawia zmienne function loadVariables(file: string, name: string): delete {marudaChat::%{_name}%::*} unload yaml {_file} load yaml {_file} set {_list::*} to skript-yaml node list "" from {_name} loop {_list::*}: if skript-yaml node list loop-value from {_name} is set: loop skript-yaml node list loop-value from {_name}: if skript-yaml node list loop-value-2 from {_name} is set: loop skript-yaml node list loop-value-2 from {_name}: setVariables(loop-value-3, {_name}) else: setVariables(loop-value-2, {_name}) else: setVariables(loop-value, {_name}) #funkcja wyciąga odgległość zawartą w nawiasach kwadratowych - do chatu na odległość function getDistanceFromString(t: string) :: number: if {_} starts with "[": set {_subtext} to subtext of {_} from character 2 to character ((first index of "]" in {_}) - 1) set {_i} to {_subtext} parsed as integer if {_i} is an integer: if {_i} < 0: set {_i} to ({_i} * (-1)) else: set {_i} to 0 return {_i} #wiadomość jest czyszczona z odległości do chatu na odległość function removeDistanceFromString(t: string) :: string: set {_return} to subtext of {_t} from character ((first index of "]" in {_t}) + 1) to character (length of {_t}) return {_return} #funkcja odpowiada za wstawianie wybranych wartości za zmienne z konfiguracji messages.yml function replaceExpressions(msg: strings, list: strings) :: strings: loop {_list::*}: set {_value::*} to loop-value split at "-" loop {_msg::*}: replace {_value::1} with {_value::2} in {_msg::%loop-index-2%} return {_msg::*} #Funkcja sprawdza czy gracz lub globalny chat jest wyciszony function checkPlayerMute(p: string) :: boolean: if now < {VARmarudaChat::mute::%{_p}%}: return true return false #funkcja zamienia emotikony w podanym tekscie function replaceEmotes(msg: string) :: string: loop {marudaChat::config::emotes::*}: replace all "%loop-value%" with "%{marudaChat::emotes::%loop-value%}%" in {_msg} return {_msg} #funkcja sprawdza czy gracz może używać zdefiniowanych komend function checkCommand(cmd: string, p: player) :: boolean: if {marudaChat::config::commands::block} is true: loop {marudaChat::config::commands::list::*}: if loop-value is {_cmd}: if {_p} has permission "chatmanager.*": return true return false return true else: loop {marudaChat::config::commands::list::*}: if loop-value is {_cmd}: return true if {_p} has permission "chatmanager.*": return true return false loop {marudaChat::config::commands::list::*}: if loop-value is {_cmd}: if {marudaChat::config::commands::block}: if {_p} do not have permission "chatmanager.*": return false return true else: return true if {marudaChat::config::commands::block} is false: return false #funkcja odpowiada za rozpoczęcie i wysyłanie automatycznych wiadomości do graczy function sendAutomessage(t: string, p: player): if {_t} is "": set {_t} to "playerTime::%{_p}%" add {_p} to {_recipients::*} else: set {_t} to "serverTime" set {_nodes::*} to skript-yaml node keys "automessage.list" from "config" if {marudaChat::config::automessage::random} is true: set {_now} and {marudaChat::config::automessage::%{_t}%} to now while {_now} is {marudaChat::config::automessage::%{_t}%}: set {_random} to random element out of {_nodes::*} #broadcast {_random} wait {marudaChat::config::automessage::interval} if script is loaded: if {_t} is "serverTime": set {_recipients::*} to all players send formatted {marudaChat::config::automessage::list::%{_random}%::*} to {_recipients::*} else: stop else: while {_now} is {marudaChat::config::automessage::%{_t}%}: loop {_nodes::*}: wait {marudaChat::config::automessage::interval} if script is loaded: if {_now} is {marudaChat::config::automessage::%{_t}%}: if {_t} is "serverTime": set {_recipients::*} to all players send formatted {marudaChat::config::automessage::list::%loop-value%::*} to {_recipients::*} else: stop else: stop #-------------------(wydarzenia)------------------- #wydarzenie nasłuchuje chatów graczy i sprawdza mute, odległości, listy ignore oraz umieszcza w tekscie emotki on chat: if checkPlayerMute("gm") is false: if checkPlayerMute(name of player) is false: set {_dist} to getDistanceFromString(uncoloured message) if {_dist} is not 0: set message to removeDistanceFromString(message) set {_dist} to 10000000000 loop all players: if world of loop-player is world of player: if distance between player and loop-player > {_dist}: remove loop-player from chat recipients if {VARmarudaChat::ignore::%loop-player%::all} is true: remove loop-player from chat recipients else: loop {VARmarudaChat::ignore::%loop-player%::players::*}: if loop-value-2 is player: remove loop-player from chat recipients set message to replaceEmotes(message) else: cancel event set {_date} to {VARmarudaChat::mute::%player%} formatted as "dd.MM.YYYY HH:mm:ss" send formatted replaceExpressions({marudaChat::messages::chat-deny::*}, ("[date]-%{_date}%")) else: cancel event send formatted {marudaChat::messages::global-chat-deny::*} #wydarzenie czyszczące automatyczne wiadomości po wyjściu gracza z serwera on disconnect: delete {marudaChat::config::automessage::playerTime::%player%} #sprawdzanie czy gracz ma zezwolenie do użycia komendy on command: if sender is not console: if checkCommand(command, player) is false: send formatted {marudaChat::messages::command-deny::*} cancel event #gdy gracz wchodzi na serwer, uruchamiane jest automessage on join: if {marudaChat::config::automessage::status} is true: if {marudaChat::config::automessage::interval} is set: if {marudaChat::config::automessage::player} is true: sendAutomessage("", player) else: if size of all players <= 1: sendAutomessage("serverTime", player) #podczas ładowania skryptu tworzone są pliki, zmienne i cała konfiguracja on load: delete {marudaChat::*} if file "{@config}" does not exist: create dir "{@dir}" download file from "https://code.skript.pl/9dmYNRCt/raw" to file "{@messages}" download file from "https://code.skript.pl/8BPISFvk/raw" to file "{@config}" wait 2 tick if file "{@config}" exists: loadVariables("{@config}", "config") loadVariables("{@messages}", "messages") clear {clearchat::*} loop 100 times: add "" to {clearchat::*} loop {marudaChat::config::emotes::*}: set {_emote::*} to loop-value split at " -|- " set {marudaChat::emotes::%{_emote::1}%} to {_emote::2} add {_emote::1} to {_lista::*} set {marudaChat::config::emotes::*} to {_lista::*} set {marudaChat::config::automessage::interval} to "%{marudaChat::config::automessage::interval}% seconds" parsed as timespan #-------------------(komendy)------------------- #administracyjna komenda do zarządzania skryptem command /chatmanager [] []: aliases: chat, cm permission: chatmanager.* trigger: if arg 1 is not set: send formatted {marudaChat::messages::help::*} else: if arg 1 is "reload": if arg 2 is "all": reload script script send formatted {marudaChat::messages::chat-loaded-script::*} else if arg 2 is "config": loadVariables("{@config}", "config") send formatted {marudaChat::messages::chat-loaded-config::*} else if arg 2 is "messages": loadVariables("{@messages}", "messages") send formatted {marudaChat::messages::chat-loaded-messages::*} #komenda do wyciszania graczy oraz głównego chatu command /mute [] [] [] []: trigger: if argument 1 is set: if argument 1 is not "gm": set {_player} to argument 1 parsed as offline player if {_player} has not played before: send formatted replaceExpressions({marudaChat::messages::player-does-not-exist::*}, ("[player]-%{_player}%")) stop if argument 2 is set: set {_time} to argument 2 if {_time} is not 0: set {_time} to abs({_time}) set {_now} to now if argument 3 is set: if argument 3 is "s" or "sekund" or "sekundy": add ("%{_time}% seconds" parsed as timespan) to {_now} else if argument 3 is "m" or "minut" or "minuty": add ("%{_time}% minutes" parsed as timespan) to {_now} else if argument 3 is "h" or "g" or "godzin" or "godziny": add ("%{_time}% hours" parsed as timespan) to {_now} else if argument 3 is "d" or "dzien" or "dni": add ("%{_time}% days" parsed as timespan) to {_now} else: send formatted {marudaChat::messages::no-timespan::*} stop else: send formatted {marudaChat::messages::no-timespan::*} stop set {VARmarudaChat::mute::%argument 1%} to {_now} if argument 4 is set: set {_reason} to argument 4 else: set {_reason} to {marudaChat::messages::default-reason::1} set {_date} to {_now} formatted as "dd.MM.YYYY HH:mm:ss" if argument 1 is "gm": broadcast replaceExpressions({marudaChat::messages::global-chat-muted::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[timespan]-%argument 2% %argument 3%" and "[date]-%{_date}%")) else: if {marudaChat::config::mute-send-to::1} is "all": broadcast replaceExpressions({marudaChat::messages::player-muted::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[player]-%{_player}%", "[timespan]-%{_time}% %argument 3%" and "[date]-%{_date}%")) else: if {marudaChat::config::mute-send-to::1} is "ops": send formatted replaceExpressions({marudaChat::messages::player-muted::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[player]-%{_player}%", "[timespan]-%{_time}% %argument 3%" and "[date]-%{_date}%")) to all ops send formatted replaceExpressions({marudaChat::messages::muted-by::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[timespan]-%{_time}% %argument 3%" and "[date]-%{_date}%")) to {_player} else if {marudaChat::config::mute-send-to::1} is "admin": send formatted replaceExpressions({marudaChat::messages::player-muted::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[player]-%{_player}%", "[timespan]-%{_time}% %argument 3%" and "[date]-%{_date}%")) to sender send formatted replaceExpressions({marudaChat::messages::muted-by::*}, ("[reason]-%{_reason}%", "[admin]-%sender%", "[timespan]-%{_time}% %argument 3%" and "[date]-%{_date}%")) to {_player} else: if argument 1 is "gm": broadcast formatted replaceExpressions({marudaChat::messages::global-chat-unmuted::*}, ("[admin]-%sender%")) else: broadcast formatted replaceExpressions({marudaChat::messages::player-unmuted::*}, ("[admin]-%sender%" and "[player]-%{_player}%")) else: send formatted {marudaChat::messages::no-length::*} else: send formatted {marudaChat::messages::no-player-or-gm::*} #komenda dla graczy, do wyciszania innych command /ignore []: trigger: if argument 1 is set: if argument 1 is "all": if {VARmarudaChat::ignore::%player%::all} is true: set {VARmarudaChat::ignore::%player%::all} to false send formatted {marudaChat::messages::unignore-all::*} else: set {VARmarudaChat::ignore::%player%::all} to true send formatted {marudaChat::messages::ignore-all::*} else: set {_player} to arg 1 parsed as offline player if {_player} has played before: loop {VARmarudaChat::ignore::%player%::players::*}: if loop-value is {_player}: delete {VARmarudaChat::ignore::%player%::players::%loop-index%} send formatted replaceExpressions({marudaChat::messages::unignore-player::*}, ("[player]-%{_player}%")) stop add {_player} to {VARmarudaChat::ignore::%player%::players::*} send formatted replaceExpressions({marudaChat::messages::ignore-player::*}, ("[player]-%{_player}%")) else: send formatted replaceExpressions({marudaChat::messages::player-does-not-exist::*}, ("[player]-%argument 1%")) else: send formatted replaceExpressions({marudaChat::messages::ignored-list::*}, ("[list]-%{VARmarudaChat::ignore::%player%::players::*}%" and "[boolean]-%{VARmarudaChat::ignore::%player%::all}%")) #komenda do prywatnych wiadomości command /message [] []: aliases: m, msg trigger: if player has permission "chatmanager.message": if argument 1 is set: if argument 1 has played before: if argument 1 is online: if argument 2 is set: send formatted replaceExpressions({marudaChat::messages::format-to::*}, ("[recipient]-%argument 1%" and "[message]-%argument 2%")) if argument 1 is not sender: send formatted replaceExpressions({marudaChat::messages::format-from::*}, ("[sender]-%sender%" and "[message]-%argument 2%")) to argument 1 set {marudaChat::message::last::%argument 1%} to sender set {marudaChat::message::last::%sender%} to argument 1 else: send formatted {marudaChat::messages::no-message::*} else: send formatted replaceExpressions({marudaChat::messages::player-offline::*}, ("[player]-%argument 1%")) else: send formatted replaceExpressions({marudaChat::messages::player-offline::*}, ("[player]-%argument 1%")) else: send formatted replaceExpressions({marudaChat::messages::no-player::*}, ("[player]-%argument 1%")) else: replaceExpressions({marudaChat::messages::no-permission::*}, ("[permission]-chatmanager.reply")) #szybka odpowiedź na ostatnią wiadomość command /reply []: aliases: r trigger: if player has permission "chatmanager.reply": if argument 1 is set: if {marudaChat::message::last::%sender%} is online: send formatted replaceExpressions({marudaChat::messages::format-from::*}, ("[sender]-%sender%" and "[message]-%argument%")) to {marudaChat::message::last::%sender%} if {marudaChat::message::last::%sender%} is not sender: send formatted replaceExpressions({marudaChat::messages::format-to::*}, ("[recipient]-%{marudaChat::message::last::%sender%}%" and "[message]-%argument%")) set {marudaChat::message::last::%{marudaChat::message::last::%sender%}%} to sender else: send formatted {marudaChat::messages::no-recipient::*} else: send formatted {marudaChat::messages::no-message::*} else: send formatted replaceExpressions({marudaChat::messages::no-permission::*}, ("[permission]-chatmanager.reply")) #komenda do czyszczenia chatu, dostępna dla graczy oraz administracji command /clearchat []: aliases: cc, clearc, chatclear trigger: if player has permission "chatmanager.clearchat": if argument is set: if argument has played before: if argument is online: send {clearchat::*} to argument if argument is not player: send formatted replaceExpressions({marudaChat::messages::cleared-chat-of-player::*}, ("[player]-%argument%")) send formatted replaceExpressions({marudaChat::messages::chat-cleared-by-admin::*}, ("[admin]-%player%")) to argument else: send formatted replaceExpressions({marudaChat::messages::player-offline::*}, ("[player]-%argument%")) else: send formatted replaceExpressions({marudaChat::messages::player-does-not-exist::*}, ("[player]-%argument%")) else: set {_gracze::*} to all players loop {_gracze::*}: if loop-value is not an op: remove loop-value from {_gracze::*} send {clear::*} to {_gracze::*} send formatted replaceExpressions({marudaChat::messages::chat-cleared::*}, ("[admin]-%player%")) to all players else: if argument is set: send formatted replaceExpressions({marudaChat::messages::clearchat-others-deny::*}, ("[permission]-chatmanager.clearchat")) else: send {clear::*} to {_gracze::*} send formatted {marudaChat::messages::chat-cleared-by-player::*} to player