SteamWar/BauSystem2.0
Archiviert
12
0

Merge pull request 'Script System Lua' (#178) from lua into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #178
Dieser Commit ist enthalten in:
YoyoNow 2023-07-17 16:44:03 +02:00
Commit 9598838d2e
98 geänderte Dateien mit 1850 neuen und 6505 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
import javax.lang.model.element.TypeElement;
public class LuaLib_GENERIC implements LinkageType {
@Override
public String method() {
return "link";
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
buildPlan.addImport("de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin");
methodBuilder.addLine("SteamWarLuaPlugin.add(" + s + ");");
}
}

Datei anzeigen

@ -1,40 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
import javax.lang.model.element.TypeElement;
public class Operator_GENERIC implements LinkageType {
@Override
public String method() {
return "linkScriptCommands";
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
buildPlan.addImport("de.steamwar.bausystem.features.script.expression.Expression");
methodBuilder.addLine("Expression.registerOperator(" + s + ");");
}
}

Datei anzeigen

@ -1,40 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
import javax.lang.model.element.TypeElement;
public class SpecialCommand_GENERIC implements LinkageType {
@Override
public String method() {
return "linkScriptCommands";
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
buildPlan.addImport("de.steamwar.bausystem.features.script.ScriptExecutor");
methodBuilder.addLine("ScriptExecutor.SPECIAL_COMMANDS.add(" + s + ");");
}
}

Datei anzeigen

@ -64,4 +64,6 @@ dependencies {
annotationProcessor swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
implementation 'org.luaj:luaj-jse:3.0.1'
}

Datei anzeigen

@ -230,298 +230,25 @@ GUI_EDITOR_TITLE_MORE=Select item
# Script
## Errors
SCRIPT_SLEEP_ERROR = §cInsert a sleep into your script
SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnknown variable {0}
SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression error with: {0}
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cThe first argument is missing and should be a variable
SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cThe first argument is missing and should be a number
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cThe first argument is missing and should be a variable or a number
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cThe first argument is missing and should be a jump-point
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cThe second argument is missing and should be a variable
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cThe econd argument is missing and should be a value
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cThe second argument is missing and should be a jump-point
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cThe third argument is missing and should be a variable
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cThe third argument is missing and should be a value
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cThe third argument is missing and should be a variable or a number
SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cThe fourth argument is missing and should be a value
SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cOnly booleans can be compared
SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cOnly numbers can be compared
SCRIPT_COMMAND_ERROR_NO_BOOLEAN = §cThe value is not a boolean
SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cOnly strings are allowed
SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cOnly numbers are allowed
SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnknown operation: {0}
## Commands
SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cOnly numbers or strings can be added
SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cOnly numbers can be divided
SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cOnly numbers can be multiplied
SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cOnly numbers can be subtracted
SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cOnly numbers can be raised to a power
SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cOnly whole numbers can be used for modulo
SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cOnly whole numbers and booleans can be used for and
SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cOnly whole numbers and booleans can be used for or
SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cOnly whole numbers and booleans can be used for xor
SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR = §cOnly whole numbers can be used for left shift value
SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR = §cOnly whole numbers can be used for right shift value
SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR = §cOnly whole numbers can be used for logic right shift value
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Ceils the second number and writes it in the first or ceils the second number with the precision from the third number and writes it in the first
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cOnly floating point numbers can be ceiled
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cThe precision needs to be a whole number
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Floors the second number and writes it in the first or floors the second number with the precision from the third number and writes it in the first
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cOnly floating point numbers can be floored
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cThe precision needs to be a whole number
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Round the second number and writes it in the first or rounds the second number with the precision from the third number and writes it in the first
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cOnly floating point numbers can be rounded
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cThe precision needs to be a whole number
SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7value§8>
SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Send a message to the player. If the value is empty, the message will be empty as well
SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0}
SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7value§8>
SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Send a message to the player to the action bar. If the value is empty, the message will be empty as well
SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7variable§8> §8<§7text§8>
SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Request an input from the player, which will be written in the variable. The text is optional
SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7number§8>
SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7variable§8> §8<§7number§8>
SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Insert something into a String at a given index. The number is the index and the variable is the string. Optionally the result can be written in another or a new variable
SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7variable§8> §8<§7from variable§8>
SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8>
SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Removes all occurrences of a string from another string.
SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8>
SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8>
SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Replaces all occurrences of a string from another string with a given string
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7variable§8> §8<§7number§8>
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7variable§8> §8<§7variable§8> §8<§7number§8>
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Shortens a string either from the start or the end, depending on whether the given index is positive (start) or negative (end)
SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7variable§8> §8[§7value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Writes a value in a constant, which can be a number, a boolean or a string
SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7variable§8> §8<§7value§8>
SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Converts a value to 'number' if it's a number, or to 'boolean' if it's either 'true' or 'false'. Otherwise it remains of type 'text'.
SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7variable§8> §8[§7value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string
SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7variable§8>
SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Deletes a global variable.
SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7variable§8>
SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Deletes a local variable.
SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7variable§8> §8[§7value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string
SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8>
SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Writes the material of a block in the world in the variable
SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8>
SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Sets a block in the world with the given material, given in the variable
SCRIPT_COMMAND_EXIT_HELP_1 = §eexit
SCRIPT_COMMAND_EXIT_HELP_2 = Exits the script
SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8>
SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8>
SCRIPT_COMMAND_IF_HELP_3 = §7Jump to the first jump-point if the given value is true or the second jump-point otherwise.
SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7jump-point§8>
SCRIPT_COMMAND_JUMP_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before.
SCRIPT_COMMAND_JUMP_ERROR = §cUnknown jump-point: {0}
SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7jump-point§8>
SCRIPT_COMMAND_CALL_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before. Building a return stack alongside. Use 'return' to jump back.
SCRIPT_COMMAND_CALL_ERROR = §cUnknown jump-point: {0}
SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn
SCRIPT_COMMAND_RETURN_HELP_2 = §7Jump back to the last 'call' command
SCRIPT_COMMAND_RETURN_ERROR = §cNo 'call' command executed before
SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7time§8>
SCRIPT_COMMAND_SLEEP_HELP_2 = Pauses the execution by the given number of game ticks.
SCRIPT_COMMAND_SLEEP_ERROR = §cThe given number needs to be greater than zero.
## GUI
SCRIPT_GUI_ITEM_NAME = §eScript Help
SCRIPT_ERROR_GUI=§cError in parsing script: Line {0}
SCRIPT_ERROR_GLOBAL=§cError in global script: Line {0}
SCRIPT_ERROR_CLICK=§cError in script: Line {0}
## CustomScript
SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1}
SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1}
SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0}
SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0}
SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0}
SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0}
## Script Menu GUI
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Click to retrieve
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift-Click to copy
SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7%
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Right-Click to edit
SCRIPT_MENU_GUI_ITEM_LORE_4 = §7Middle-Click to preview
SCRIPT_MENU_GUI_NAME = §eScript-Menu
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert
SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' already defined
SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' cannot be defined
SCRIPT_MENU_GUI_LIMIT = §cScript-Book limit reached
## ScriptCommand
SCRIPT_COMMAND_HELP = §8/§escript §8- §7Opens the ScriptGUI
SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Opens the ScriptGUI for custom commands shares across baus
## Script GUI
SCRIPT_GUI_NAME = Script Elements
SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0}
SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Write§8: §e#!HOTKEY 'Char'
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom hotkey. The 'Char' can be any char between '§eA§7' and '§eZ§7' as well as '§e0§7' and '§e9§7'. While executing two variables are available: §epressed§7, §ereleased§7.
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7You can add modifiers like "SHIFT", "CTRL", "ALT" or "META" to the hotkey. §7Example: §e#!HOTKEY SHIFT+A
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cThis can only be used in conjunction with the Fabric-Mod: §eAdvancedScripts §7found on §ehttps://steamwar.de/downloads
SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands
SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Write§8: §e#!CMD 'COMMAND'
SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom command. The command always starts with §e/§7 and can be structured as you wish. Everything in pointy Brackets '§e<>§7' will be counted as a Parameter and therefore as a variable. Parameters in round brackets '§e()§7' are optional. Simple texts as parameters get a variable with the same name with the values true/false, depending on whether the value was given or not
SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events
SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Write§8: §e#!EVENT 'EventName'
SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7at the beginning of a Script Book to use a custom event. Every event can ve canceled by using 'var cancel true'. After the event name are the variables which are usable in a Script Book.
SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Usable Events are:
SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF
SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType
SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType
SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType,
SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e*
SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType,
SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e*
SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn
SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_18 = §eScoreboard
SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Everything in brackets is only set if the variable before is set on §etrue§7.
SCRIPT_GUI_OTHER = §eOther
SCRIPT_GUI_OTHER_LORE_1 = §7Comments start with §e#§7.
SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points start with §e.§7.
SCRIPT_GUI_OTHER_LORE_3 = §7A variable name enclosed in '§e{}§7' is replaced by its value. A variable can be prefixed with '§econst.§7' or '§elocal.§7' or '§eglobal.§7'.
SCRIPT_GUI_OTHER_LORE_4 = §7The following applies:
SCRIPT_GUI_OTHER_LORE_5 = §7- Local variables are only available in the script book.
SCRIPT_GUI_OTHER_LORE_6 = §7- Global variables are available in every script book.
SCRIPT_GUI_OTHER_LORE_7 = §7- Constant variables are variables from the server (e.g. player name, TPS, etc.)
SCRIPT_GUI_OTHER_LORE_8 = §7A variable can be appended with '§e.length§7' or '§e.type§7' or '§e.isset§7'.
SCRIPT_GUI_OTHER_LORE_9 = §7The following applies:
SCRIPT_GUI_OTHER_LORE_10 = §7- Length returns the length of the variable as a number.
SCRIPT_GUI_OTHER_LORE_11 = §7- Type returns the type (number, floating_number, text or boolean) as text.
SCRIPT_GUI_OTHER_LORE_12 = §7- Isset returns as a boolean whether the variable exists.
SCRIPT_GUI_OTHER_LORE_13 = §7Mathematical as well as logical operations can be specified in '§e{}§7'.
SCRIPT_GUI_OTHER_LORE_14 = §7The following applies:
SCRIPT_GUI_OTHER_LORE_15 = §7- arithmetic operators: §e+ * - /§7 as well as §e%§7 for modulo
SCRIPT_GUI_OTHER_LORE_16 = §7- Logical operators: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (this is the character for or)
SCRIPT_GUI_OTHER_LORE_17 = §7- Bitwise operators: §e&§7; §e|§7; §e^
SCRIPT_GUI_OTHER_LORE_18 = §7- Shift operators: §e<<§7; §e>>§7; §e>>>§7
SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0}
SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables
SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime
SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formatted time variable.
SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks
SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks since server start.
SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace
SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 if the trace is activated.
SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace
SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 if the auto trace is activated.
SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status
SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7One of: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE
SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time
SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 if the trace is not active, otherwise the time in ticks since the trace was started.
SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status
SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7One of: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND
SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt
SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 if tnt is not deactivated.
SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb
SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 if tnt no build is activated.
SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze
SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 if freeze is not deactivated.
SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire
SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 if fire is not deactivated.
SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect
SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 if protect is activated.
SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex
SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 position of the player.
SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey
SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 position of the player.
SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez
SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 position of the player.
SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename
SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 name of the player.
SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking
SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 if the player is sneaking.
SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting
SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 is the player is sprinting.
SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot
SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 for the selected slot.
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 of the item in the current slot
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 of the item in the off hand
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the current slot
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the off hand
SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type
SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region
SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name
SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eregion name§7 of the current region
SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps
SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server
SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit
SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server
SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name
# Shield Printing
SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starts the shield printing

Datei anzeigen

@ -226,295 +226,20 @@ GUI_EDITOR_ITEM_CLOSE=§eSchließen
GUI_EDITOR_TITLE_MORE=Item auswählen
# Script
## Errors
SCRIPT_SLEEP_ERROR = §cFüge ein sleep in dein Script ein
SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnbekannte Variable {0}
SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression fehler in: {0}
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cDas erste Argument fehlt und sollte eine Variable sein
SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cDas erste Argument fehlt und sollte eine Zahl sein
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cDas erste Argument fehlt und sollte eine Variable oder ein Wert sein
SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cDas erste Argument fehlt und sollte ein Jump-Point sein
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cDas zweite Argument fehlt und sollte eine Variable sein
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cDas zweite Argument fehlt und sollte ein Wert sein
SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cDas dritte Argument fehlt und sollte ein Jump-Point sein
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cDas dritte Argument fehlt und sollte eine Variable sein
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cDas dritte Argument fehlt und sollte ein Wert sein
SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cDas dritte Argument fehlt und sollte eine Variable/Zahl sein
SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cDas vierte Argument fehlt und sollte ein Wert sein
SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cNur Booleans können verglichen werden
SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cNur Zahlen können verglichen werden
SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cNur Strings können verwendet werden
SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cNur Zahlen können verwendet werden
SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnbekannte Operation: {0}
## Commands
SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cNur Zahlen können addiert werden
SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cNur Zahlen können dividiert werden
SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cNur Zahlen können multipliziert werden
SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cNur Zahlen können subtrahiert werden
SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cNur Zahlen können potenziert werden
SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cNur ganze Zahlen können für modulo verwendet werden
SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cNur ganze Zahlen und booleans können für und verwendet werden
SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cNur ganze Zahlen und booleans können für oder verwendet werden
SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cNur ganze Zahlen und booleans können für xor verwendet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Aufrunden der zweiten Zahl und schreibt es in die erste oder aufrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste.
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cNur Fließ-Komma-Zahlen können aufgerundet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Abrunden der zweiten Zahl und schreibt es in die erste oder abrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste.
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cNur Fließ-Komma-Zahlen können abgerundet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8>
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Runden der zweiten Zahl und schreibt es in die erste oder runden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste.
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cNur Fließ-Komma-Zahlen können gerundet werden
SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden
SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7Wert§8>
SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Schreibe etwas dem Spieler. Wenn kein Wert angegeben wurde ist die Nachricht leer.
SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0}
SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7Wert§8>
SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Schreibe etwas dem Spieler in der ActionBar. Wenn kein Wert angegeben wurde ist die Nachricht leer.
SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7Variable§8> §8<§7Text§8>
SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Fordere eine Eingabe von dem Spieler, welche in die Variable geschrieben wird. Der Text ist optional.
SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8>
SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8>
SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Füge etwas in einen String an einer Stelle ein. Die Zahl ist für die Position und die Variable davor für was. Schreibe optional dies in eine neue oder andere Variable.
SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7Variable§8> §8<§7Von Variable§8>
SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8>
SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Lösche eine Zeichenkette aus dem Ursprung. Dies ersetzt nicht nur die erste Stelle sondern alle.
SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8>
SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8>
SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Ersetzte eine Zeichenkette aus dem Ursprung mit einer neuen Zeichenkette. Dies ersetzt nicht nur die erste Stelle sondern alle.
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7Variable§8> §8<§7Zahl§8>
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8>
SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Kürze einen String entweder vorne oder hinter, je nachdem ob die Zahl positiv (vorne) oder negativ (hinten) ist.
SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7Variable§8> §8[§7Value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Schreibt in eine Konstante einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text.
SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7Variable§8> §8<§7Value§8>
SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Konvertiere den Value zu 'number' wenn es eine Zahl ist, oder zu 'boolean' bei 'true' oder 'false' und behalte 'text' bei wenn nichts zutrifft.
SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7Variable§8> §8[§7Value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text.
SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7Variable§8>
SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Lösche eine Globale variable.
SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7Variable§8>
SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Lösche eine Locale variable.
SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7Variable§8> §8[§7Value§8(§7s§8)§8]
SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text.
SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8>
SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Schreibt das material von einem Block in der Welt in die Variable.
SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8>
SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Setzt an einem Block in der Welt das Material der ersten Variable.
SCRIPT_COMMAND_EXIT_HELP_1 = §eexit
SCRIPT_COMMAND_EXIT_HELP_2 = Beendet das ausführen des Scripts.
SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8>
SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8>
SCRIPT_COMMAND_IF_HELP_3 = §7Springe zu ersten Stelle, wenn der Wert true ist. Oder zu dem zweiten, wenn dies nicht der fall ist.
SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7Jump-Point§8>
SCRIPT_COMMAND_JUMP_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor.
SCRIPT_COMMAND_JUMP_ERROR = §cDer Jump-Point ({0}) ist nicht definiert.
SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7Jump-Point§8>
SCRIPT_COMMAND_CALL_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor. Hierbei wird auf den ReturnStack die jetzige Zeile geschrieben, dahin kann man wieder mit 'return' zurück springen.
SCRIPT_COMMAND_CALL_ERROR = §cDer Jump-Point ({0}) ist nicht definiert.
SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn
SCRIPT_COMMAND_RETURN_HELP_2 = §7Springe zum letzten 'call' Befehl.
SCRIPT_COMMAND_RETURN_ERROR = §cEs wurde kein 'call' Befehl ausgeführt
SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7Time§8>
SCRIPT_COMMAND_SLEEP_HELP_2 = Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks.
SCRIPT_COMMAND_SLEEP_ERROR = §cDie Zeit muss eine Zahl großer 0 sein.
## GUI
SCRIPT_GUI_ITEM_NAME = §eScript Hilfe
## CustomScript
SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1}
SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1}
SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0}
SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0}
SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0}
SCRIPT_COMMAND_ITEM_NAME = §7Befehl§8: §e/{0}
## Script Menu GUI
SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift Klicke zum kopieren
SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7%
SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shiftklick zum kopieren
SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Rechtsklick zum editieren
SCRIPT_MENU_GUI_ITEM_LORE_4 = §7Mittelklick zum anschauen
SCRIPT_MENU_GUI_NAME = §eSkript-Menü
SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen
SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' bereits definiert
SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' ist nicht definierbar
SCRIPT_MENU_GUI_LIMIT = §cScript-Buch Limit erreicht
## ScriptCommand
SCRIPT_COMMAND_HELP = §8/§escript §8- §7Öffnet die ScriptGUI
SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Öffnet die ScriptMenuGUI für Custom Command bauübergreifend
## Script GUI
SCRIPT_GUI_NAME = Script Elements
SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0}
SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Schreibe§8: §e#!HOTKEY 'Char'
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7am Anfang eines Skript Buches, um einen benutzerdefinierten Hotkey zu verwenden. Das 'Char' kann ein beliebiges Zeichen zwischen '§eA§7' und '§eZ§7' sowie '§e0§7' und '§e9§7' sein. Während der Ausführung sind zwei Variablen verfügbar: §epressed§7, §ereleased§7
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7Sie können dem Hotkey Modifikatoren wie "SHIFT", "CTRL", "ALT" oder "META" hinzufügen. §7Beispiel: §e#!HOTKEY SHIFT+A
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7
SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cDies kann nur in Verbindung mit den Fabric-Mod: §eAdvancedScripts §7runterladbar unter §ehttps://steamwar.de/downloads §cverwendet werden.
SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands
SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Schreibe§8: §e#!CMD 'COMMAND'
SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Command zu nutzen. Der Befehl startet immer mit §e/§7 und kann dann so aufgebaut sein wie du willst. Alles was in Spitzen Klammern steht '§e<>§7' wird als Parameter und somit als Variable gewertet. Parameter, welche in runden Klammern stehen sind Optional. Einfache Texte als Parameter bekommen eine gleichnamige Variable mit true/false als Wert je nachdem ob dieser angegeben wurde oder nicht
SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events
SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Schreibe§8: §e#!EVENT 'EventName'
SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Event zu nutzen. Jedes Event kann durch 'var cancel true' gecancelt werden. Hinter dem Event Namen stehen die Variablen, welche im Script durch das Event nutztbar sind.
SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Nutzbare Events sind:
SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF
SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType
SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType
SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType,
SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e*
SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType,
SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e*
SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn
SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Alles in den Klammern ist nur gesetzt, wenn die Variable davor auf §etrue§7 gesetzt ist.
SCRIPT_GUI_OTHER = §eOther
SCRIPT_GUI_OTHER_LORE_1 = §7Kommentare fangen mit §e#§7 an.
SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points fangen mit §e.§7 an.
SCRIPT_GUI_OTHER_LORE_3 = §7Einen Variablennamen, der in '§e{}§7' eingeschlossen ist wird durch seinen Wert ersetzt. Eine Variable kann mit den Präfixen '§econst.§7' oder '§elocal.§7' oder '§eglobal.§7' versehen werden.
SCRIPT_GUI_OTHER_LORE_4 = §7Dabei gilt:
SCRIPT_GUI_OTHER_LORE_5 = §7- Lokalevariablen sind nur in dem Script-Buch verfügbar.
SCRIPT_GUI_OTHER_LORE_6 = §7- Gloablevariablen sind in jedem Script-Buch verfügbar.
SCRIPT_GUI_OTHER_LORE_7 = §7- Konstantevariablen sind Variablen vom Server (z.B. Spielername, TPS usw.)
SCRIPT_GUI_OTHER_LORE_8 = §7Eine Variable kann mit den Appendixen '§e.length§7' oder '§e.type§7' oder '§e.isset§7' versehen werden.
SCRIPT_GUI_OTHER_LORE_9 = §7Dabei gilt:
SCRIPT_GUI_OTHER_LORE_10 = §7- Length gibt die Länge der variable als Zahl zurück.
SCRIPT_GUI_OTHER_LORE_11 = §7- Type gibt den typen (number, floating number, text oder boolean) als Text zurück.
SCRIPT_GUI_OTHER_LORE_12 = §7- Isset gibt als boolean zurück, ob die Variable existiert.
SCRIPT_GUI_OTHER_LORE_13 = §7Mathematische sowie logische Operationsvorgänge können in '§e{}§7' angegeben werden.
SCRIPT_GUI_OTHER_LORE_14 = §7Dabei gilt:
SCRIPT_GUI_OTHER_LORE_15 = §7- Rechenoperatoren: §e+ * - /§7 sowie §e%§7 für Modulo
SCRIPT_GUI_OTHER_LORE_16 = §7- Logische Operatoren: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (Dies ist das Zeichen für oder)
SCRIPT_GUI_OTHER_LORE_17 = §7- Bitweise Operatoren: §e&§7; §e|§7; §e^
SCRIPT_GUI_OTHER_LORE_18 = §7- Shift Operatoren: §e<<§7; §e>>§7; §e>>>§7
SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0}
SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables
SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime
SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formattierte Uhrzeit
SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks
SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks seit dem Serverstart
SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace
SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 wenn gerade der Tracer an ist.
SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace
SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 wenn gerade der AutoTracer an ist.
SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status
SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE
SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time
SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 wenn gerade kein TNT getraced wird, ansonsten die Zeit in Ticks seit dem Start des Tracers.
SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status
SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND
SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt
SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 wenn TNT nicht ausgeschaltet ist.
SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb
SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 wenn TNT Nur Testblock an ist.
SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze
SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 wenn Freeze nicht ausgeschaltet ist.
SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire
SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 wenn Fire nicht ausgeschaltet ist.
SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect
SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 wenn Protect angeschaltet ist.
SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex
SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 Position des Spielers.
SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey
SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 Position des Spielers.
SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez
SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 Position des Spielers.
SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename
SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 Name des Spielers.
SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking
SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 wenn der Spieler gerade sneakt.
SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting
SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 wenn der Spieler gerade rennt.
SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot
SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 für den ausgewählten slot.
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 des Items im Slot
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 des Items in der Off Hand
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname
SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 des Items im Slot
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname
SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 des Items in der Off Hand
SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type
SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eRegionstype§7 der jetztigen Region
SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name
SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eRegionsname§7 der jetztigen Region
SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps
SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server
SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit
SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server
# Shield Printing
SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starte das Schild drucken
SHIELD_PRINTING_HELP_COPY = §8/§eshieldprinting copy §8- §7Kopiert die Schilder
@ -535,7 +260,7 @@ SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0}
SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1}
SHIELD_PRINTING_START = §aShield printing wurde gestartet.
SHIELD_PRINTING_COPY = §aSchilde wurden kopiert.
SHIELD_PRINTING_COPY = §aSchilde wurden kopiert.
SHIELD_PRINTING_APPLY = §aSchilde wurden angewendet.
SHIELD_PRINTING_STOP = §aShield printing wurde gestoppt.

Datei anzeigen

@ -20,8 +20,6 @@
package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.CustomScriptManager;
import de.steamwar.bausystem.features.script.custom.event.EventType;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
@ -48,10 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
@Linked
public class TNTListener implements Listener, ScoreboardElement {
@LinkedInstance
public CustomScriptManager customScriptManager;
private void explode(List<Block> blockList, Location location, EventType eventType, Event event) {
private void explode(List<Block> blockList) {
AtomicBoolean inBuild = new AtomicBoolean();
blockList.removeIf(block -> {
Region region = Region.getRegion(block.getLocation());
@ -71,24 +66,16 @@ public class TNTListener implements Listener, ScoreboardElement {
}
return value == TNTMode.DENY;
});
if (inBuild.get()) {
Region region = Region.getRegion(location);
for (Player player : Bukkit.getOnlinePlayers()) {
if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
customScriptManager.callEvent(eventType, player, event);
}
}
}
}
@EventHandler
public void onBlockExplode(BlockExplodeEvent event) {
explode(event.blockList(), event.getBlock().getLocation(), null, null);
explode(event.blockList());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplode(EntityExplodeEvent event) {
explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event);
explode(event.blockList());
}
@Override

Datei anzeigen

@ -1,342 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.script.custom.MenuScript;
import de.steamwar.bausystem.features.script.custom.Script;
import de.steamwar.bausystem.features.script.custom.command.CustomCommand;
import de.steamwar.bausystem.features.script.custom.command.InventoryCommand;
import de.steamwar.bausystem.features.script.custom.command.MenuCommand;
import de.steamwar.bausystem.features.script.custom.event.CustomEvent;
import de.steamwar.bausystem.features.script.custom.event.EventType;
import de.steamwar.bausystem.features.script.custom.event.InventoryEvent;
import de.steamwar.bausystem.features.script.custom.event.MenuEvent;
import de.steamwar.bausystem.features.script.custom.hotkey.Hotkey;
import de.steamwar.bausystem.features.script.custom.hotkey.Hotkeys;
import de.steamwar.bausystem.features.script.custom.hotkey.InventoryHotkey;
import de.steamwar.bausystem.features.script.custom.hotkey.MenuHotkey;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.UserConfig;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import yapion.hierarchy.output.LengthOutput;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONMap;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONValue;
import yapion.parser.YAPIONParser;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@Linked
public class CustomScriptManager implements Listener {
public final Map<Player, List<Script>> playerMap = Collections.synchronizedMap(new HashMap<>()); // new ConcurrentHashMap<>();
private void updateInventory(Player p) {
playerMap.computeIfPresent(p, (player, customCommands) -> {
customCommands.removeIf(script -> !(script instanceof MenuScript));
return customCommands;
});
for (ItemStack item : p.getInventory().getContents()) {
if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) {
continue;
}
BookMeta bookMeta = ((BookMeta) item.getItemMeta());
if (bookMeta.getPageCount() == 0) {
continue;
}
if (bookMeta.getPage(1).isEmpty()) {
continue;
}
String s = bookMeta.getPage(1).split("\n")[0];
if (s.startsWith("#!CMD /")) {
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryCommand(bookMeta, s.substring(6).split(" ")));
} else if (s.startsWith("#!EVENT ")) {
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryEvent(bookMeta, s.substring(8).split(" ")));
} else if (s.startsWith("#!HOTKEY ")) {
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryHotkey(bookMeta, s.substring(9).split(" ")));
}
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
load(e.getPlayer());
}
private synchronized void load(Player p) {
updateInventory(p);
String s = UserConfig.getConfig(p.getUniqueId(), "bausystem-scripts");
if (s == null) {
s = UserConfig.getConfig(p.getUniqueId(), "bausystem-commands");
UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-commands");
}
YAPIONObject yapionObject;
if (s == null) {
yapionObject = new YAPIONObject();
yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui"));
} else {
yapionObject = YAPIONParser.parse(s);
if (yapionObject.containsKey("")) {
yapionObject.add("commands", yapionObject.getMap(""));
yapionObject.remove("");
yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui"));
}
}
yapionObject.getYAPIONMapOrSetDefault("commands", new YAPIONMap()).forEach((key, value) -> {
String[] command = ((YAPIONValue<String>) key).get().split(" ");
List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList());
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuCommand(pages, command));
});
yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).forEach((key, value) -> {
String[] event = ((YAPIONValue<String>) key).get().split(" ");
List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList());
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuEvent(pages, event));
});
yapionObject.getYAPIONMapOrSetDefault("hotkeys", new YAPIONMap()).forEach((key, value) -> {
String[] hotkey = ((YAPIONValue<String>) key).get().split(" ");
List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList());
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuHotkey(pages, hotkey));
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
save(e.getPlayer());
playerMap.remove(e.getPlayer());
}
private YAPIONObject output(Player p) {
if (!playerMap.containsKey(p)) return new YAPIONObject();
YAPIONObject yapionObject = new YAPIONObject();
YAPIONMap commandsMap = new YAPIONMap();
yapionObject.add("commands", commandsMap);
playerMap.get(p).stream().filter(MenuCommand.class::isInstance).map(MenuCommand.class::cast).forEach(menuCommand -> {
menuCommand.save(commandsMap);
});
YAPIONMap eventsMap = new YAPIONMap();
yapionObject.add("events", eventsMap);
playerMap.get(p).stream().filter(MenuEvent.class::isInstance).map(MenuEvent.class::cast).forEach(menuCommand -> {
menuCommand.save(eventsMap);
});
YAPIONMap hotkeysMap = new YAPIONMap();
yapionObject.add("hotkeys", hotkeysMap);
playerMap.get(p).stream().filter(MenuHotkey.class::isInstance).map(MenuHotkey.class::cast).forEach(menuCommand -> {
menuCommand.save(hotkeysMap);
});
return yapionObject;
}
private boolean save(Player p) {
if (!playerMap.containsKey(p)) {
UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-scripts");
return true;
}
YAPIONObject yapionObject = output(p);
if (yapionObject.toYAPION(new LengthOutput()).getLength() > 64 * 1024) {
return false;
}
UserConfig.updatePlayerConfig(p.getUniqueId(), "bausystem-scripts", yapionObject.toYAPION(new StringOutput()).getResult());
return true;
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
if (e.getPlayer() instanceof Player) {
updateInventory((Player) e.getPlayer());
}
}
public void openCommandsMenu(Player p) {
List<SWListInv.SWListEntry<MenuScript>> menuCommands = new ArrayList<>();
playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(MenuScript.class::isInstance).map(MenuScript.class::cast).forEach(menuItem -> {
SWItem swItem = menuItem.toItem(p);
ItemStack itemStack = swItem.getItemStack();
if (menuItem instanceof MenuHotkey) {
itemStack.setType(Material.CHAIN_COMMAND_BLOCK);
} else if (menuItem instanceof MenuEvent) {
itemStack.setType(Material.REPEATING_COMMAND_BLOCK);
} else {
itemStack.setType(Material.COMMAND_BLOCK);
}
swItem.setItemStack(itemStack);
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", p), BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", p)));
menuCommands.add(new SWListInv.SWListEntry<>(swItem, menuItem));
});
int length = (int) output(p).toYAPION(new LengthOutput()).getLength();
double percentage = ((int) ((length / 655336.0) * 1000)) / 10.0;
String menuName = BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", p, percentage > 99 ? "§c" : (percentage >= 75 ? "§6" : "§a"), percentage);
SWListInv<MenuScript> menuCommandSWListInv = new SWListInv<>(p, menuName, false, menuCommands, (clickType, menuCommand) -> {
if (!clickType.isShiftClick()) {
playerMap.get(p).removeIf(customCommand -> customCommand == menuCommand);
}
SWUtils.giveItemToPlayer(p, menuCommand.toItem(p).getItemStack());
p.closeInventory();
save(p);
});
menuCommandSWListInv.setItem(49, new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_LORE", p)), false, clickType -> {
ItemStack item = p.getItemOnCursor();
if (item.getType().isAir()) {
return;
}
if (FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) {
return;
}
BookMeta bookMeta = ((BookMeta) item.getItemMeta());
if (bookMeta.getPageCount() == 0) {
return;
}
if (bookMeta.getPage(1).isEmpty()) {
return;
}
String s = bookMeta.getPage(1).split("\n")[0];
if (s.startsWith("#!CMD /")) {
MenuCommand menuCommand = new MenuCommand(bookMeta.getPages(), s.substring(6).split(" "));
for (Script script : playerMap.computeIfAbsent(p, player -> new ArrayList<>())) {
if (!(script instanceof MenuCommand)) {
continue;
}
if (((MenuCommand) script).equals(menuCommand)) {
BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_DUPLICATE_COMMAND", p, String.join(" ", menuCommand.command()));
return;
}
}
scriptBookLimit(p, menuCommand);
} else if (s.startsWith("#!EVENT ")) {
MenuEvent menuEvent = new MenuEvent(bookMeta.getPages(), s.substring(8).split(" "));
try {
EventType.valueOf(menuEvent.eventName());
} catch (Exception e) {
BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_UNKNOWN_EVENT", p, menuEvent.eventName());
return;
}
scriptBookLimit(p, menuEvent);
} else if (s.startsWith("#!HOTKEY ")) {
scriptBookLimit(p, new MenuHotkey(bookMeta.getPages(), s.substring(9).split(" ")));
}
}));
menuCommandSWListInv.open();
}
private void scriptBookLimit(Player p, Script menuScript) {
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(menuScript);
if (!save(p)) {
playerMap.get(p).removeIf(script -> script == menuScript);
p.closeInventory();
SWUtils.giveItemToPlayer(p, p.getItemOnCursor());
save(p);
BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_LIMIT", p);
return;
}
p.setItemOnCursor(null);
openCommandsMenu(p);
}
public boolean callCommand(Player p, PlayerCommandPreprocessEvent e, String message) {
List<CustomCommand> customCommands = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomCommand.class::isInstance).map(CustomCommand.class::cast).collect(Collectors.toList());
String[] command = message.split(" ");
for (CustomCommand customCommand : customCommands) {
if (customCommand.execute(command, e)) {
return true;
}
}
return false;
}
public boolean callScoreboard(Player p, Map<String, String> variables, Consumer<String> echoConsumer) {
Map<String, Value> valueMap = new HashMap<>();
for (Map.Entry<String, String> entry : variables.entrySet()) {
valueMap.put(entry.getKey(), new Value.StringValue(entry.getValue()));
}
List<CustomEvent> customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList());
boolean hasScript = false;
for (CustomEvent customEvent : customEvents) {
if (customEvent.eventName().equals(EventType.Scoreboard.name())) {
customEvent.execute(p, valueMap, echoConsumer);
hasScript = true;
}
}
return hasScript;
}
public void callEvent(EventType eventType, Player p, Event e) {
if (eventType == null) return;
if (!eventType.getEventType().equals(e.getClass())) return;
List<CustomEvent> customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList());
for (CustomEvent customEvent : customEvents) {
if (customEvent.eventName().equals(eventType.name())) {
Map<String, Value> variables = eventType.getEventValues().apply(e);
if (variables == null) {
variables = new HashMap<>();
}
if (e instanceof Cancellable) {
variables.put("cancel", new Value.BooleanValue(((Cancellable) e).isCancelled()));
}
customEvent.execute(p, variables, null);
if (variables.containsKey("cancel")) {
Value value = variables.get("cancel");
((Cancellable) e).setCancelled(value.asBoolean());
}
}
}
}
public void callHotkey(int modifiers, char pressedHotkey, Player p, boolean pressed) {
List<Hotkey> hotkeys = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(Hotkey.class::isInstance).map(Hotkey.class::cast).collect(Collectors.toList());
for (Hotkey hotkey : hotkeys) {
if (Hotkeys.isSame(modifiers, pressedHotkey, hotkey.hotkey())) {
hotkey.execute(p, pressed);
}
}
}
}

Datei anzeigen

@ -0,0 +1,77 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@AllArgsConstructor
@Builder
@EqualsAndHashCode
public class Hotkey {
private final int charcode;
private final boolean ctrl;
private final boolean shift;
private final boolean alt;
private final boolean meta;
public static Hotkey fromString(String string) {
String[] parts = string.split("\\+");
HotkeyBuilder builder = Hotkey.builder();
for (String part : parts) {
switch (part.toLowerCase()) {
case "ctrl":
builder.ctrl(true);
break;
case "shift":
builder.shift(true);
break;
case "alt":
builder.alt(true);
break;
case "meta":
builder.meta(true);
break;
default:
if (part.length() == 1) {
builder.charcode(Character.toLowerCase(part.charAt(0)));
} else {
throw new IllegalArgumentException("Invalid hotkey: " + string);
}
}
}
return builder.build();
}
public static Hotkey fromChar(int c, int mods) {
return Hotkey.builder()
.charcode(Character.toLowerCase(c))
.shift((mods & 1) != 0)
.ctrl((mods & 2) != 0)
.alt((mods & 4) != 0)
.meta((mods & 8) != 0)
.build();
}
}

Datei anzeigen

@ -1,20 +1,28 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import static de.steamwar.bausystem.features.script.ScriptExecutor.SPECIAL_COMMANDS;
@Linked
public class ScriptCommand extends SWCommand {
@ -22,142 +30,8 @@ public class ScriptCommand extends SWCommand {
super("script");
}
@LinkedInstance
public CustomScriptManager customScriptManager = null;
private List<String> loreBuilder(Player p, String... strings) {
List<String> result = new ArrayList<>();
for (String s : strings) {
result.addAll(split(BauSystem.MESSAGE.parse(s, p)));
}
return result;
}
@Register(description = "SCRIPT_COMMAND_HELP")
public void menuCommand(Player p) {
List<SWListInv.SWListEntry<SpecialCommand>> swItems = new ArrayList<>();
addEmptyItems(swItems, 2);
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_HOTKEYS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5")), null));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_COMMANDS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2")), null));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_1", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_2", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_3", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_4", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_5", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_6", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_7", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_8", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_9", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_10", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_11", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_12", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_13", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_14", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_15", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_16", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_17", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_18", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1")), null));
addEmptyItems(swItems, 1);
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_OTHER", loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_1", "SCRIPT_GUI_OTHER_LORE_2", "SCRIPT_GUI_OTHER_LORE_3", "SCRIPT_GUI_OTHER_LORE_4", "SCRIPT_GUI_OTHER_LORE_5", "SCRIPT_GUI_OTHER_LORE_6", "SCRIPT_GUI_OTHER_LORE_7", "SCRIPT_GUI_OTHER_LORE_8", "SCRIPT_GUI_OTHER_LORE_9", "SCRIPT_GUI_OTHER_LORE_10", "SCRIPT_GUI_OTHER_LORE_11", "SCRIPT_GUI_OTHER_LORE_12", "SCRIPT_GUI_OTHER_LORE_13", "SCRIPT_GUI_OTHER_LORE_14", "SCRIPT_GUI_OTHER_LORE_15", "SCRIPT_GUI_OTHER_LORE_16", "SCRIPT_GUI_OTHER_LORE_17", "SCRIPT_GUI_OTHER_LORE_18")), null));
addEmptyItems(swItems, 2);
addCustomScriptsItems(swItems, p);
addEmptyItems(swItems, 45 - swItems.size() % 45);
addEmptyItems(swItems, 4);
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_VARIABLES", new ArrayList<>()), null));
addEmptyItems(swItems, 4);
addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TIME_NAME", "SCRIPT_GUI_CONSTANT_TIME_LORE");
addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TICKS_NAME", "SCRIPT_GUI_CONSTANT_TICKS_LORE");
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE");
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE");
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME", "SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE");
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME", "SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE");
addConstantItem(swItems, p, Material.HOPPER, "SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME", "SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE");
addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE");
addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE");
addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE");
addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE");
addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE");
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE");
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE");
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE");
addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE");
addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE");
addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE");
addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE");
addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE");
addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE");
addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE");
addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE");
addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE");
addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_NAME_NAME", "SCRIPT_GUI_CONSTANT_REGION_NAME_LORE");
addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_NAME", "SCRIPT_GUI_CONSTANT_TPS_LORE");
addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME", "SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE");
addEmptyItems(swItems, 45 - swItems.size() % 45);
SWListInv<SpecialCommand> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> {
if (o != null) {
BauSystem.MESSAGE.send("SCRIPT_GUI_COMMAND_CHAT", p, o.command());
for (String s : o.description()) {
if (s.isEmpty()) {
BauSystem.MESSAGE.sendPrefixless("PREFIX", p);
} else {
BauSystem.MESSAGE.send(s, p);
}
}
p.closeInventory();
}
});
swListInv.open();
}
private void addEmptyItems(List<SWListInv.SWListEntry<SpecialCommand>> swItems, int count) {
for (int i = 0; i < count; i++) {
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> {
}), null));
}
}
private SWItem createItem(Player p, Material material, String name, List<String> lore) {
return new SWItem(material, BauSystem.MESSAGE.parse(name, p), lore, false, clickType -> {
});
}
private void addConstantItem(List<SWListInv.SWListEntry<SpecialCommand>> swItems, Player p, Material material, String name, String lore) {
List<String> itemLore = new ArrayList<>();
itemLore.add(BauSystem.MESSAGE.parse(lore, p));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, material, name, itemLore), null));
}
private void addCustomScriptsItems(List<SWListInv.SWListEntry<SpecialCommand>> swItems, Player p) {
List<SpecialCommand> specialCommands = new ArrayList<>(SPECIAL_COMMANDS);
specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName()));
specialCommands.forEach(specialCommand -> {
List<String> strings = new ArrayList<>();
boolean b = false;
for (String s : specialCommand.description()) {
if (s.isEmpty()) {
b = true;
strings.add("");
continue;
}
s = BauSystem.MESSAGE.parse(s, p);
if (b) {
strings.addAll(split(s));
} else {
strings.add(s);
}
}
SWItem swItem = new SWItem(specialCommand.material(), BauSystem.MESSAGE.parse("SCRIPT_GUI_COMMAND_NAME", p, specialCommand.command()), strings, false, clickType -> {
});
swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand));
});
}
private List<String> split(String s) {
List<String> strings = new ArrayList<>();
while (s.length() > 60) {
int index = s.indexOf(' ', 60);
if (index == -1) {
strings.add("§7" + s);
s = null;
break;
} else {
strings.add("§7" + s.substring(0, index));
s = s.substring(index + 1);
}
}
if (s != null) {
strings.add("§7" + s);
}
return strings;
}
@Register(value = "menu", description = "SCRIPT_COMMAND_HELP_MENU")
public void menuGUICommand(Player p) {
customScriptManager.openCommandsMenu(p);
@Register
public void genericCommand(Player player) {
ScriptGUI.open(player);
}
}

Datei anzeigen

@ -1,304 +0,0 @@
package de.steamwar.bausystem.features.script;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.expression.Expression;
import de.steamwar.bausystem.features.script.expression.UnknownOperatorException;
import de.steamwar.bausystem.features.script.expression.VarNotFoundException;
import de.steamwar.bausystem.features.script.variables.Constants;
import de.steamwar.bausystem.features.script.variables.Context;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.bausystem.features.world.WorldEditListener;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.bausystem.utils.WorldEditUtils;
import lombok.Getter;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.meta.BookMeta;
import java.util.*;
import java.util.function.Consumer;
import java.util.logging.Level;
public final class ScriptExecutor {
public static final Set<SpecialCommand> SPECIAL_COMMANDS = new HashSet<>();
static {
LinkageUtils.linkScriptCommands();
}
private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null;
private String specialCommand = null;
@Getter
private final Player player;
@Getter
private final Context localVariables = new Context();
@Getter
private final Context globalVariables;
private final List<String> commands = new ArrayList<>();
@Getter
public final Map<String, Integer> jumpPoints = new HashMap<>();
@Getter
private final LinkedList<Integer> returnStack = new LinkedList<>();
@Getter
@Setter
private int index = 0;
@Getter
private final Consumer<String> echoConsumer;
public ScriptExecutor(BookMeta bookMeta, Player player, Consumer<String> echoConsumer) {
this(bookMeta, player, new HashMap<>(), echoConsumer);
}
public ScriptExecutor(List<String> pages, Player player, Consumer<String> echoConsumer) {
this(pages, player, new HashMap<>(), echoConsumer);
}
public ScriptExecutor(BookMeta bookMeta, Player player, Map<String, Value> localVariables, Consumer<String> echoConsumer) {
this.player = player;
globalVariables = ScriptListener.getGlobalContext(player);
parseMeta(bookMeta);
this.echoConsumer = echoConsumer != null ? echoConsumer : s -> {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s);
};
if (commands.isEmpty()) return;
localVariables.forEach(this.localVariables::putValue);
resume();
}
public ScriptExecutor(List<String> pages, Player player, Map<String, Value> localVariables, Consumer<String> echoConsumer) {
this.player = player;
globalVariables = ScriptListener.getGlobalContext(player);
parseList(pages);
this.echoConsumer = echoConsumer != null ? echoConsumer : s -> {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s);
};
if (commands.isEmpty()) return;
localVariables.forEach(this.localVariables::putValue);
resume();
}
private void parseMeta(BookMeta bookMeta) {
boolean initial = true;
for (String page : bookMeta.getPages()) {
initial = parsePage(page, initial);
}
}
private void parseList(List<String> pages) {
boolean initial = true;
for (String page : pages) {
initial = parsePage(page, initial);
}
}
private boolean parsePage(String page, boolean initial) {
for (String command : page.split("\n")) {
command = command.replaceAll(" +", " ");
if (command.startsWith("#") || command.trim().isEmpty()) {
if (initial && command.startsWith("#!CMD /")) {
specialCommand = command.substring(7).split(" ")[0];
}
initial = false;
continue;
}
initial = false;
if (command.startsWith(".")) {
jumpPoints.put(command.substring(1), commands.size());
continue;
}
commands.add(command);
}
return initial;
}
public void resume() {
if (!player.isOnline()) {
return;
}
int executionPoints = 0;
while (index < commands.size()) {
String command = commands.get(index).trim();
index++;
if (executionPoints++ > 200) {
BauSystem.MESSAGE.send("SCRIPT_SLEEP_ERROR", player);
return;
}
String[] strings = replaceExpressions(command);
if (strings.length == 0) {
return;
}
boolean found = false;
for (SpecialCommand specialCommand : SPECIAL_COMMANDS) {
if (specialCommand.command().equalsIgnoreCase(strings[0])) {
found = true;
if (!specialCommand.execute(strings, this)) {
return;
}
}
}
if (found) {
continue;
}
if (strings[0].contains(":")) {
continue;
}
// Variable Replaces in commands.
command = String.join(" ", strings);
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (specialCommand != null && command.startsWith(specialCommand) ? "script:" : "") + command);
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
if (preprocessEvent.isCancelled()) {
continue;
}
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
if (!strings[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + strings[0])) {
EditSession editSession = WorldEditUtils.getEditSession(player);
Actor actor = BukkitAdapter.adapt(player);
WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession));
editSession.flushSession();
WorldEditUtils.addToPlayer(player, editSession);
} else {
Bukkit.getServer().dispatchCommand(player, command);
}
}
}
private String[] replaceExpressions(String s) {
s = s.replaceAll(" +", " ");
StringBuilder result = new StringBuilder();
int depth = 0;
StringBuilder st = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '{') {
st.append(c);
depth++;
} else if (c == '}') {
st.append(c);
depth--;
if (depth == 0) {
try {
Expression expression = new Expression(player, st.toString(), this);
result.append(expression.eval().asString());
st = new StringBuilder();
} catch (IllegalArgumentException e) {
BauSystem.MESSAGE.send(e.getMessage(), player);
return new String[0];
} catch (VarNotFoundException e) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_VAR", player, e.getMessage());
return new String[0];
} catch (IndexOutOfBoundsException e) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_EXPRESSION", player, st.toString());
return new String[0];
} catch (UnknownOperatorException e) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION", player, e.getMessage());
return new String[0];
}
}
} else if (st.length() > 0) {
st.append(c);
} else {
result.append(c);
}
}
return result.toString().split(" ");
}
public Value getOrItselfValue(String variable) {
if (!isVariable(variable)) {
return Value.parse(variable);
}
if (localVariables.hasValue(variable)) {
return localVariables.getValue(variable);
}
if (globalVariables.hasValue(variable)) {
return globalVariables.getValue(variable);
}
return Constants.getConstant(variable, player);
}
public Value getValueOrNull(String variable) {
if (localVariables.hasValue(variable)) {
return localVariables.getValue(variable);
}
if (globalVariables.hasValue(variable)) {
return globalVariables.getValue(variable);
}
if (Constants.isConstant(variable)) {
return Constants.getConstant(variable, player);
}
return null;
}
public String getOrItself(String variable) {
if (isVariable(variable)) {
return getValue(variable);
}
return variable;
}
public boolean isVariable(String variable) {
return Constants.isConstant(variable) || globalVariables.hasValue(variable) || localVariables.hasValue(variable);
}
public String getValue(String variable) {
if (localVariables.hasValue(variable)) {
return localVariables.getValue(variable).asString();
}
if (globalVariables.hasValue(variable)) {
return globalVariables.getValue(variable).asString();
}
if (Constants.isConstant(variable)) {
return Constants.getConstant(variable, player).asString();
}
return "";
}
public String getConstant(String variable) {
if (Constants.isConstant(variable)) {
return Constants.getConstant(variable, player).asString();
}
return "0";
}
public String getGlobal(String variable) {
if (globalVariables.hasValue(variable)) {
return globalVariables.getValue(variable).asString();
}
return "0";
}
public String getLocal(String variable) {
if (localVariables.hasValue(variable)) {
return localVariables.getValue(variable).asString();
}
return "0";
}
}

Datei anzeigen

@ -0,0 +1,126 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.lua.SteamWarPlatform;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.Script;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.luaj.vm2.Globals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Linked
public class ScriptGUI implements Listener {
public static void open(Player player) {
open(player, null);
}
private static void open(Player player, ItemStack setCursor) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
List<SWListInv.SWListEntry<Script>> entries = new ArrayList<>();
List<String> lore = new ArrayList<>();
Globals globals = SteamWarPlatform.createGlobalParser(
(eventType, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", player, eventType.name())),
(s, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", player, s)),
commandRegister -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", player, commandRegister.getName()))
);
Script.list(user).forEach(script -> {
try {
globals.load(script.getCode()).call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
lore.add(BauSystem.MESSAGE.parse("SCRIPT_ERROR_GUI", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length))));
}
if(!lore.isEmpty()) {
lore.add("");
}
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", player));
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", player));
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_3", player));
lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_4", player));
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.ENCHANTED_BOOK, script.getName(), new ArrayList<>(lore), false, clickType -> {}), script));
lore.clear();
});
SWListInv<Script> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", player), false, entries, (clickType, script) -> {
ItemStack itemStack = ScriptHelper.getScriptItem(script, clickType.isRightClick());
if(clickType == ClickType.MIDDLE) {
player.openBook(itemStack);
} else if(!clickType.isShiftClick()) {
script.delete();
ScriptRunner.updateGlobalScript(player);
open(player, itemStack);
} else {
player.getOpenInventory().setCursor(itemStack);
}
});
inv.setItem(49, Material.HOPPER, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_NAME", player), Collections.singletonList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_LORE", player)), false, click -> {
if(player.getOpenInventory().getCursor() != null) {
ItemStack cursor = player.getOpenInventory().getCursor();
if(!(cursor.getItemMeta() instanceof BookMeta)) {
return;
}
BookMeta meta = (BookMeta) cursor.getItemMeta();
if(meta == null) {
return;
}
saveWithName(player, meta, meta.getTitle());
}
});
inv.open();
if(setCursor != null) {
player.getOpenInventory().setCursor(setCursor);
}
}
private static void saveWithName(Player player, BookMeta meta, String name) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(name != null && Script.list(user).stream().noneMatch(script -> script.getName().equalsIgnoreCase(name))) {
Script.create(user, name, ScriptHelper.getScriptString(meta.getPages()));
player.getOpenInventory().setCursor(null);
ScriptRunner.updateGlobalScript(player);
open(player);
} else {
SWAnvilInv inv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ENTER_NAME", player), name == null ? "" : name);
inv.setCallback(s -> saveWithName(player, meta, s));
inv.open();
}
}
}

Datei anzeigen

@ -0,0 +1,55 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.sql.Script;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ScriptHelper {
private static final String PAGE_SEPARATOR = "\n\0\n";
public static ItemStack getScriptItem(Script script, boolean writeable) {
ItemStack itemStack = new ItemStack(writeable ? Material.WRITABLE_BOOK : Material.WRITTEN_BOOK);
BookMeta meta = (BookMeta) itemStack.getItemMeta();
if(!writeable) {
meta.setTitle(script.getName());
meta.setAuthor(SteamwarUser.get(script.getUserId()).getUserName());
}
meta.setPages(getScriptPages(script));
itemStack.setItemMeta(meta);
return itemStack;
}
public static List<String> getScriptPages(Script script) {
return Arrays.stream(script.getCode().split(PAGE_SEPARATOR)).collect(Collectors.toList());
}
public static String getScriptString(List<String> pages) {
return String.join(PAGE_SEPARATOR, pages);
}
}

Datei anzeigen

@ -1,6 +1,24 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.features.script.variables.Context;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@ -14,17 +32,13 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Linked
public class ScriptListener implements Listener {
private static final Map<Player, Context> GLOBAL_CONTEXT = new HashMap<>();
private Set<Player> playerSet = new HashSet<>();
private final Set<Player> playerSet = new HashSet<>();
@EventHandler(priority = EventPriority.HIGH)
public void onLeftClick(PlayerInteractEvent event) {
@ -44,20 +58,16 @@ public class ScriptListener implements Listener {
}
event.setCancelled(true);
new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) {
GLOBAL_CONTEXT.put(event.getPlayer(), new Context());
ScriptRunner.runScript(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null), event.getPlayer());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
GLOBAL_CONTEXT.remove(event.getPlayer());
ScriptRunner.remove(event.getPlayer());
}
public static Context getGlobalContext(Player player) {
return GLOBAL_CONTEXT.computeIfAbsent(player, ignore -> new Context());
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
ScriptRunner.updateGlobalScript(event.getPlayer());
}
}

Datei anzeigen

@ -0,0 +1,135 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.lua.CommandRegister;
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
import de.steamwar.bausystem.features.script.lua.SteamWarPlatform;
import de.steamwar.sql.Script;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@UtilityClass
public class ScriptRunner {
// Script Table
// User
// Key -> bau-script-<BUCH NAME>
// Value -> <LUA Script>
private static final Map<Player, Map<SteamWarGlobalLuaPlugin.EventType, List<LuaFunction>>> EVENT_MAP = new HashMap<>();
private static final Map<Player, Map<Hotkey, List<LuaFunction>>> HOTKEY_MAP = new HashMap<>();
private static final Map<Player, Map<String, CommandRegister>> COMMAND_MAP = new HashMap<>();
public static void runScript(String script, Player player) {
Globals globals = SteamWarPlatform.createClickGlobals(player);
try {
globals.load(script).call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_CLICK", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
}
public static void updateGlobalScript(Player player) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
ScriptRunner.createGlobalScript(Script.list(user).stream().map(Script::getCode).collect(Collectors.toList()), player);
}
public static void createGlobalScript(List<String> scripts, Player player) {
remove(player);
Globals globals = SteamWarPlatform.createGlobalGlobals(player,
(s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new EnumMap<>(SteamWarGlobalLuaPlugin.EventType.class)).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction),
(s, luaFunction) -> HOTKEY_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(Hotkey.fromString(s), s1 -> new ArrayList<>()).add(luaFunction),
commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister));
for (String script : scripts) {
try {
globals.load(script).call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
}
}
public static void remove(Player player) {
EVENT_MAP.remove(player);
COMMAND_MAP.remove(player);
HOTKEY_MAP.remove(player);
}
public static boolean callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) {
List<LuaFunction> luaFunctions = EVENT_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(event, Collections.emptyList());
if (luaFunctions == null) {
if(event == SteamWarGlobalLuaPlugin.EventType.DoubleSwap) {
player.performCommand("gui");
}
return false;
}
if (eventValue == LuaValue.NIL) {
eventValue = LuaValue.tableOf();
}
AtomicBoolean cancelled = new AtomicBoolean(false);
eventValue.set("setCancelled", new OneArgFunction() {
@Override
public LuaValue call(LuaValue arg) {
cancelled.set(arg.checkboolean());
return valueOf(cancelled.get());
}
});
for (LuaFunction luaFunction : luaFunctions) {
luaFunction.call(eventValue);
}
return cancelled.get();
}
public static boolean callCommand(Player player, String command, LuaValue args) {
CommandRegister commandRegister = COMMAND_MAP.getOrDefault(player, Collections.emptyMap()).get(command);
if (commandRegister == null) {
return false;
}
commandRegister.getFunction().call(args);
return true;
}
public static void callHotkey(int mods, int key, Player player, boolean pressed) {
Hotkey hotkey = Hotkey.fromChar(key, mods);
HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed)));
}
}

Datei anzeigen

@ -1,105 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.custom.event.EventType;
import de.steamwar.bausystem.features.script.expression.Expression;
import de.steamwar.linkage.Linked;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject;
import java.util.Arrays;
@Linked
public class ScriptSyntaxSender implements Listener {
private byte[] syntax;
{
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(BauSystem.getInstance(), "sw:script_syntax");
// Whole Syntax object
YAPIONObject yapionObject = new YAPIONObject();
ScriptExecutor.SPECIAL_COMMANDS.toString();
// Operators
YAPIONArray operators = new YAPIONArray();
yapionObject.add("@operators", operators);
Expression.OPERATORS.forEach((s, operator) -> {
operators.add(s);
});
// Headers
YAPIONArray headers = new YAPIONArray();
yapionObject.add("@headers", headers);
headers.add("CMD /.*");
headers.add("EVENT " + Arrays.stream(EventType.values()).map(Enum::name).reduce((s, s2) -> s + "|" + s2).map(s -> "(" + s + ")").orElse("") + "( .+)?");
headers.add("HOTKEY .+");
// Variable prefixes
YAPIONArray prefixes = new YAPIONArray();
yapionObject.add("@prefixes", prefixes);
prefixes.add("global");
prefixes.add("const");
prefixes.add("local");
// Variable suffixes
YAPIONArray suffixes = new YAPIONArray();
yapionObject.add("@suffixes", suffixes);
suffixes.add("isset");
suffixes.add("type");
suffixes.add("length");
// Commands
ScriptExecutor.SPECIAL_COMMANDS.forEach(specialCommand -> {
YAPIONArray yapionArray = new YAPIONArray();
yapionObject.add(specialCommand.command(), yapionArray);
if (specialCommand.repeating()) {
yapionArray.add(true);
} else {
yapionArray.add(false);
}
for (SpecialCommand.TokenType[] types : specialCommand.getSyntax()) {
YAPIONArray syntax = new YAPIONArray();
yapionArray.add(syntax);
for (SpecialCommand.TokenType type : types) {
syntax.add(type.ordinal());
}
}
});
syntax = yapionObject.toJSONLossy(new StringOutput()).getResult().getBytes();
}
@EventHandler
@SneakyThrows
public void onPlayerJoin(PlayerJoinEvent event) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
event.getPlayer().sendPluginMessage(BauSystem.getInstance(), "sw:script_syntax", syntax);
}, 5);
}
}

Datei anzeigen

@ -1,86 +0,0 @@
package de.steamwar.bausystem.features.script;
import org.bukkit.Material;
public interface SpecialCommand {
default String[] description() {
return new String[0];
}
default Material material() {
return Material.PAPER;
}
String command();
boolean execute(String[] command, ScriptExecutor scriptExecutor);
default boolean repeating() {
return false;
}
TokenType[][] getSyntax();
default long asLong(String value) {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
return 0;
}
}
default boolean asBoolean(String value) {
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes");
}
default String asString(String value) {
return value;
}
default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) {
scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> {
scriptExecutor.setIndex(integer);
return integer;
});
}
default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) {
Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null);
if (jp == null) {
scriptExecutor.getPlayer().sendMessage(message);
return;
}
scriptExecutor.setIndex(jp);
}
default void jumpToIndexWithMessageAndReturnStack(ScriptExecutor scriptExecutor, String jumpPoint, String message) {
Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null);
if (jp == null) {
scriptExecutor.getPlayer().sendMessage(message);
return;
}
scriptExecutor.getReturnStack().add(scriptExecutor.getIndex());
scriptExecutor.setIndex(jp);
}
default void returnFromStackWithMessage(ScriptExecutor scriptExecutor, String message) {
if (scriptExecutor.getReturnStack().isEmpty()) {
scriptExecutor.getPlayer().sendMessage(message);
return;
}
scriptExecutor.setIndex(scriptExecutor.getReturnStack().pop());
}
enum TokenType {
any, // This does not include jump_point and variable
expression,
jump_point,
variable,
text_type,
number_type,
floating_number_type,
boolean_type,
}
}

Datei anzeigen

@ -1,20 +1,20 @@
/*
* This file is a part of the SteamWar software.
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script;
@ -37,7 +37,8 @@ public class UnsignCommand extends SWCommand {
public void unsignCommand(Player p) {
ItemStack itemStack = p.getInventory().getItemInMainHand();
if (FlatteningWrapper.impl.isNoBook(itemStack)) return;
itemStack.setType(Material.WRITABLE_BOOK);
p.getInventory().setItemInMainHand(itemStack);
ItemStack clone = new ItemStack(Material.WRITABLE_BOOK);
clone.setItemMeta(itemStack.getItemMeta());
p.getInventory().setItemInMainHand(clone);
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Call implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_CALL_HELP_1",
"",
"SCRIPT_COMMAND_CALL_HELP_2"
};
}
@Override
public Material material() {
return Material.LEATHER_BOOTS;
}
@Override
public String command() {
return "call";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer());
return true;
}
jumpToIndexWithMessageAndReturnStack(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_CALL_ERROR", scriptExecutor.getPlayer(), command[1]));
return true;
}
private TokenType[][] syntax = {
{ TokenType.jump_point },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,41 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Exit implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_EXIT_HELP_1",
"",
"SCRIPT_COMMAND_EXIT_HELP_2"
};
}
@Override
public Material material() {
return Material.BARRIER;
}
@Override
public String command() {
return "exit";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
return false;
}
private TokenType[][] syntax = {};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,68 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class If implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_IF_HELP_1",
"SCRIPT_COMMAND_IF_HELP_2",
"",
"SCRIPT_COMMAND_IF_HELP_3"
};
}
@Override
public Material material() {
return Material.OBSERVER;
}
@Override
public String command() {
return "if";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length < 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE", scriptExecutor.getPlayer());
return true;
}
if (command.length < 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT", scriptExecutor.getPlayer());
return true;
}
Value v = scriptExecutor.getOrItselfValue(command[1]);
if (!(v instanceof Value.BooleanValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_NO_BOOLEAN", scriptExecutor.getPlayer());
return false;
}
if (v.asBoolean() && command.length > 2) {
jumpToIndex(scriptExecutor, command[2]);
} else if (command.length > 3) {
jumpToIndex(scriptExecutor, command[3]);
}
return true;
}
private TokenType[][] syntax = {
{ TokenType.boolean_type, TokenType.jump_point },
{ TokenType.boolean_type, TokenType.jump_point, TokenType.jump_point },
{ TokenType.expression, TokenType.jump_point },
{ TokenType.expression, TokenType.jump_point, TokenType.jump_point }
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Jump implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_JUMP_HELP_1",
"",
"SCRIPT_COMMAND_JUMP_HELP_2"
};
}
@Override
public Material material() {
return Material.LEATHER_BOOTS;
}
@Override
public String command() {
return "jump";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer());
return true;
}
jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_JUMP_ERROR", scriptExecutor.getPlayer(), command[1]));
return true;
}
private TokenType[][] syntax = {
{ TokenType.jump_point }
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,43 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Return implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_RETURN_HELP_1",
"",
"SCRIPT_COMMAND_RETURN_HELP_2"
};
}
@Override
public Material material() {
return Material.DIAMOND_BOOTS;
}
@Override
public String command() {
return "return";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
returnFromStackWithMessage(scriptExecutor, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_RETURN_ERROR", scriptExecutor.getPlayer()));
return true;
}
private TokenType[][] syntax = {};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,58 +0,0 @@
package de.steamwar.bausystem.features.script.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@Linked
public class Sleep implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_SLEEP_HELP_1",
"",
"SCRIPT_COMMAND_SLEEP_HELP_2"
};
}
@Override
public Material material() {
return Material.CLOCK;
}
@Override
public String command() {
return "sleep";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER", scriptExecutor.getPlayer());
return true;
}
long sleepTime = asLong(command[1]);
if (sleepTime < 0) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_SLEEP_ERROR", scriptExecutor.getPlayer());
return true;
}
if (sleepTime == 0) {
return true;
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), scriptExecutor::resume, sleepTime);
return false;
}
private TokenType[][] syntax = {
{ TokenType.number_type }
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,107 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.arithmetic.other;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Ceil implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2",
"",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3"
};
}
@Override
public Material material() {
return Material.REDSTONE_TORCH;
}
@Override
public String command() {
return "ceil";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
Value v1;
Value v2;
if (command.length == 3) {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
v2 = new Value.LongValue(0);
} else {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
}
if (!(v1 instanceof Value.DoubleValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.LongValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() < 0) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() == 0) {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.ceil(v1.asDouble())));
} else {
double pow = Math.pow(10, v2.asLong());
scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.ceil(v1.asDouble() * pow) / pow));
}
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type },
{ TokenType.variable, TokenType.variable, TokenType.number_type },
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
{ TokenType.variable, TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,107 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.arithmetic.other;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Floor implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2",
"",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3"
};
}
@Override
public Material material() {
return Material.REDSTONE_TORCH;
}
@Override
public String command() {
return "floor";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
Value v1;
Value v2;
if (command.length == 3) {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
v2 = new Value.LongValue(0);
} else {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
}
if (!(v1 instanceof Value.DoubleValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.LongValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() < 0) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() == 0) {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.floor(v1.asDouble())));
} else {
double pow = Math.pow(10, v2.asLong());
scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.floor(v1.asDouble() * pow) / pow));
}
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type },
{ TokenType.variable, TokenType.variable, TokenType.number_type },
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
{ TokenType.variable, TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,107 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.arithmetic.other;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Round implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2",
"",
"SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3"
};
}
@Override
public Material material() {
return Material.REDSTONE_TORCH;
}
@Override
public String command() {
return "round";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
Value v1;
Value v2;
if (command.length == 3) {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
v2 = new Value.LongValue(0);
} else {
v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
}
if (!(v1 instanceof Value.DoubleValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.LongValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() < 0) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer());
return true;
}
if (v2.asLong() == 0) {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(Math.round(v1.asDouble())));
} else {
double pow = Math.pow(10, v2.asLong());
scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.round(v1.asDouble() * pow) / pow));
}
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type },
{ TokenType.variable, TokenType.variable, TokenType.number_type },
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
{ TokenType.variable, TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,62 +0,0 @@
package de.steamwar.bausystem.features.script.command.io;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
@Linked
public class Echo implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_IO_ECHO_HELP_1",
"",
"SCRIPT_COMMAND_IO_ECHO_HELP_2"
};
}
@Override
public Material material() {
return Material.OAK_SIGN;
}
@Override
public String command() {
return "echo";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
scriptExecutor.getEchoConsumer().accept("");
return true;
}
StringBuilder st = new StringBuilder();
for (int i = 1; i < command.length; i++) {
if (i != 1) {
st.append(" ");
}
st.append(command[i]);
}
scriptExecutor.getEchoConsumer().accept(ChatColor.translateAlternateColorCodes('&', st.toString()));
return true;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,62 +0,0 @@
package de.steamwar.bausystem.features.script.command.io;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
@Linked
public class Echoactionbar implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1",
"",
"SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2"
};
}
@Override
public Material material() {
return Material.BIRCH_SIGN;
}
@Override
public String command() {
return "echoactionbar";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
SWUtils.sendToActionbar(scriptExecutor.getPlayer(), "");
return true;
}
StringBuilder st = new StringBuilder();
for (int i = 1; i < command.length; i++) {
if (i != 1) {
st.append(" ");
}
st.append(command[i]);
}
SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString()));
return true;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,79 +0,0 @@
package de.steamwar.bausystem.features.script.command.io;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.linkage.Linked;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@Linked
public class Input implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_IO_INPUT_HELP_1",
"",
"SCRIPT_COMMAND_IO_INPUT_HELP_2"
};
}
@Override
public Material material() {
return Material.ANVIL;
}
@Override
public String command() {
return "input";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
StringBuilder st = new StringBuilder();
for (int i = 2; i < command.length; i++) {
if (i != 2) {
st.append(" ");
}
st.append(command[i]);
}
SWAnvilInv swAnvilInv = new SWAnvilInv(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString()));
swAnvilInv.setCallback(s -> {
try {
long value = Long.parseLong(s);
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(value));
} catch (NumberFormatException e) {
if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(s.equalsIgnoreCase("true")));
} else {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(s));
}
}
scriptExecutor.resume();
});
swAnvilInv.addCloseCallback(scriptExecutor::resume);
swAnvilInv.open();
return false;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,98 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.string;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Insert implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_STRING_INSERT_HELP_1",
"SCRIPT_COMMAND_STRING_INSERT_HELP_2",
"",
"SCRIPT_COMMAND_STRING_INSERT_HELP_3"
};
}
@Override
public Material material() {
return Material.HOPPER;
}
@Override
public String command() {
return "insert";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 3) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER", scriptExecutor.getPlayer());
return true;
}
String resultName = command[1];
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]);
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
if (!(v1 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v3 instanceof Value.LongValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(new StringBuilder(v1.asString()).insert((int) v3.asLong(), v2.asString()).toString()));
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable, TokenType.number_type },
{ TokenType.variable, TokenType.variable, TokenType.variable, TokenType.number_type },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,89 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.string;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Remove implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_STRING_REMOVE_HELP_1",
"SCRIPT_COMMAND_STRING_REMOVE_HELP_2",
"",
"SCRIPT_COMMAND_STRING_REMOVE_HELP_3"
};
}
@Override
public Material material() {
return Material.SHEARS;
}
@Override
public String command() {
return "remove";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
String resultName = command[1];
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
if (!(v1 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), "")));
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.variable, TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,98 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.string;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Replace implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_STRING_REPLACE_HELP_1",
"SCRIPT_COMMAND_STRING_REPLACE_HELP_2",
"",
"SCRIPT_COMMAND_STRING_REPLACE_HELP_3"
};
}
@Override
public Material material() {
return Material.WOODEN_AXE;
}
@Override
public String command() {
return "replace";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 3) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
String resultName = command[1];
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]);
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
if (!(v1 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v3 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), v3.asString())));
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.variable, TokenType.variable },
{ TokenType.variable, TokenType.variable, TokenType.variable, TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,99 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.string;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Substring implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1",
"SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2",
"",
"SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3"
};
}
@Override
public Material material() {
return Material.STICKY_PISTON;
}
@Override
public String command() {
return "substring";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
String resultName = command[1];
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
if (!(v1 instanceof Value.StringValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
if (!(v2 instanceof Value.LongValue)) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer());
return true;
}
Value result;
try {
if (v2.asLong() < 0) {
result = new Value.StringValue(v1.asString().substring(v1.asString().length() - 1 - (int) v2.asLong()));
} else {
result = new Value.StringValue(v1.asString().substring((int) v2.asLong()));
}
} catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException e) {
result = new Value.StringValue("");
}
scriptExecutor.getLocalVariables().putValue(resultName, result);
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.number_type },
{ TokenType.variable, TokenType.variable, TokenType.number_type },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,87 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Constants;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Const implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_CONST_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_CONST_HELP_2"
};
}
@Override
public Material material() {
return Material.STRUCTURE_BLOCK;
}
@Override
public String command() {
return "const";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
String varName = command[1];
StringBuilder varValue = new StringBuilder();
for (int i = 2; i < command.length; i++) {
if (varValue.length() != 0) {
varValue.append(" ");
}
varValue.append(command[i]);
}
Constants.getConstant(varName, scriptExecutor.getPlayer()).fromValue(Value.parse(varValue.toString()));
return true;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,74 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Convert implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2",
};
}
@Override
public Material material() {
return Material.ENDER_CHEST;
}
@Override
public String command() {
return "convert";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getLocalVariables().putValue(command[1], Value.parse(command[2]));
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,67 +0,0 @@
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Global implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2"
};
}
@Override
public Material material() {
return Material.MAP;
}
@Override
public String command() {
return "global";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
String varName = command[1];
StringBuilder varValue = new StringBuilder();
for (int i = 2; i < command.length; i++) {
if (varValue.length() != 0) {
varValue.append(" ");
}
varValue.append(command[i]);
}
scriptExecutor.getGlobalVariables().putValue(varName, Value.parse(varValue.toString()));
return true;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Unglobal implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2"
};
}
@Override
public Material material() {
return Material.BEACON;
}
@Override
public String command() {
return "unglobal";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getGlobalVariables().removeValue(command[1]);
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Unvar implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2"
};
}
@Override
public Material material() {
return Material.STRUCTURE_VOID;
}
@Override
public String command() {
return "unvar";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
scriptExecutor.getLocalVariables().removeValue(command[1]);
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,67 +0,0 @@
package de.steamwar.bausystem.features.script.command.variable;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
@Linked
public class Var implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_VARIABLE_VAR_HELP_1",
"",
"SCRIPT_COMMAND_VARIABLE_VAR_HELP_2"
};
}
@Override
public Material material() {
return Material.STRUCTURE_BLOCK;
}
@Override
public String command() {
return "var";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
String varName = command[1];
StringBuilder varValue = new StringBuilder();
for (int i = 2; i < command.length; i++) {
if (varValue.length() != 0) {
varValue.append(" ");
}
varValue.append(command[i]);
}
scriptExecutor.getLocalVariables().putValue(varName, Value.parse(varValue.toString()));
return true;
}
@Override
public boolean repeating() {
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.any },
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,89 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@Linked
public class GetMaterial implements SpecialCommand {
private final World world = Bukkit.getWorlds().get(0);
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1",
"",
"SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2"
};
}
@Override
public Material material() {
return Material.STICKY_PISTON;
}
@Override
public String command() {
return "getmaterial";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 3) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 4) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong();
int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong();
int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong();
scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(world.getBlockAt(x, y, z).getType().name()));
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type }
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,92 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.command.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@Linked
public class SetMaterial implements SpecialCommand {
private final World world = Bukkit.getWorlds().get(0);
@Override
public String[] description() {
return new String[]{
"SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1",
"",
"SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2"
};
}
@Override
public Material material() {
return Material.PISTON;
}
@Override
public String command() {
return "setmaterial";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 2) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 3) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
if (command.length <= 4) {
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer());
return true;
}
int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong();
int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong();
int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong();
try {
world.getBlockAt(x, y, z).setType(Material.valueOf(scriptExecutor.getOrItself(command[1])));
} catch (Exception e) {
// Ignored
}
return true;
}
private TokenType[][] syntax = {
{ TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type }
};
@Override
public TokenType[][] getSyntax() {
return syntax;
}
}

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom;
import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Player;
import yapion.hierarchy.types.YAPIONMap;
public interface MenuScript {
void save(YAPIONMap yapionMap);
SWItem toItem(Player p);
}

Datei anzeigen

@ -1,23 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom;
public interface Script {
}

Datei anzeigen

@ -1,45 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.command;
import de.steamwar.bausystem.features.script.CustomScriptManager;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@Linked
public class CommandListener implements Listener {
@LinkedInstance
public CustomScriptManager manager;
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
if (e.getMessage().startsWith("/script:")) {
e.setMessage("/" + e.getMessage().substring(8));
return;
}
manager.callCommand(e.getPlayer(), e, e.getMessage());
}
}

Datei anzeigen

@ -1,87 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.command;
import de.steamwar.bausystem.features.script.custom.Script;
import de.steamwar.bausystem.features.script.variables.Value;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.HashMap;
import java.util.Map;
public interface CustomCommand extends Script {
String[] command();
default Map<String, Value> check(String[] args, String[] command) {
if (args.length < command.length) {
return null;
}
if (!args[0].equals(command[0])) {
return null;
}
Map<String, Value> arguments = new HashMap<>();
if (!check(arguments, args, command, 0, 0)) {
return null;
}
return arguments;
}
default boolean check(Map<String, Value> arguments, String[] args, String[] command, int argsIndex, int commandIndex) {
if (command.length <= commandIndex) {
for (int i = argsIndex; i < args.length; i++) {
if (!(args[i].startsWith("(") && args[i].endsWith(")"))) {
return false;
}
}
return true;
}
if (args.length <= argsIndex) return true;
String currentArg = args[argsIndex];
String currentCommand = command[commandIndex];
if (currentArg.startsWith("<") && currentArg.endsWith(">")) {
arguments.put(trim(currentArg, 1), new Value.StringValue(currentCommand));
return check(arguments, args, command, argsIndex + 1, commandIndex + 1);
} else if (currentArg.startsWith("(<") && currentArg.endsWith(">)")) {
arguments.put(trim(currentArg, 2), new Value.StringValue(currentCommand));
return check(arguments, args, command, argsIndex + 1, commandIndex + 1);
} else if (currentArg.startsWith("(") && currentArg.endsWith(")")) {
if (!trim(currentArg, 1).equals(currentCommand)) {
arguments.put(trim(currentArg, 1), new Value.BooleanValue(false));
return check(arguments, args, command, argsIndex + 1, commandIndex);
} else {
arguments.put(trim(currentArg, 1), new Value.BooleanValue(true));
return check(arguments, args, command, argsIndex + 1, commandIndex + 1);
}
} else {
if (!currentArg.equals(currentCommand)) return false;
return check(arguments, args, command, argsIndex + 1, commandIndex + 1);
}
}
default String trim(String s, int count) {
return s.substring(count, s.length() - count);
}
boolean execute(String[] command, PlayerCommandPreprocessEvent e);
}

Datei anzeigen

@ -1,51 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.command;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.variables.Value;
import lombok.RequiredArgsConstructor;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.meta.BookMeta;
import java.util.Map;
@RequiredArgsConstructor
public
class InventoryCommand implements CustomCommand {
public final BookMeta bookMeta;
public final String[] args;
@Override
public String[] command() {
return args;
}
public boolean execute(String[] command, PlayerCommandPreprocessEvent e) {
Map<String, Value> arguments = check(args, command);
if (arguments == null) {
return false;
}
e.setCancelled(true);
new ScriptExecutor(bookMeta, e.getPlayer(), arguments, null);
return true;
}
}

Datei anzeigen

@ -1,99 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.command;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.custom.MenuScript;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.inventory.SWItem;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.meta.BookMeta;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONMap;
import java.util.List;
import java.util.Map;
@RequiredArgsConstructor
public
class MenuCommand implements CustomCommand, MenuScript {
public final List<String> pages;
public final String[] args;
@Override
public String[] command() {
return args;
}
public boolean execute(String[] command, PlayerCommandPreprocessEvent e) {
Map<String, Value> arguments = check(args, command);
if (arguments == null) {
return false;
}
e.setCancelled(true);
new ScriptExecutor(pages, e.getPlayer(), arguments, null);
return true;
}
public boolean equals(MenuCommand menuCommand) {
if (menuCommand.args.length != args.length) {
return false;
}
if (!args[0].equals(menuCommand.args[0])) {
return false;
}
for (int i = 0; i < args.length; i++) {
if (i == 0) continue;
String s1 = args[i];
String s2 = menuCommand.args[i];
if (!s1.equals(s2)) {
return false;
}
if (!(s1.startsWith("<") && s1.endsWith(">") && s2.startsWith("<") && s2.endsWith(">"))) {
return false;
}
if (!(s1.startsWith("(<") && s1.endsWith(">)") && s2.startsWith("(<") && s2.endsWith(">)"))) {
return false;
}
}
return true;
}
@Override
public void save(YAPIONMap yapionMap) {
YAPIONArray yapionArray = new YAPIONArray();
pages.forEach(yapionArray::add);
yapionMap.put(String.join(" ", args), yapionArray);
}
@Override
public SWItem toItem(Player p) {
SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", p, String.join(" ", args)));
BookMeta bookMeta = (BookMeta) swItem.getItemMeta();
bookMeta.setPages(pages.toArray(new String[0]));
swItem.setItemMeta(bookMeta);
return swItem;
}
}

Datei anzeigen

@ -1,34 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.event;
import de.steamwar.bausystem.features.script.custom.Script;
import de.steamwar.bausystem.features.script.variables.Value;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.function.Consumer;
public interface CustomEvent extends Script {
String eventName();
boolean execute(Player p, Map<String, Value> variables, Consumer<String> echoConsumer);
}

Datei anzeigen

@ -1,146 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.event;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.CustomScriptManager;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Linked
public class EventListener implements Listener {
@LinkedInstance
public CustomScriptManager manager;
private static final Map<Player, Long> LAST_FS = new HashMap<>();
{
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
LAST_FS.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() > 200);
}, 2, 2);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
manager.callEvent(EventType.SelfJoin, event.getPlayer(), event);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
manager.callEvent(EventType.SelfLeave, event.getPlayer(), event);
}
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
if (LAST_FS.containsKey(event.getPlayer())) {
manager.callEvent(EventType.FF, event.getPlayer(), event);
} else {
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
manager.callEvent(EventType.PlaceBlock, event.getPlayer(), event);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
manager.callEvent(EventType.BreakBlock, event.getPlayer(), event);
}
private Set<Player> ignore = new HashSet<>();
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (ignore.remove(event.getPlayer())) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
manager.callEvent(EventType.RightClick, event.getPlayer(), event);
}
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
manager.callEvent(EventType.LeftClick, event.getPlayer(), event);
}
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.PRIMED_TNT) {
return;
}
Region tntRegion = Region.getRegion(event.getLocation());
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
manager.callEvent(EventType.TNTSpawn, player, event);
}
}
}
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntityType() != EntityType.PRIMED_TNT) {
return;
}
Region tntRegion = Region.getRegion(event.getLocation());
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
manager.callEvent(EventType.TNTExplode, player, event);
}
}
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
ignore.add(event.getPlayer());
manager.callEvent(EventType.DropItem, event.getPlayer(), event);
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
for (Player player : Bukkit.getOnlinePlayers()) {
manager.callEvent(EventType.EntityDeath, player, event);
}
}
}

Datei anzeigen

@ -1,133 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.event;
import de.steamwar.bausystem.features.script.variables.Value;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.*;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
@Getter
public enum EventType {
FF(PlayerSwapHandItemsEvent.class, event -> null),
PlaceBlock(BlockPlaceEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addBlockXYZ(valueMap, event.getBlockPlaced().getLocation());
valueMap.put("blockType", new Value.StringValue(event.getBlockPlaced().getType().name()));
return valueMap;
}),
BreakBlock(BlockBreakEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addBlockXYZ(valueMap, event.getBlock().getLocation());
valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name()));
return valueMap;
}),
RightClick(PlayerInteractEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
valueMap.put("action", new Value.StringValue(event.getAction().name()));
valueMap.put("handType", new Value.StringValue(event.getMaterial().name()));
valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock()));
if (event.hasBlock()) {
addBlockXYZ(valueMap, event.getClickedBlock().getLocation());
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
}
return valueMap;
}),
LeftClick(PlayerInteractEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
valueMap.put("action", new Value.StringValue(event.getAction().name()));
valueMap.put("handType", new Value.StringValue(event.getMaterial().name()));
valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock()));
if (event.hasBlock()) {
addBlockXYZ(valueMap, event.getClickedBlock().getLocation());
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
}
return valueMap;
}),
TNTSpawn(EntitySpawnEvent.class, event -> null),
TNTExplode(EntityExplodeEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addXYZ(valueMap, event.getLocation());
return valueMap;
}),
TNTExplodeInBuild(EntityExplodeEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addXYZ(valueMap, event.getLocation());
return valueMap;
}),
SelfJoin(PlayerJoinEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addXYZ(valueMap, event.getPlayer().getLocation());
return valueMap;
}),
SelfLeave(PlayerQuitEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
addXYZ(valueMap, event.getPlayer().getLocation());
return valueMap;
}),
DropItem(PlayerDropItemEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("material", new Value.StringValue(event.getItemDrop().getItemStack().getType().name()));
addXYZ(valueMap, event.getItemDrop().getLocation());
return valueMap;
}),
EntityDeath(EntityDeathEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("entityType", new Value.StringValue(event.getEntityType().name()));
addXYZ(valueMap, event.getEntity().getLocation());
return valueMap;
}),
Scoreboard(Event.class, event -> {
return new HashMap<>();
}),
;
private static void addXYZ(Map<String, Value> valueMap, Location location) {
valueMap.put("x", new Value.DoubleValue(location.getX()));
valueMap.put("y", new Value.DoubleValue(location.getY()));
valueMap.put("z", new Value.DoubleValue(location.getZ()));
}
private static void addBlockXYZ(Map<String, Value> valueMap, Location location) {
valueMap.put("blockX", new Value.LongValue(location.getBlockX()));
valueMap.put("blockY", new Value.LongValue(location.getBlockY()));
valueMap.put("blockZ", new Value.LongValue(location.getBlockZ()));
}
private Class<? extends Event> eventType;
private Function<Event, Map<String, Value>> eventValues;
<T extends Event> EventType(Class<T> eventType, Function<T, Map<String, Value>> eventValues) {
this.eventType = eventType;
this.eventValues = event -> eventValues.apply((T) event);
}
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.event;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.variables.Value;
import lombok.RequiredArgsConstructor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.BookMeta;
import java.util.Map;
import java.util.function.Consumer;
@RequiredArgsConstructor
public
class InventoryEvent implements CustomEvent {
public final BookMeta bookMeta;
public final String[] args;
@Override
public String eventName() {
return args[0];
}
@Override
public boolean execute(Player p, Map<String, Value> variables, Consumer<String> echoConsumer) {
new ScriptExecutor(bookMeta, p, variables, echoConsumer);
return true;
}
}

Datei anzeigen

@ -1,76 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.event;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.custom.MenuScript;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.inventory.SWItem;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.BookMeta;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@RequiredArgsConstructor
public
class MenuEvent implements CustomEvent, MenuScript {
public final List<String> pages;
public final String[] args;
@Override
public String eventName() {
return args[0];
}
@Override
public boolean execute(Player p, Map<String, Value> variables, Consumer<String> echoConsumer) {
new ScriptExecutor(pages, p, variables, echoConsumer);
return false;
}
@Override
public void save(YAPIONMap yapionMap) {
YAPIONArray yapionArray = new YAPIONArray();
pages.forEach(yapionArray::add);
yapionMap.put(String.join(" ", args), yapionArray);
}
@Override
public SWItem toItem(Player p) {
StringBuilder st = new StringBuilder();
for (int i = 1; i < args.length; i++) {
if (i != 1) st.append(" ");
st.append(args[i]);
}
SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", p, args[0], st.toString()));
BookMeta bookMeta = (BookMeta) swItem.getItemMeta();
bookMeta.setPages(pages.toArray(new String[0]));
swItem.setItemMeta(bookMeta);
return swItem;
}
}

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.hotkey;
import de.steamwar.bausystem.features.script.custom.Script;
import org.bukkit.entity.Player;
public interface Hotkey extends Script {
String hotkey();
boolean execute(Player p, boolean pressed);
}

Datei anzeigen

@ -1,135 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.hotkey;
import java.util.HashSet;
import java.util.Set;
public interface Hotkeys {
public static boolean isSame(int mods, char key, String checkAgainst) {
Set<Modifier> modifiers = Modifier.get(mods);
Key k = Key.fromString(key + "");
if (k == null) {
return false;
}
try {
String[] split = checkAgainst.split("\\+");
Set<Modifier> checkModifiers = new HashSet<>();
Key checkKey = null;
for (String s : split) {
Modifier m = Modifier.fromString(s);
if (m != null) {
checkModifiers.add(m);
} else {
checkKey = Key.fromString(s);
}
}
return checkKey == k && checkModifiers.equals(modifiers);
} catch (Exception e) {
return false;
}
}
enum Modifier {
SHIFT,
CTRL,
ALT,
META,
;
public static Set<Modifier> get(int mods) {
Set<Modifier> modifiers = new HashSet<>();
for (Modifier modifier : values()) {
if ((mods & (1 << modifier.ordinal())) != 0) {
modifiers.add(modifier);
}
}
return modifiers;
}
public static Modifier fromString(String string) {
try {
return valueOf(string.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}
enum Key {
// A-Z
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
// 0-9
NUM_0,
NUM_1,
NUM_2,
NUM_3,
NUM_4,
NUM_5,
NUM_6,
NUM_7,
NUM_8,
NUM_9,
;
public static Key fromString(String key) {
key = key.toUpperCase();
try {
return Key.valueOf(key);
} catch (IllegalArgumentException e) {
// ignore
}
try {
return Key.valueOf("NUM_" + key);
} catch (IllegalArgumentException e) {
// ignore
}
return null;
}
}
}

Datei anzeigen

@ -1,51 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.hotkey;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.variables.Value;
import lombok.RequiredArgsConstructor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.BookMeta;
import java.util.HashMap;
import java.util.Map;
@RequiredArgsConstructor
public
class InventoryHotkey implements Hotkey {
public final BookMeta bookMeta;
public final String[] args;
@Override
public String hotkey() {
return args[0];
}
@Override
public boolean execute(Player p, boolean pressed) {
Map<String, Value> variables = new HashMap<>();
variables.put("pressed", new Value.BooleanValue(pressed));
variables.put("released", new Value.BooleanValue(!pressed));
new ScriptExecutor(bookMeta, p, variables, null);
return false;
}
}

Datei anzeigen

@ -1,80 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.hotkey;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.custom.MenuScript;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.inventory.SWItem;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.BookMeta;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequiredArgsConstructor
public
class MenuHotkey implements Hotkey, MenuScript {
public final List<String> pages;
public final String[] args;
@Override
public String hotkey() {
return args[0];
}
@Override
public boolean execute(Player p, boolean pressed) {
Map<String, Value> variables = new HashMap<>();
variables.put("pressed", new Value.BooleanValue(pressed));
variables.put("released", new Value.BooleanValue(!pressed));
new ScriptExecutor(pages, p, variables, null);
return false;
}
@Override
public void save(YAPIONMap yapionMap) {
YAPIONArray yapionArray = new YAPIONArray();
pages.forEach(yapionArray::add);
yapionMap.put(String.join(" ", args), yapionArray);
}
@Override
public SWItem toItem(Player p) {
StringBuilder st = new StringBuilder();
for (int i = 1; i < args.length; i++) {
if (i != 1) st.append(" ");
st.append(args[i]);
}
SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", p, args[0], st.toString()));
BookMeta bookMeta = (BookMeta) swItem.getItemMeta();
bookMeta.setPages(pages.toArray(new String[0]));
swItem.setItemMeta(bookMeta);
return swItem;
}
}

Datei anzeigen

@ -0,0 +1,41 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.event;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.linkage.Linked;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.luaj.vm2.LuaValue;
@Linked
public class CommandListener implements Listener {
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
LuaValue[] values = new LuaValue[split.length - 1];
for (int i = 1; i < split.length; i++) {
values[i - 1] = LuaValue.valueOf(split[i]);
}
event.setCancelled(ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), LuaValue.listOf(values)));
}
}

Datei anzeigen

@ -0,0 +1,185 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.event;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.*;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Linked
public class EventListener implements Listener {
private static final Map<Player, Long> LAST_FS = new HashMap<>();
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
LAST_FS.entrySet().removeIf(entry -> TPSUtils.currentTick.get() - entry.getValue() > 4);
}, 2, 2);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerQuit(PlayerQuitEvent event) {
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
if (LAST_FS.containsKey(event.getPlayer())) {
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL));
} else {
LAST_FS.put(event.getPlayer(), TPSUtils.currentTick.get());
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
LuaTable table = new LuaTable();
table.set("x", event.getBlock().getX());
table.set("y", event.getBlock().getY());
table.set("z", event.getBlock().getZ());
table.set("type", event.getBlock().getType().name());
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table));
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
LuaTable table = new LuaTable();
table.set("x", event.getBlock().getX());
table.set("y", event.getBlock().getY());
table.set("z", event.getBlock().getZ());
table.set("type", event.getBlock().getType().name());
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table));
}
private final Set<Player> ignore = new HashSet<>();
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (ignore.remove(event.getPlayer())) {
return;
}
LuaTable table = new LuaTable();
table.set("action", event.getAction().name());
table.set("hand", event.getHand().name());
table.set("block", event.getItem() == null ? Material.AIR.name() : event.getItem().getType().name());
if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
table.set("hasBlock", LuaValue.valueOf(true));
table.set("blockX", event.getClickedBlock().getX());
table.set("blockY", event.getClickedBlock().getY());
table.set("blockZ", event.getClickedBlock().getZ());
table.set("blockFace", event.getBlockFace().name());
} else {
table.set("hasBlock", LuaValue.valueOf(false));
}
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table));
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table));
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.PRIMED_TNT) {
return;
}
Region tntRegion = Region.getRegion(event.getLocation());
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntityType() != EntityType.PRIMED_TNT) {
return;
}
Region tntRegion = Region.getRegion(event.getLocation());
LuaTable table = new LuaTable();
table.set("x", event.getLocation().getX());
table.set("y", event.getLocation().getY());
table.set("z", event.getLocation().getZ());
boolean cancel = false;
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL) &&
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table)) {
cancel = true;
}
}
event.setCancelled(cancel);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
ignore.add(event.getPlayer());
LuaTable table = new LuaTable();
table.set("type", event.getItemDrop().getItemStack().getType().name());
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table));
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
for (Player player : Bukkit.getOnlinePlayers()) {
LuaTable table = new LuaTable();
table.set("type", event.getEntityType().name());
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table);
}
}
}

Datei anzeigen

@ -1,42 +1,39 @@
/*
* This file is a part of the SteamWar software.
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.custom.hotkey;
package de.steamwar.bausystem.features.script.event;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.CustomScriptManager;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import de.steamwar.linkage.api.Plain;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
@Linked
public class HotkeyListener implements PluginMessageListener {
public class HotkeyListener implements PluginMessageListener, Plain {
{
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this);
}
@LinkedInstance
public CustomScriptManager manager;
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!channel.equals("sw:hotkeys")) return;
@ -48,10 +45,11 @@ public class HotkeyListener implements PluginMessageListener {
if (message.length >= 9) {
int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF);
// player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods));
manager.callHotkey(mods, ((char) key), player, action == 1);
ScriptRunner.callHotkey(mods, key, player, action == 1);
} else {
// player.sendMessage("Hotkey: " + (char) key + " " + action);
manager.callHotkey(0, ((char) key), player, action == 1);
ScriptRunner.callHotkey(0, key, player, action == 1);
}
}
}

Datei anzeigen

@ -1,242 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.variables.Constants;
import de.steamwar.bausystem.features.script.variables.Value;
import org.bukkit.entity.Player;
import java.util.*;
public class Expression {
private static int highestPrecedence = 1;
public static final Map<String, Operator> OPERATORS = new HashMap<>();
public static void registerOperator(Operator operator) {
highestPrecedence = Math.max(highestPrecedence, operator.getPriority()) + 1;
OPERATORS.put(operator.getOperator(), operator);
}
private Player p;
private ScriptExecutor scriptExecutor;
private String s;
public Expression(Player p, String s, ScriptExecutor scriptExecutor) {
s = s.substring(1, s.length() - 1);
this.p = p;
this.s = s;
this.scriptExecutor = scriptExecutor;
}
public Value eval() {
List<Object> tokens = new ArrayList<>(tokenize(s));
List<Integer> priorities = priorities(tokens);
while (true) {
int toCalc = getToCalc(priorities);
if (priorities.get(toCalc) == 0) break;
if (priorities.get(toCalc) == highestPrecedence) {
String s = (String) tokens.get(toCalc);
if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) {
tokens.set(toCalc, new Value.BooleanValue(Boolean.parseBoolean(s)));
priorities.set(toCalc, 0);
continue;
}
String[] strings = s.split("\\.");
if (strings.length == 1) {
Value value = scriptExecutor.getValueOrNull(strings[0]);
if (value == null) {
throw new VarNotFoundException(strings[0]);
}
tokens.set(toCalc, value);
priorities.set(toCalc, 0);
} else {
boolean searchGlobal = false;
boolean searchConst = false;
boolean searchLocal = false;
if (strings[0].equals("global")) {
searchGlobal = true;
strings = Arrays.copyOfRange(strings, 1, strings.length);
} else if (strings[0].equals("const")) {
searchConst = true;
strings = Arrays.copyOfRange(strings, 1, strings.length);
} else if (strings[0].equals("local")) {
searchLocal = true;
strings = Arrays.copyOfRange(strings, 1, strings.length);
}
String varName = strings[0];
Value value;
if (searchGlobal) {
value = scriptExecutor.getGlobalVariables().getValue(varName);
} else if (searchConst) {
value = Constants.getConstant(varName, p);
} else if (searchLocal) {
value = scriptExecutor.getLocalVariables().getValue(varName);
} else {
value = scriptExecutor.getValueOrNull(varName);
}
for (int i = 1; i < strings.length; i++) {
switch (strings[i]) {
case "isset":
value = new Value.BooleanValue(value != null);
break;
case "type":
value = new Value.StringValue(value == null ? "" : value.type());
break;
case "length":
value = new Value.LongValue(value == null ? 0 : value.asString().length());
break;
}
}
if (value == null) {
throw new VarNotFoundException(strings[0]);
}
tokens.set(toCalc, value);
priorities.set(toCalc, 0);
}
} else {
Value first = parse(tokens.get(toCalc - 1));
Value second = parse(tokens.get(toCalc + 1));
String op = (String) tokens.get(toCalc);
Operator operation = OPERATORS.get(op);
if (operation == null) {
throw new UnknownOperatorException(op);
}
Value result = operation.operate(first, second);
tokens.set(toCalc - 1, result);
tokens.remove(toCalc);
tokens.remove(toCalc);
priorities.remove(toCalc);
priorities.remove(toCalc);
priorities.set(toCalc - 1, 0);
}
}
return parse(tokens.get(0));
}
private Value parse(Object token) {
if (token instanceof Value) {
return (Value) token;
} else if (token instanceof String) {
String s = (String) token;
if (s.startsWith("{") && s.endsWith("}")) {
return new Expression(p, s, scriptExecutor).eval();
} else {
return Value.parse(s);
}
} else {
throw new IllegalArgumentException("Unknown token: " + token);
}
}
private String getExpressionString(String s, int index) {
StringBuilder result = new StringBuilder();
int depth = 0;
for (int i = index; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '{') {
depth++;
} else if (c == '}') {
result.append(c);
depth--;
if (depth == 0) {
return result.toString();
}
}
if (depth > 0) {
result.append(c);
}
}
return result.toString();
}
private List<String> tokenize(String s) {
List<String> tokens = new ArrayList<>();
StringBuilder token = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == ' ') continue;
if (c == '{') {
String subExpression = getExpressionString(s, i);
tokens.add(subExpression);
i += subExpression.length() - 1;
continue;
}
StringBuilder op = new StringBuilder();
for (int j = i; j < s.length(); j++) {
char k = s.charAt(j);
if (k == '+' || k == '-' || k == '*' || k == '/' || k == '%' || k == '^' || k == '&' || k == '|' || k == '>' || k == '<' || k == '=' || k == '!') {
op.append(k);
} else {
break;
}
}
if (op.length() > 0) {
if (token.length() > 0) {
tokens.add(token.toString());
token = new StringBuilder();
}
tokens.add(op.toString());
i += op.length() - 1;
continue;
}
token.append(c);
}
if (token.length() > 0) {
tokens.add(token.toString());
}
return tokens;
}
private List<Integer> priorities(List<Object> tokens) {
List<Integer> priorities = new ArrayList<>();
for (Object obj : tokens) {
String token = (String) obj;
Operator operator = OPERATORS.get(token);
if (token.startsWith("{") && token.endsWith("}")) {
priorities.add(0);
} else if (!token.matches("[0-9]+([.,][0-9]+)?") && operator == null) {
priorities.add(highestPrecedence);
} else if (operator != null) {
priorities.add(operator.getPriority());
} else {
priorities.add(0);
}
}
return priorities;
}
private int getToCalc(List<Integer> priorities) {
int max = 0;
int index = 0;
for (int i = 0; i < priorities.size(); i++) {
if (priorities.get(i) > max) {
max = priorities.get(i);
index = i;
}
}
return index;
}
}

Datei anzeigen

@ -1,37 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression;
import de.steamwar.bausystem.features.script.variables.Value;
public interface Operator {
String getOperator();
int getPriority();
Value operate(Value value, Value value2);
default boolean is(Value value, Class<?>... classes) {
for (Class<?> clazz : classes) {
if (clazz.isInstance(value)) {
return true;
}
}
return false;
}
}

Datei anzeigen

@ -1,27 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression;
public class UnknownOperatorException extends RuntimeException{
public UnknownOperatorException(String message) {
super(message);
}
}

Datei anzeigen

@ -1,27 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression;
public class VarNotFoundException extends RuntimeException{
public VarNotFoundException(String message) {
super(message);
}
}

Datei anzeigen

@ -1,61 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class EqualOperator implements Operator {
@Override
public String getOperator() {
return "==";
}
@Override
public int getPriority() {
return 6;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) {
return new Value.BooleanValue(value.asDouble() == value2.asDouble());
}
if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() == value2.asDouble());
}
if (!value.type().equals(value2.type())) {
return new Value.BooleanValue(false);
}
if (value instanceof Value.StringValue) {
return new Value.BooleanValue(value.asString().equals(value2.asString()));
}
if (value instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() == value2.asDouble());
}
if (value instanceof Value.LongValue) {
return new Value.BooleanValue(value.asLong() == value2.asLong());
}
return new Value.BooleanValue(value.asBoolean() == value2.asBoolean());
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class GreaterOperator implements Operator {
@Override
public String getOperator() {
return ">";
}
@Override
public int getPriority() {
return 7;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() > value2.asDouble());
} else {
return new Value.BooleanValue(value.asLong() > value2.asLong());
}
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class GreaterOrEqualOperator implements Operator {
@Override
public String getOperator() {
return ">=";
}
@Override
public int getPriority() {
return 7;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() >= value2.asDouble());
} else {
return new Value.BooleanValue(value.asLong() >= value2.asLong());
}
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class LessOperator implements Operator {
@Override
public String getOperator() {
return "<";
}
@Override
public int getPriority() {
return 7;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() < value2.asDouble());
} else {
return new Value.BooleanValue(value.asLong() < value2.asLong());
}
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class LessOrEqualOperator implements Operator {
@Override
public String getOperator() {
return "<=";
}
@Override
public int getPriority() {
return 7;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() <= value2.asDouble());
} else {
return new Value.BooleanValue(value.asLong() <= value2.asLong());
}
}
}

Datei anzeigen

@ -1,61 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.comparison;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class NotEqualOperator implements Operator {
@Override
public String getOperator() {
return "!=";
}
@Override
public int getPriority() {
return 6;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) {
return new Value.BooleanValue(value.asDouble() != value2.asDouble());
}
if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() != value2.asDouble());
}
if (!value.type().equals(value2.type())) {
return new Value.BooleanValue(false);
}
if (value instanceof Value.StringValue) {
return new Value.BooleanValue(!value.asString().equals(value2.asString()));
}
if (value instanceof Value.DoubleValue) {
return new Value.BooleanValue(value.asDouble() != value2.asDouble());
}
if (value instanceof Value.LongValue) {
return new Value.BooleanValue(value.asLong() != value2.asLong());
}
return new Value.BooleanValue(value.asBoolean() != value2.asBoolean());
}
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.logic;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class AndOperator implements Operator {
@Override
public String getOperator() {
return "&&";
}
@Override
public int getPriority() {
return 2;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE");
}
return new Value.BooleanValue(value.asBoolean() && value2.asBoolean());
}
}

Datei anzeigen

@ -1,55 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.logic;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseAndOperator implements Operator {
@Override
public String getOperator() {
return "&";
}
@Override
public int getPriority() {
return 5;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR");
}
if (value.getClass() != value2.getClass()) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR");
}
if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) {
return new Value.BooleanValue(value.asBoolean() && value2.asBoolean());
}
return new Value.LongValue(value.asLong() & value2.asLong());
}
}

Datei anzeigen

@ -1,55 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.logic;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseOrOperator implements Operator {
@Override
public String getOperator() {
return "|";
}
@Override
public int getPriority() {
return 4;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR");
}
if (value.getClass() != value2.getClass()) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR");
}
if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) {
return new Value.BooleanValue(value.asBoolean() || value2.asBoolean());
}
return new Value.LongValue(value.asLong() | value2.asLong());
}
}

Datei anzeigen

@ -1,55 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.logic;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseXorOperator implements Operator {
@Override
public String getOperator() {
return "^";
}
@Override
public int getPriority() {
return 3;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR");
}
if (value.getClass() != value2.getClass()) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR");
}
if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) {
return new Value.BooleanValue(value.asBoolean() ^ value2.asBoolean());
}
return new Value.LongValue(value.asLong() ^ value2.asLong());
}
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.logic;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class OrOperator implements Operator {
@Override
public String getOperator() {
return "||";
}
@Override
public int getPriority() {
return 1;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE");
}
return new Value.BooleanValue(value.asBoolean() || value2.asBoolean());
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseLeftOperator implements Operator {
@Override
public String getOperator() {
return "<<";
}
@Override
public int getPriority() {
return 8;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR");
}
return new Value.LongValue(value.asLong() << value2.asLong());
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseLogicRightOperator implements Operator {
@Override
public String getOperator() {
return ">>>";
}
@Override
public int getPriority() {
return 8;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR");
}
return new Value.LongValue(value.asLong() >>> value2.asLong());
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class BitwiseRightOperator implements Operator {
@Override
public String getOperator() {
return ">>";
}
@Override
public int getPriority() {
return 8;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR");
}
return new Value.LongValue(value.asLong() >> value2.asLong());
}
}

Datei anzeigen

@ -1,49 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class DivideOperator implements Operator {
@Override
public String getOperator() {
return "/";
}
@Override
public int getPriority() {
return 10;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR");
}
if (value2.asDouble() == 0) {
return new Value.DoubleValue(Double.NaN);
}
return new Value.DoubleValue(value.asDouble() / value2.asDouble());
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class MinusOperator implements Operator {
@Override
public String getOperator() {
return "-";
}
@Override
public int getPriority() {
return 9;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR");
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.DoubleValue(value.asDouble() - value2.asDouble());
} else {
return new Value.LongValue(value.asLong() - value2.asLong());
}
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class ModuloOperator implements Operator {
@Override
public String getOperator() {
return "%";
}
@Override
public int getPriority() {
return 10;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.LongValue && value2 instanceof Value.LongValue) {
return new Value.LongValue(value.asLong() % value2.asLong());
}
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR");
}
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class MultiplyOperator implements Operator {
@Override
public String getOperator() {
return "*";
}
@Override
public int getPriority() {
return 10;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR");
}
if (value instanceof Value.StringValue) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < value2.asLong(); i++) {
sb.append(value.asString());
}
return new Value.StringValue(sb.toString());
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.DoubleValue(value.asDouble() * value2.asDouble());
} else {
return new Value.LongValue(value.asLong() * value2.asLong());
}
}
}

Datei anzeigen

@ -1,53 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class PlusOperator implements Operator {
@Override
public String getOperator() {
return "+";
}
@Override
public int getPriority() {
return 9;
}
@Override
public Value operate(Value value, Value value2) {
if (value instanceof Value.BooleanValue || value2 instanceof Value.BooleanValue) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR");
}
if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) {
return new Value.StringValue(value.asString() + value2.asString());
}
if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) {
return new Value.DoubleValue(value.asDouble() + value2.asDouble());
} else {
return new Value.LongValue(value.asLong() + value2.asLong());
}
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.expression.operator.math;
import de.steamwar.bausystem.features.script.expression.Operator;
import de.steamwar.bausystem.features.script.variables.Value;
import de.steamwar.linkage.Linked;
@Linked
public class PowerOperator implements Operator {
@Override
public String getOperator() {
return "**";
}
@Override
public int getPriority() {
return 11;
}
@Override
public Value operate(Value value, Value value2) {
if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) {
throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_POW_ERROR");
}
return new Value.DoubleValue(Math.pow(value.asDouble(), value2.asDouble()));
}
}

Datei anzeigen

@ -1,55 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class ScriptMenuBauGuiItem extends BauGuiItem {
public ScriptMenuBauGuiItem() {
super(15);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.WRITTEN_BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_ITEM_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
p.performCommand("script");
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.luaj.vm2.LuaFunction;
@AllArgsConstructor
@Getter
public class CommandRegister {
private final String name;
private final LuaFunction function;
}

Datei anzeigen

@ -0,0 +1,105 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaString;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.TwoArgFunction;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SteamWarGlobalLuaPlugin extends TwoArgFunction {
private final BiConsumer<EventType, LuaFunction> eventConsumer;
private final BiConsumer<String, LuaFunction> hotkeyConsumer;
private final Consumer<CommandRegister> commandRegisterConsumer;
@Override
public LuaValue call(LuaValue modname, LuaValue env) {
LuaValue types = tableOf();
for (EventType value : EventType.values()) {
types.set(value.name(), value.ordinal());
}
env.set("events", types);
env.set("event", new On());
env.set("command", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
LuaString command = arg1.checkstring();
LuaFunction function = arg2.checkfunction();
commandRegisterConsumer.accept(new CommandRegister(command.tojstring().toLowerCase(), function));
return NIL;
}
});
env.set("hotkey", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
LuaString key = arg1.checkstring();
LuaFunction function = arg2.checkfunction();
hotkeyConsumer.accept(key.tojstring().toLowerCase(), function);
return null;
}
});
return NIL;
}
class On extends TwoArgFunction {
@Override
public LuaValue call(LuaValue eventName, LuaValue function) {
int ord = eventName.checkint();
LuaFunction luaFunction = function.checkfunction();
int nArgs = luaFunction.narg();
if (nArgs != 1) {
return LuaValue.valueOf("Expected 1 argument, got " + nArgs);
}
eventConsumer.accept(EventType.values()[ord], luaFunction);
return LuaValue.NIL;
}
}
public enum EventType {
DoubleSwap,
PlaceBlock,
BreakBlock,
RightClick,
LeftClick,
TNTSpawn,
TNTExplode,
TNTExplodeInBuild,
SelfJoin,
SelfLeave,
DropItem,
EntityDeath
}
}

Datei anzeigen

@ -0,0 +1,150 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
import de.steamwar.inventory.SWAnvilInv;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.ThreeArgFunction;
import org.luaj.vm2.lib.TwoArgFunction;
import org.luaj.vm2.lib.VarArgFunction;
import java.util.*;
public class SteamWarLuaPlugin extends TwoArgFunction {
protected static final Map<Class<?>, List<LuaLib>> LUA_LIBS = new HashMap<>();
public static void add(LuaLib luaLib) {
LUA_LIBS.computeIfAbsent(luaLib.parent(), l -> new ArrayList<>()).add(luaLib);
}
private final Player player;
public SteamWarLuaPlugin(Player player) {
this.player = player;
}
@Override
public LuaValue call(LuaValue modname, LuaValue env) {
LuaValue materialLib = tableOf();
for (Material mat : Material.values()) {
materialLib.set(mat.name().toLowerCase(), valueOf(mat.name()));
}
initialize(env, null);
env.set("print", new Print());
env.set("input", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
String message = arg1.tojstring();
LuaFunction callback = arg2.checkfunction();
SWAnvilInv inv = new SWAnvilInv(player, message);
inv.setCallback(s -> callback.call(valueOf(s)));
inv.open();
return LuaValue.NIL;
}
});
env.set("delayed", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
long time = arg1.checklong();
LuaFunction callback = arg2.checkfunction();
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> callback.call(), time);
return LuaValue.NIL;
}
});
env.set("pos", new ThreeArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
double x = arg1.checkdouble();
double y = arg2.checkdouble();
double z = arg3.checkdouble();
Location loc = new Location(player.getWorld(), x, y, z);
return tableOf(new LuaValue[] {
valueOf("x"), valueOf(loc.getBlockX()),
valueOf("y"), valueOf(loc.getBlockY()),
valueOf("z"), valueOf(loc.getBlockZ())
});
}
});
env.set("exec", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
player.performCommand(varArgsToString(args));
return LuaValue.NIL;
}
});
env.set("collectgarbage", NIL);
env.set("dofile", NIL);
env.set("load", NIL);
env.set("loadfile", NIL);
env.set("pcall", NIL);
env.set("rawequal", NIL);
env.set("rawget", NIL);
env.set("rawlen", NIL);
env.set("rawset", NIL);
env.set("setmetatable", NIL);
env.set("xpcall", NIL);
return null;
}
public static String varArgsToString(Varargs args) {
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= args.narg(); i++) {
LuaValue arg = args.arg(i);
builder.append(arg.tojstring());
builder.append(" ");
}
return builder.toString();
}
private void initialize(LuaValue parent, Class<? extends LuaLib> clazz) {
LUA_LIBS.getOrDefault(clazz, Collections.emptyList()).forEach(luaLib -> {
LuaTable luaTable = luaLib.get(player);
parent.set(luaLib.name(), luaTable);
initialize(luaTable, luaLib.getClass());
});
}
class Print extends VarArgFunction {
@Override
public Varargs invoke(Varargs args) {
player.sendMessage(varArgsToString(args));
return LuaValue.NIL;
}
}
}

Datei anzeigen

@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua;
import org.bukkit.entity.Player;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LoadState;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.Bit32Lib;
import org.luaj.vm2.lib.PackageLib;
import org.luaj.vm2.lib.StringLib;
import org.luaj.vm2.lib.TableLib;
import org.luaj.vm2.lib.jse.JseBaseLib;
import org.luaj.vm2.lib.jse.JseMathLib;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class SteamWarPlatform {
public static Globals createClickGlobals(Player player) {
Globals globals = new Globals();
globals.load(new JseBaseLib());
globals.load(new PackageLib());
globals.load(new JseMathLib());
globals.load(new TableLib());
globals.load(new Bit32Lib());
globals.load(new StringLib());
globals.load(new SteamWarLuaPlugin(player));
LoadState.install(globals);
LuaC.install(globals);
return globals;
}
public static Globals createGlobalGlobals(Player player, BiConsumer<SteamWarGlobalLuaPlugin.EventType, LuaFunction> eventConsumer, BiConsumer<String, LuaFunction> hotkeyConsumer, Consumer<CommandRegister> commandConsumer) {
Globals globals = createClickGlobals(player);
globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, hotkeyConsumer, commandConsumer));
return globals;
}
public static Globals createGlobalParser(BiConsumer<SteamWarGlobalLuaPlugin.EventType, LuaFunction> eventConsumer, BiConsumer<String, LuaFunction> hotkeyConsumer, Consumer<CommandRegister> commandConsumer) {
Globals globals = new Globals();
globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, hotkeyConsumer, commandConsumer));
LoadState.install(globals);
LuaC.install(globals);
return globals;
}
}

Datei anzeigen

@ -0,0 +1,107 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
import org.luaj.vm2.*;
import org.luaj.vm2.lib.VarArgFunction;
import org.luaj.vm2.lib.ZeroArgFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;
public interface LuaLib {
static <T> LuaValue runGetter(Supplier<T> supplier) {
T value = supplier.get();
if (value == null) {
return LuaValue.NIL;
}
Class<?> clazz = value.getClass();
if (clazz == Integer.class || clazz == Long.class) {
return LuaValue.valueOf((int) value);
} else if (clazz == Double.class || clazz == Float.class) {
return LuaValue.valueOf((double) value);
} else if (clazz == String.class) {
return LuaValue.valueOf((String) value);
} else if (clazz == Boolean.class) {
return LuaValue.valueOf((boolean) value);
}
return LuaValue.NIL;
}
default <T> LuaFunction getter(Supplier<T> supplier) {
return new ZeroArgFunction() {
@Override
public LuaValue call() {
return runGetter(supplier);
}
};
}
default <T> LuaFunction getterAndSetter(Supplier<T> supplier, Consumer<T> consumer) {
return new GetterAndSetter<>(supplier, consumer);
}
default String varArgsToString(Varargs varargs) {
return de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin.varArgsToString(varargs);
}
default Class<? extends LuaLib> parent() {
return null;
}
String name();
LuaTable get(Player player);
@AllArgsConstructor
class GetterAndSetter<T> extends VarArgFunction {
private Supplier<T> supplier;
private Consumer consumer;
@Override
public Varargs invoke(Varargs args) {
if (args.narg() == 0) {
return runGetter(supplier);
} else {
if (args.narg() == 1) {
LuaValue luaValue = args.arg(0);
try {
if (luaValue instanceof LuaBoolean) {
consumer.accept(luaValue.toboolean());
} else if (luaValue instanceof LuaInteger) {
consumer.accept(luaValue.toint());
} else if (luaValue instanceof LuaDouble) {
consumer.accept(luaValue.todouble());
} else if (luaValue instanceof LuaString) {
consumer.accept(luaValue.toString());
} else {
throw new LuaError("Invalid lua type: " + luaValue.typename());
}
} catch (Throwable throwable) {
throw new LuaError("Error in '" + checkfunction().name() + "' " + throwable.getMessage());
}
}
return NIL;
}
}
}
}

Datei anzeigen

@ -0,0 +1,85 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.VarArgFunction;
@Linked
public class PlayerLib implements LuaLib {
public String name() {
return "player";
}
public LuaTable get(Player player) {
LuaTable table = new LuaTable();
table.set("name", getter(player::getName));
table.set("chat", new Print(player));
table.set("actionbar", new SendActionbar(player));
table.set("x", getterAndSetter(() -> player.getLocation().getX(), player.getLocation()::setX));
table.set("y", getterAndSetter(() -> player.getLocation().getY(), player.getLocation()::setY));
table.set("z", getterAndSetter(() -> player.getLocation().getZ(), player.getLocation()::setZ));
table.set("yaw", getterAndSetter(() -> player.getLocation().getYaw(), player.getLocation()::setYaw));
table.set("pitch", getterAndSetter(() -> player.getLocation().getPitch(), player.getLocation()::setPitch));
table.set("sneaking", getter(player::isSneaking));
table.set("sprinting", getter(player::isSprinting));
table.set("slot", getterAndSetter(() -> player.getInventory().getHeldItemSlot(), player.getInventory()::setHeldItemSlot));
table.set("item", getter(() -> player.getInventory().getItemInMainHand().getType().name()));
table.set("offHandItem", getter(() -> player.getInventory().getItemInOffHand().getType().name()));
return table;
}
private class Print extends VarArgFunction {
private final Player player;
public Print(Player player) {
this.player = player;
}
@Override
public Varargs invoke(Varargs args) {
player.sendMessage(varArgsToString(args));
return LuaValue.NIL;
}
}
private class SendActionbar extends VarArgFunction {
private final Player player;
public SendActionbar(Player player) {
this.player = player;
}
@Override
public Varargs invoke(Varargs args) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args)));
return LuaValue.NIL;
}
}
}

Datei anzeigen

@ -0,0 +1,77 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.features.loader.Loader;
import de.steamwar.bausystem.features.tracer.record.ActiveTracer;
import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder;
import de.steamwar.bausystem.features.tracer.record.Recorder;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.FireMode;
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
@Linked
public class RegionLib implements LuaLib {
@Override
public String name() {
return "region";
}
@Override
public LuaTable get(Player player) {
LuaTable table = LuaValue.tableOf();
table.set("name", getter(() -> Region.getRegion(player.getLocation()).getName()));
table.set("type", getter(() -> Region.getRegion(player.getLocation()).getPrototype().getName()));
LuaValue tntLib = LuaValue.tableOf();
tntLib.set("mode", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class).name()));
tntLib.set("enabled", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY));
tntLib.set("onlyTb", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB));
table.set("tnt", tntLib);
table.set("fire", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW));
table.set("freeze", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE));
table.set("protect", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE));
LuaValue traceLib = LuaValue.tableOf();
traceLib.set("active", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof ActiveTracer));
traceLib.set("auto", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof AutoTraceRecorder));
traceLib.set("status", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptState()));
traceLib.set("time", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptTime()));
table.set("trace", traceLib);
Loader loader = Loader.getLoader(player);
table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name()));
return table;
}
}

Datei anzeigen

@ -0,0 +1,84 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.core.TPSWatcher;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaString;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction;
import org.luaj.vm2.lib.TwoArgFunction;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@Linked
public class ServerLib implements LuaLib {
@Override
public String name() {
return "server";
}
@Override
public LuaTable get(Player player) {
LuaTable serverLib = LuaValue.tableOf();
serverLib.set("time", getter(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime())));
serverLib.set("ticks", getter(TPSUtils.currentTick));
serverLib.set("getBlockAt", new OneArgFunction() {
@Override
public LuaValue call(LuaValue arg1) {
LuaTable pos = arg1.checktable();
return valueOf(player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).getType().name());
}
});
serverLib.set("setBlockAt", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
LuaTable pos = arg1.checktable();
LuaString material = arg2.checkstring();
Material mat = SWItem.getMaterial(material.tojstring());
if (mat == null) {
return NIL;
}
player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).setType(mat);
return NIL;
}
});
LuaValue tpsLib = LuaValue.tableOf();
tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND)));
tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS)));
tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)));
tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)));
tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)));
tpsLib.set("current", getter(TPSWatcher::getTPS));
tpsLib.set("limit", getter(TPSLimitUtils::getCurrentTPSLimit));
serverLib.set("tps", tpsLib);
return serverLib;
}
}

Datei anzeigen

@ -0,0 +1,71 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.script.lua.libs;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.math.BlockVector3;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
@Linked
public class WorldEditLib implements LuaLib {
@Override
public String name() {
return "_worldedit";
}
@Override
public LuaTable get(Player player) {
LuaTable table = new LuaTable();
table.set("selection", getterAndSetter(() -> {
LuaTable selection = new LuaTable();
selection.set("min", posFromVec(WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getSelectionWorld().getMinimumPoint()));
selection.set("max", posFromVec(WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getSelectionWorld().getMaximumPoint()));
return selection;
}, o -> {
LuaTable selection = o.checktable();
if(selection.length() != 2) {
throw new IllegalArgumentException("selection must have exactly 2 elements");
}
Point one = vecFromPos(selection.get(1).checktable());
Point two = vecFromPos(selection.get(2).checktable());
FlatteningWrapper.impl.setSelection(player, one, two);
}));
return table;
}
public static LuaTable posFromVec(BlockVector3 vec) {
LuaTable table = new LuaTable();
table.set("x", vec.getBlockX());
table.set("y", vec.getBlockY());
table.set("z", vec.getBlockZ());
return table;
}
public static Point vecFromPos(LuaTable table) {
return new Point(table.get("x").checkint(), table.get("y").checkint(), table.get("z").checkint());
}
}

Datei anzeigen

@ -1,315 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.Loader;
import de.steamwar.bausystem.features.tpslimit.FreezeUtils;
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tracer.record.ActiveTracer;
import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder;
import de.steamwar.bausystem.features.tracer.record.Recorder;
import de.steamwar.bausystem.features.tracer.record.TraceRecorder;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.FireMode;
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.core.TPSWatcher;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
@UtilityClass
public class Constants {
private final Map<String, Function<Player, Value>> CONSTANTS = new HashMap<>();
private static class ConstantDoubleValue extends Value.DoubleValue {
private Supplier<Double> doubleSupplier;
public ConstantDoubleValue(Supplier<Double> doubleSupplier) {
super(doubleSupplier.get());
this.doubleSupplier = doubleSupplier;
}
@Override
public long asLong() {
value = doubleSupplier.get();
return super.asLong();
}
@Override
public double asDouble() {
value = doubleSupplier.get();
return super.asDouble();
}
@Override
public boolean asBoolean() {
value = doubleSupplier.get();
return super.asBoolean();
}
@Override
public String asString() {
value = doubleSupplier.get();
return super.asString();
}
}
private static class ConstantLongValue extends Value.LongValue {
private Supplier<Long> longSupplier;
public ConstantLongValue(Supplier<Long> longSupplier) {
super(longSupplier.get());
this.longSupplier = longSupplier;
}
@Override
public long asLong() {
value = longSupplier.get();
return super.asLong();
}
@Override
public double asDouble() {
value = longSupplier.get();
return super.asDouble();
}
@Override
public boolean asBoolean() {
value = longSupplier.get();
return super.asBoolean();
}
@Override
public String asString() {
value = longSupplier.get();
return super.asString();
}
}
private static class ConstantBooleanValue extends Value.BooleanValue {
private Supplier<Boolean> booleanSupplier;
public ConstantBooleanValue(Supplier<Boolean> booleanSupplier) {
super(booleanSupplier.get());
this.booleanSupplier = booleanSupplier;
}
@Override
public long asLong() {
value = booleanSupplier.get();
return super.asLong();
}
@Override
public double asDouble() {
value = booleanSupplier.get();
return super.asDouble();
}
@Override
public boolean asBoolean() {
value = booleanSupplier.get();
return super.asBoolean();
}
@Override
public String asString() {
value = booleanSupplier.get();
return super.asString();
}
}
private static class ConstantStringValue extends Value.StringValue {
private Supplier<String> stringSupplier;
public ConstantStringValue(Supplier<String> stringSupplier) {
super(stringSupplier.get());
this.stringSupplier = stringSupplier;
}
@Override
public long asLong() {
value = stringSupplier.get();
return super.asLong();
}
@Override
public double asDouble() {
value = stringSupplier.get();
return super.asDouble();
}
@Override
public boolean asBoolean() {
value = stringSupplier.get();
return super.asBoolean();
}
@Override
public String asString() {
value = stringSupplier.get();
return super.asString();
}
}
static {
CONSTANTS.put("trace", player -> {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return new ConstantBooleanValue(() -> false);
}
return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof ActiveTracer);
});
CONSTANTS.put("autotrace", player -> {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return new ConstantBooleanValue(() -> false);
}
return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder);
});
CONSTANTS.put("trace_status", player -> {
TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation()));
return new ConstantStringValue(recorder::scriptState);
});
CONSTANTS.put("trace_time", player -> {
TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation()));
return new ConstantLongValue(recorder::scriptTime);
});
CONSTANTS.put("tnt", player -> {
return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY);
});
CONSTANTS.put("tnt_onlytb", player -> {
return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB);
});
CONSTANTS.put("fire", player -> {
return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW);
});
CONSTANTS.put("freeze", player -> {
return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE);
});
CONSTANTS.put("protect", player -> {
return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE);
});
CONSTANTS.put("x", player -> {
return new ConstantDoubleValue(() -> player.getLocation().getX());
});
CONSTANTS.put("y", player -> {
return new ConstantDoubleValue(() -> player.getLocation().getY());
});
CONSTANTS.put("z", player -> {
return new ConstantDoubleValue(() -> player.getLocation().getZ());
});
CONSTANTS.put("name", player -> {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
return new ConstantStringValue(user::getUserName);
});
CONSTANTS.put("sneaking", player -> {
return new ConstantBooleanValue(player::isSneaking);
});
CONSTANTS.put("sprinting", player -> {
return new ConstantBooleanValue(player::isSprinting);
});
CONSTANTS.put("slot", player -> {
return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot());
});
CONSTANTS.put("slotmaterial", player -> {
return new ConstantStringValue(() -> player.getInventory().getItemInMainHand().getType().name());
});
CONSTANTS.put("offhandmaterial", player -> {
return new ConstantStringValue(() -> player.getInventory().getItemInOffHand().getType().name());
});
CONSTANTS.put("materialname", player -> {
return new ConstantStringValue(() -> {
ItemMeta itemMeta = player.getInventory().getItemInMainHand().getItemMeta();
if (itemMeta == null) {
return "";
}
return itemMeta.getDisplayName();
});
});
CONSTANTS.put("offmaterialname", player -> {
return new ConstantStringValue(() -> {
ItemMeta itemMeta = player.getInventory().getItemInOffHand().getItemMeta();
if (itemMeta == null) {
return "";
}
return itemMeta.getDisplayName();
});
});
CONSTANTS.put("region_type", player -> {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return new ConstantStringValue(() -> "global");
}
return new ConstantStringValue(() -> region.getPrototype().getDisplayName().replace(' ', '_').toLowerCase());
});
CONSTANTS.put("region_name", player -> {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return new ConstantStringValue(() -> "Global");
}
return new ConstantStringValue(() -> region.getPrototype().getDisplayName());
});
CONSTANTS.put("tps", player -> {
return new ConstantDoubleValue(() -> {
if (FreezeUtils.isFrozen()) return 0.0;
return TPSWatcher.getTPS();
});
});
CONSTANTS.put("tps_limit", player -> {
return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit);
});
CONSTANTS.put("ticks", player -> {
return new ConstantLongValue(TPSUtils.currentTick);
});
CONSTANTS.put("time", player -> {
return new ConstantStringValue(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime()));
});
CONSTANTS.put("loader_status", player -> {
Loader loader = Loader.getLoader(player);
if (loader == null) {
return new ConstantStringValue(() -> "OFF");
}
return new ConstantStringValue(() -> loader.getStage().name());
});
}
public Set<String> allVariables() {
return CONSTANTS.keySet();
}
public boolean isConstant(String variableName) {
return CONSTANTS.containsKey(variableName);
}
public Value getConstant(String variableName, Player player) {
return CONSTANTS.get(variableName).apply(player);
}
}

Datei anzeigen

@ -1,42 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Context {
private Map<String, Value> variables = new HashMap<>();
public void putValue(String variableName, Value value) {
if (variables.containsKey(variableName)) {
if (variables.get(variableName).type().equals(value.type())) {
variables.get(variableName).fromValue(value);
} else {
variables.put(variableName, value);
}
} else {
variables.put(variableName, value);
}
}
public void removeValue(String variableName) {
variables.remove(variableName);
}
public boolean hasValue(String variableName) {
return variables.containsKey(variableName);
}
public Value getValue(String variableName) {
return variables.get(variableName);
}
public Set<String> allVariables() {
return variables.keySet();
}
public Set<Map.Entry<String, Value>> entrySet() {
return variables.entrySet();
}
}

Datei anzeigen

@ -1,188 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
import lombok.AllArgsConstructor;
import lombok.ToString;
public interface Value {
static Value parse(String varValue) {
try {
return new Value.LongValue(Long.parseLong(varValue));
} catch (NumberFormatException ne) {
try {
return new Value.DoubleValue(Double.parseDouble(varValue));
} catch (NumberFormatException e) {
if (varValue.equalsIgnoreCase("true") || varValue.equalsIgnoreCase("false")) {
return new Value.BooleanValue(varValue.equalsIgnoreCase("true"));
} else {
return new Value.StringValue(varValue);
}
}
}
}
String type();
long asLong();
double asDouble();
boolean asBoolean();
String asString();
void fromValue(Value value);
@AllArgsConstructor
@ToString
class DoubleValue implements Value {
protected double value;
@Override
public String type() {
return "floating_number";
}
@Override
public long asLong() {
return Math.round(value);
}
@Override
public double asDouble() {
return value;
}
@Override
public boolean asBoolean() {
return value != 0;
}
@Override
public String asString() {
return value + "";
}
@Override
public void fromValue(Value value) {
this.value = value.asDouble();
}
}
@AllArgsConstructor
@ToString
class LongValue implements Value {
protected long value;
@Override
public String type() {
return "number";
}
@Override
public long asLong() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public boolean asBoolean() {
return value != 0;
}
@Override
public String asString() {
return value + "";
}
@Override
public void fromValue(Value value) {
this.value = value.asLong();
}
}
@AllArgsConstructor
@ToString
class BooleanValue implements Value {
protected boolean value;
@Override
public String type() {
return "boolean";
}
@Override
public long asLong() {
return value ? 1 : 0;
}
@Override
public double asDouble() {
return value ? 1 : 0;
}
@Override
public boolean asBoolean() {
return value;
}
@Override
public String asString() {
return value + "";
}
@Override
public void fromValue(Value value) {
this.value = value.asBoolean();
}
}
@AllArgsConstructor
@ToString
class StringValue implements Value {
protected String value;
@Override
public String type() {
return "text";
}
@Override
public long asLong() {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
return 0;
}
}
@Override
public double asDouble() {
try {
return Double.parseDouble(value);
} catch (NumberFormatException e) {
return 0;
}
}
@Override
public boolean asBoolean() {
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes");
}
@Override
public String asString() {
return value;
}
@Override
public void fromValue(Value value) {
this.value = value.asString();
}
}
}

309
SCRIPT.md Normale Datei
Datei anzeigen

@ -0,0 +1,309 @@
# SteamWar.de - Script System
---
<!-- TOC -->
* [SteamWar.de - Script System](#steamwarde---script-system)
* [Einleitung](#einleitung)
* [Basis-Apis](#basis-apis)
* [SteamWar.de-Api](#steamwarde-api)
* [player](#player)
* [region](#region)
* [tnt](#tnt)
* [trace](#trace)
* [server](#server)
* [tps](#tps)
* [SteamWar.de-Global-Api](#steamwarde-global-api)
* [Hotkeys](#hotkeys)
* [Eventtypen](#eventtypen)
* [BlockEvent](#blockevent)
* [InteractEvent](#interactevent)
* [Position](#position)
* [Instabile APIs](#instabile-apis)
* [_worldedit](#worldedit)
* [Beispiele](#beispiele)
* [Hello, World!](#hello-world)
* [Code](#code)
* [Ausgabe](#ausgabe)
* [BauGUI on DoubleSwap](#baugui-on-doubleswap)
* [Code](#code-1)
* [SL Command](#sl-command)
* [Code](#code-2)
* [Paste Hotkey](#paste-hotkey)
* [Code](#code-3)
<!-- TOC -->
## Einleitung
Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html).
Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden.
# Basis-Apis
Es werden folgende Standard-Apis zur Verfügung gestellt:
- [`math`](https://www.lua.org/manual/5.4/manual.html#6.7)
- [`string`](https://www.lua.org/manual/5.4/manual.html#6.4)
- [`table`](https://www.lua.org/manual/5.4/manual.html#6.6)
- [`bit32`](https://www.lua.org/manual/5.2/manual.html#6.7)
# SteamWar.de-Api
APIs, die mit einem `_` beginnen sind noch nicht stabil und können sich jederzeit ändern.
Sie sollten daher nicht verwendet werden, da sie sich noch in der Entwicklung befinden.
Diese können auch undokumentierte Funktionen enthalten, die nicht in der Dokumentation aufgeführt sind.
In den Scripten gibt es dazu noch folgende globale Variablen:
- [`player`](#player)
- [`region`](#region)
- [`server`](#server)
- `_worldedit`
Ohne eine Kategorie sind folgende Funktionen verfügbar, die nicht allgemein sind:
| Name | Signature | Beschreibung |
|-----------|----------------------------------|-------------------------------------------------------------------------------------------------------------------|
| `print` | print(String...) | @see message(String...) |
| `input` | input(String, Function\<String>) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser |
| `delayed` | delayed(Number, Function\<Void>) | Wartet die angegebene Anzahl an Ticks und führt danach die zugehörige Funktion aus |
| `pos` | pos(Number, Number, Number) | Erstellt aus drei Zahlen eine Position-Table. Die Koordinaten sind unter den Namen `x`, `y` und `z` abgespeichert |
| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus |
### player
Das `player`-Modul stellt Funktionen zur Verfügung, die den Spieler betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|---------------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| `name` | name(): String | Gibt den `displayName` des Spielers zurück |
| `chat` | chat(String...) | Sendet den Text in den Chat des Spielers |
| `actionbar` | actionbar(String...) | Sendet den Text in die ActionBar des Spielers |
| `x` | x(Number), x(): Number | Setzt oder gibt die X-Koordinate des Spielers |
| `y` | y(Number), y(): Number | Setzt oder gibt die Y-Koordinate des Spielers |
| `z` | z(Number), z(): Number | Setzt oder gibt die Z-Koordinate des Spielers |
| `yaw` | yaw(Number), yaw(): Number | Setzt oder gibt die Gierung des Spielers |
| `pitch` | pitch(Number), pitch(): Number | Setzt oder gibt die Steigung des Spielers |
| `sneaking` | sneaking(): Boolean | Wahr, wenn der Spieler am Sneaken ist |
| `sprinting` | sprinting(): Boolean | Wahr, wenn der Spieler am Sprinten ist |
| `slot` | slot(Number), slot(): Number | Setzt oder gibt den Slot des gehaltenden Items des Spielers [(Wiki)](https://minecraft.fandom.com/wiki/Slot#Java_Edition) |
| `item` | item(): String | Gibt den Itemtyp der Main-Hand zurück |
| `offHandItem` | offHandItem(): String | Gibt den Itemtyp der Off-Hand zurück |
### region
Das `region`-Modul stellt Funktion zur Verfügung, die die Region des Spielers betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|-----------|--------------------|------------------------------------------------------------------------------------------------------------|
| `name` | name(): String | Gibt den Regionsnamen |
| `type` | type(): String | Gibt den Regionstyp |
| `fire` | fire(): Boolean | Gibt den Fire-Modus der Region zurück |
| `freeze` | freeze(): Boolean | Gibt den Freeze-Modus der Region zurück |
| `protect` | protect(): Boolean | Gibt den Protect-Modus der Region zurück |
| `loader` | loader(): String | Gibt den Status des Loaders des Spielers zurück, die Werte sind: `OFF`, `SETUP`, `RUNNING`, `PAUSE`, `END` |
Es gibt folgende weitere Module:
| Name | Beschreibung |
|---------|-----------------|
| `tnt` | [tnt](#tnt) |
| `trace` | [trace](#trace) |
#### tnt
Das `tnt`-Modul stellt Funktionen zur Verfügung, die den TNT-Modus in der Region des Spielers betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|-----------|--------------------|-------------------------------------------------------------------------------------|
| `mode` | mode(): String | Gibt den Aktuellen TNT-Modus zurück, die werte sind: `ALLOW`, `DENY` oder `ONLY_TB` |
| `enabled` | enabled(): Boolean | Gibt zurück, ob der TNT-Modus in der Region des Spielers aktiviert ist oder nicht |
| `onlyTb` | onlyTb(): Boolean | Gibt zurück, ob der TNT-Modus auf Only-Tb ist |
#### trace
Das `trace`-Modul stellt Funktionen zur Verfügung, die den Status des Tracers der Region betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|----------|-------------------|--------------------------------------------------------------------------------|
| `active` | active(): Boolean | Gibt zurück, ob der Tracer in der Region des Spielers aktiviert ist oder nicht |
| `auto` | auto(): Boolean | Gibt zurück, ob der Tracer in der Region ein Auto-Tracer ist |
| `status` | status(): String | Gibt den Status des Tracers zurück |
| `time` | time(): String | Gibt die Zeit des Tracers zurück |
## server
Das `server`-Modul stellt Funktionen zur Verfügung, die den Server betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|--------------|-------------------------|---------------------------------------------------------------------|
| `time` | time(): String | Gibt die aktuelle Zeit im Format `HH:mm:ss` zurück |
| `ticks` | ticks(): Number | Gibt die Ticks seit start des Serverstarts zurück |
| `getBlockAt` | getBlockAt(Pos): String | Gibt das Material an der Position zurück |
| `setBlockAt` | setBlockAt(Pos, String) | Setzt das Material an der angegebenen Stelle (z.B. Stein = `STONE`) |
Es gibt folgende weitere Module:
| Name | Beschreibung |
|-------|--------------|
| `tps` | [tps](#tps) |
#### tps
Das `tps`-Modul stellt Funktionen zur Verfügung, die die TPS des Servers betreffen.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|--------------|----------------------|-------------------------------------------------------------------|
| `current` | current(): Number | Gibt die aktuelle TPS zurück (Das selbe wie `oneSecound()`) |
| `oneSecond` | oneSecond(): Number | Gibt die durchschnittliche TPS über die letzte Sekunde zurück |
| `tenSecond` | tenSecond(): Number | Gibt die durchschnittliche TPS über die letzte 10 Sekunden zurück |
| `oneMinute` | oneMinute(): Number | Gibt die durchschnittliche TPS über die letzte Minute zurück |
| `fiveMinute` | fiveMinute(): Number | Gibt die durchschnittliche TPS über die letzte 5 Minuten zurück |
| `tenMinute` | tenMinute(): Number | Gibt die durchschnittliche TPS über die letzte 10 Minuten zurück |
| `limit` | limit(): Number | Gibt das TPS-Limit zurück |
# SteamWar.de-Global-Api
Mit `/script` kann man Script-Bücher global abspeichern. Diese haben dann zugrif auf die `global`-Api.
Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Hotkeys mit einem Script zu reagieren.
Es gibt folgende Funktionen:
| Name | Signature | Beschreibung |
|-----------|-----------------------------------|-----------------------------------------------------------------------------|
| `event` | event(EventType, Function(Any)) | Registriere einen Event Listener |
| `command` | command(String, Function(Args)) | Registriere einen Befehl |
| `hotkey` | hotkey(String, Function(Boolean)) | Registriere einen Hotkey, the function gets a boolean if the key is pressed |
Es gibt folgende Variablen:
| Name | Beschreibung |
|----------|----------------------------------|
| `events` | Siehe: [Event Type](#eventtypen) |
## Hotkeys
Hotkeys werden im folgenden Format angegeben: `MODIFIER+KEY`. Bei den Hotkey erstellung ist die Großschreibung egal. Es gibt folgende Modifier:
- `ctrl`
- `shift`
- `alt`
- `meta`
Es können auch mehrere Modifier angegeben werden, z.B. `ctrl+shift+alt+c`. Die Reihenfolge der Modifier und des Keys ist egal.
## Eventtypen
Einige Events sind auch abbrechbar, dazu muss die Funktion `setCancelled()` aufgerufen werden.
| Name | Wenn | Parameter | Abbrechbar |
|---------------------|-----------------------------------------------------|---------------------------------|------------|
| `DoubleSwap` | Beim Doppelten Drücken der Swap-Hands taste | NIL | false |
| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) | true |
| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) | true |
| `RightClick` | Beim Rechtsklick | [InteractEvent](#interactevent) | true |
| `LeftClick` | Beim Linksklick | [InteractEvent](#interactevent) | true |
| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL | false |
| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) | true |
| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) | true |
| `SelfJoin` | Wenn man selbst den Server betritt | NIL | false |
| `SelfLeave` | Wenn man den Server verlässt | NIL | false |
| `DropItem` | Wenn man ein Item droppt | (type: Material) | true |
| `EntityDeath` | Wenn ein Entity stirbt | (type: Entity Type) | false |
### BlockEvent
Das übergebene Objekt an den Handler hat folgende Variablen:
| Name | Beschreibung |
|--------|-----------------------------|
| `x` | Die X-Koordinate des Blocks |
| `y` | Die Y-Koordinate des Blocks |
| `z` | Die Z-Koordinate des Blocks |
| `type` | Das Material des Blocks |
### InteractEvent
Das übergebene Objekt an den Handler hat folgende Variablen:
| Name | Beschreibung |
|------------|-------------------------------------------------------------------------------------------------------------------------------|
| `action` | Die Action die ausgeführt wurde, Mögliche Werte: `RIGHT_CLICK_BLOCK`, `RIGHT_CLICK_AIR`, `LEFT_CLICK_BLOCK`, `LEFT_CLICK_AIR` |
| `hand` | Die Hand die zum ausführen genutzt wird, Mögliche Werte: `HAND`, `OFF_HAND` |
| `block` | Der Typ des Items mit dem geklickt wurde |
| `hasBlock` | Wahr, wenn auf einen Block geklickt wurde |
Wenn `hasBlock` wahr ist, gibt es folgende Variablen:
| Name | Beschreibung |
|-------------|-----------------------------------------|
| `blockX` | Die X-Koordinate des Blocks |
| `blockY` | Die Y-Koordinate des Blocks |
| `blockZ` | Die Z-Koordinate des Blocks |
| `blockFace` | Die Seite des Blocks die geklickt wurde |
### Position
Die Position ist ein Objekt mit folgenden Variablen:
| Name | Beschreibung |
|------|------------------|
| `x` | Die X-Koordinate |
| `y` | Die Y-Koordinate |
| `z` | Die Z-Koordinate |
# Instabile APIs
Hier sind einige APIs aufgelistet, die nicht stabil sind und sich jederzeit ändern können.
## _worldedit
| Name | Signatur | Beschreibung |
|-------------|-----------------------------------------------------------|-----------------------------------|
| `selection` | selection(Liste\<Pos>), selection(): {min: Pos, max: Pos} | Die aktuelle auswahl des Spielers |
# Beispiele
## Hello, World!
Ein einfaches Hello, World!-Script.
#### Code
```lua
print("Hello, World!")
```
#### Ausgabe
```
Hello, World!
```
## BauGUI on DoubleSwap
Das Standardskript für das Öffnen des BauGUIs
#### Code
```lua
function handler(event)
exec("gui")
end
event(events.FF, handler)
```
## SL Command
Ein einfacher Command Redefiner.
#### Code
```lua
function handler(args)
exec("stoplag")
end
command("sl", handler)
```
## Paste Hotkey
Ein Hotkey zum Pasten des Clipboard-Inhalts.
#### Code
```lua
function handler(pressed)
if pressed then
exec("/paste -o")
end
end
hotkey("ctrl+v", handler)
```