diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java
new file mode 100644
index 00000000..79c02770
--- /dev/null
+++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java
@@ -0,0 +1,21 @@
+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 + ");");
+ }
+}
diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java
deleted file mode 100644
index 8a1916a8..00000000
--- a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java
+++ /dev/null
@@ -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 .
- */
-
-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 + ");");
- }
-}
diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java
deleted file mode 100644
index 97c63276..00000000
--- a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java
+++ /dev/null
@@ -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 .
- */
-
-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 + ");");
- }
-}
diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle
index 1052e30a..2e9a8d6c 100644
--- a/BauSystem_Main/build.gradle
+++ b/BauSystem_Main/build.gradle
@@ -64,4 +64,6 @@ dependencies {
annotationProcessor swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
+
+ implementation 'org.luaj:luaj-jse:3.0.1'
}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java
index 08309eb6..d65a8750 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java
@@ -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 blockList, Location location, EventType eventType, Event event) {
+ private void explode(List 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
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java
deleted file mode 100644
index 0c4e50af..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java
+++ /dev/null
@@ -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 .
- */
-
-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> 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) key).get().split(" ");
- List 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) key).get().split(" ");
- List 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) key).get().split(" ");
- List 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> 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 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 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 variables, Consumer echoConsumer) {
- Map valueMap = new HashMap<>();
- for (Map.Entry entry : variables.entrySet()) {
- valueMap.put(entry.getKey(), new Value.StringValue(entry.getValue()));
- }
- List 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 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 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 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);
- }
- }
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java
index d9bed371..6952d796 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java
@@ -1,163 +1,10 @@
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 {
public ScriptCommand() {
super("script");
}
-
- @LinkedInstance
- public CustomScriptManager customScriptManager = null;
-
- private List loreBuilder(Player p, String... strings) {
- List 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> 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 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> 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 lore) {
- return new SWItem(material, BauSystem.MESSAGE.parse(name, p), lore, false, clickType -> {
- });
- }
-
- private void addConstantItem(List> swItems, Player p, Material material, String name, String lore) {
- List 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> swItems, Player p) {
- List specialCommands = new ArrayList<>(SPECIAL_COMMANDS);
- specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName()));
- specialCommands.forEach(specialCommand -> {
- List 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 split(String s) {
- List 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);
- }
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java
deleted file mode 100644
index 25b29147..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java
+++ /dev/null
@@ -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 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 commands = new ArrayList<>();
-
- @Getter
- public final Map jumpPoints = new HashMap<>();
-
- @Getter
- private final LinkedList returnStack = new LinkedList<>();
-
- @Getter
- @Setter
- private int index = 0;
-
- @Getter
- private final Consumer echoConsumer;
-
- public ScriptExecutor(BookMeta bookMeta, Player player, Consumer echoConsumer) {
- this(bookMeta, player, new HashMap<>(), echoConsumer);
- }
-
- public ScriptExecutor(List pages, Player player, Consumer echoConsumer) {
- this(pages, player, new HashMap<>(), echoConsumer);
- }
-
- public ScriptExecutor(BookMeta bookMeta, Player player, Map localVariables, Consumer 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 pages, Player player, Map localVariables, Consumer 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 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";
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java
index ef9abe06..f2b5852c 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java
@@ -1,6 +1,5 @@
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;
@@ -9,22 +8,19 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
@Linked
public class ScriptListener implements Listener {
- private static final Map GLOBAL_CONTEXT = new HashMap<>();
-
- private Set playerSet = new HashSet<>();
+ private final Set playerSet = new HashSet<>();
@EventHandler(priority = EventPriority.HIGH)
public void onLeftClick(PlayerInteractEvent event) {
@@ -44,20 +40,22 @@ 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 onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
+ ItemStack item = event.getOffHandItem();
+ if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) {
+ return;
+ }
+
+ event.setCancelled(true);
+ ScriptRunner.createGlobalScript(Collections.singletonList(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null)), event.getPlayer());
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java
new file mode 100644
index 00000000..8c4ce348
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java
@@ -0,0 +1,75 @@
+package de.steamwar.bausystem.features.script;
+
+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 org.bukkit.entity.Player;
+import org.luaj.vm2.Globals;
+import org.luaj.vm2.LuaFunction;
+import org.luaj.vm2.LuaValue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ScriptRunner {
+
+ // Script Table
+ // User
+ // Key -> bau-script-
+ // Value ->
+
+ private static final Map>> EVENT_MAP = new HashMap<>();
+ private static final Map> 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) {
+ player.sendMessage("§cFehler beim Ausführen des Scripts: " + e.getMessage());
+ }
+ }
+
+ public static void createGlobalScript(List scripts, Player player) {
+ EVENT_MAP.remove(player);
+ Globals globals = SteamWarPlatform.createGlobalGlobals(player,
+ (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction),
+ commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister));
+
+ for (String script : scripts) {
+ globals.load(script).call();
+ }
+ }
+
+ public static void remove(Player player) {
+ EVENT_MAP.remove(player);
+ }
+
+ public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) {
+ Map> stringListMap = EVENT_MAP.get(player);
+ if (stringListMap == null) {
+ return;
+ }
+
+ List luaFunctions = stringListMap.get(event);
+ if (luaFunctions == null) {
+ return;
+ }
+
+ for (LuaFunction luaFunction : luaFunctions) {
+ luaFunction.call(eventValue);
+ }
+ }
+
+ public static void callCommand(Player player, String command, LuaValue args) {
+ CommandRegister commandRegister = COMMAND_MAP.get(player).get(command.toLowerCase());
+ if (commandRegister == null) {
+ return;
+ }
+
+ commandRegister.getFunction().call(args);
+ }
+}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java
deleted file mode 100644
index 8c9763c3..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java
+++ /dev/null
@@ -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 .
- */
-
-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);
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java
deleted file mode 100644
index 3cb32f9b..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java
+++ /dev/null
@@ -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,
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java
deleted file mode 100644
index 4cb22c65..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java
deleted file mode 100644
index c274d252..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java
deleted file mode 100644
index 47d92f25..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java
deleted file mode 100644
index 10ff4ab1..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java
deleted file mode 100644
index 0d9e6492..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java
deleted file mode 100644
index 3cb0f025..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java
deleted file mode 100644
index da87c9f9..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java
deleted file mode 100644
index ce5d0730..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java
deleted file mode 100644
index 2af5d261..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java
deleted file mode 100644
index da83635c..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java
deleted file mode 100644
index c5c99240..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java
deleted file mode 100644
index 4ecb4237..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java
deleted file mode 100644
index 00dbf597..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java
deleted file mode 100644
index 002fd3c5..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java
deleted file mode 100644
index a7a5716f..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java
deleted file mode 100644
index 8624cae1..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java
deleted file mode 100644
index 850a6642..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java
deleted file mode 100644
index a99c0bb6..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java
deleted file mode 100644
index ae3f33a7..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java
deleted file mode 100644
index 06e9e7b1..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java
deleted file mode 100644
index 76230f87..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java
deleted file mode 100644
index 6cda1236..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java
deleted file mode 100644
index e5511e98..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java
deleted file mode 100644
index 1411c708..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java
+++ /dev/null
@@ -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 .
- */
-
-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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java
deleted file mode 100644
index 49befa41..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java
+++ /dev/null
@@ -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 .
- */
-
-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);
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java
deleted file mode 100644
index 17693f8a..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java
+++ /dev/null
@@ -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 .
- */
-
-package de.steamwar.bausystem.features.script.custom;
-
-public interface Script {
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java
deleted file mode 100644
index 4c2e7ddf..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java
+++ /dev/null
@@ -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 .
- */
-
-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());
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java
deleted file mode 100644
index b0a7d386..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java
+++ /dev/null
@@ -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 .
- */
-
-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 check(String[] args, String[] command) {
- if (args.length < command.length) {
- return null;
- }
-
- if (!args[0].equals(command[0])) {
- return null;
- }
-
- Map arguments = new HashMap<>();
- if (!check(arguments, args, command, 0, 0)) {
- return null;
- }
- return arguments;
- }
-
- default boolean check(Map 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);
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java
deleted file mode 100644
index 34cfc738..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java
+++ /dev/null
@@ -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 .
- */
-
-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 arguments = check(args, command);
- if (arguments == null) {
- return false;
- }
-
- e.setCancelled(true);
- new ScriptExecutor(bookMeta, e.getPlayer(), arguments, null);
- return true;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java
deleted file mode 100644
index 5583f360..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java
+++ /dev/null
@@ -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 .
- */
-
-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 pages;
- public final String[] args;
-
- @Override
- public String[] command() {
- return args;
- }
-
- public boolean execute(String[] command, PlayerCommandPreprocessEvent e) {
- Map 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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java
deleted file mode 100644
index ec4bebd7..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java
+++ /dev/null
@@ -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 .
- */
-
-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 variables, Consumer echoConsumer);
-
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java
deleted file mode 100644
index 3a6d471d..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java
+++ /dev/null
@@ -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 .
- */
-
-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 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 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 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 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 valueMap = new HashMap<>();
- addXYZ(valueMap, event.getLocation());
- return valueMap;
- }),
- TNTExplodeInBuild(EntityExplodeEvent.class, event -> {
- Map valueMap = new HashMap<>();
- addXYZ(valueMap, event.getLocation());
- return valueMap;
- }),
- SelfJoin(PlayerJoinEvent.class, event -> {
- Map valueMap = new HashMap<>();
- addXYZ(valueMap, event.getPlayer().getLocation());
- return valueMap;
- }),
- SelfLeave(PlayerQuitEvent.class, event -> {
- Map valueMap = new HashMap<>();
- addXYZ(valueMap, event.getPlayer().getLocation());
- return valueMap;
- }),
- DropItem(PlayerDropItemEvent.class, event -> {
- Map 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 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 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 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> eventValues;
-
- EventType(Class eventType, Function> eventValues) {
- this.eventType = eventType;
- this.eventValues = event -> eventValues.apply((T) event);
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java
deleted file mode 100644
index d323dbc8..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java
+++ /dev/null
@@ -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 .
- */
-
-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 variables, Consumer echoConsumer) {
- new ScriptExecutor(bookMeta, p, variables, echoConsumer);
- return true;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java
deleted file mode 100644
index 96a7d6d2..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java
+++ /dev/null
@@ -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 .
- */
-
-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 pages;
- public final String[] args;
-
- @Override
- public String eventName() {
- return args[0];
- }
-
- @Override
- public boolean execute(Player p, Map variables, Consumer 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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java
deleted file mode 100644
index 2c9bd6c8..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java
+++ /dev/null
@@ -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 .
- */
-
-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);
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java
deleted file mode 100644
index 5f8adadd..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java
+++ /dev/null
@@ -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 .
- */
-
-package de.steamwar.bausystem.features.script.custom.hotkey;
-
-import de.steamwar.bausystem.BauSystem;
-import de.steamwar.bausystem.features.script.CustomScriptManager;
-import de.steamwar.linkage.Linked;
-import de.steamwar.linkage.LinkedInstance;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.messaging.PluginMessageListener;
-
-@Linked
-public class HotkeyListener implements PluginMessageListener {
-
- {
- 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;
- if (message.length < 5) return;
- int action = message[4] & 0xFF;
- if (action == 2) return;
- int key = (message[0] & 0xFF) << 24 | (message[1] & 0xFF) << 16 | (message[2] & 0xFF) << 8 | (message[3] & 0xFF);
- if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return;
- 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);
- } else {
- // player.sendMessage("Hotkey: " + (char) key + " " + action);
- manager.callHotkey(0, ((char) key), player, action == 1);
- }
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java
deleted file mode 100644
index 056afaea..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java
+++ /dev/null
@@ -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 .
- */
-
-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 modifiers = Modifier.get(mods);
- Key k = Key.fromString(key + "");
- if (k == null) {
- return false;
- }
-
- try {
- String[] split = checkAgainst.split("\\+");
- Set 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 get(int mods) {
- Set 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;
- }
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java
deleted file mode 100644
index f467e460..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java
+++ /dev/null
@@ -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 .
- */
-
-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 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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java
deleted file mode 100644
index 0407f621..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java
+++ /dev/null
@@ -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 .
- */
-
-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 pages;
- public final String[] args;
-
- @Override
- public String hotkey() {
- return args[0];
- }
-
- @Override
- public boolean execute(Player p, boolean pressed) {
- Map 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;
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java
new file mode 100644
index 00000000..e0602616
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java
@@ -0,0 +1,22 @@
+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]);
+ }
+ ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), LuaValue.listOf(values));
+ }
+}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java
similarity index 52%
rename from BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java
rename to BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java
index 4ee1a97d..3a43a83d 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java
@@ -1,31 +1,12 @@
-/*
- * 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 .
- */
-
-package de.steamwar.bausystem.features.script.custom.event;
+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.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
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;
@@ -39,6 +20,8 @@ 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;
@@ -48,9 +31,6 @@ import java.util.Set;
@Linked
public class EventListener implements Listener {
- @LinkedInstance
- public CustomScriptManager manager;
-
private static final Map LAST_FS = new HashMap<>();
{
@@ -61,18 +41,18 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
- manager.callEvent(EventType.SelfJoin, event.getPlayer(), event);
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
- manager.callEvent(EventType.SelfLeave, event.getPlayer(), event);
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL);
}
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
if (LAST_FS.containsKey(event.getPlayer())) {
- manager.callEvent(EventType.FF, event.getPlayer(), event);
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.FF, LuaValue.NIL);
} else {
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
}
@@ -80,12 +60,22 @@ public class EventListener implements Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
- manager.callEvent(EventType.PlaceBlock, event.getPlayer(), 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());
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
- manager.callEvent(EventType.BreakBlock, event.getPlayer(), 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());
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table);
}
private Set ignore = new HashSet<>();
@@ -95,11 +85,25 @@ public class EventListener implements Listener {
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().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) {
- manager.callEvent(EventType.RightClick, event.getPlayer(), event);
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table);
}
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
- manager.callEvent(EventType.LeftClick, event.getPlayer(), event);
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table);
}
}
@@ -112,7 +116,7 @@ public class EventListener implements Listener {
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
- manager.callEvent(EventType.TNTSpawn, player, event);
+ ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL);
}
}
}
@@ -124,9 +128,14 @@ public class EventListener implements Listener {
}
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());
+
for (Player player : Bukkit.getOnlinePlayers()) {
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
- manager.callEvent(EventType.TNTExplode, player, event);
+ ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table);
}
}
}
@@ -134,13 +143,17 @@ public class EventListener implements Listener {
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
ignore.add(event.getPlayer());
- manager.callEvent(EventType.DropItem, event.getPlayer(), event);
+ LuaTable table = new LuaTable();
+ table.set("type", event.getItemDrop().getItemStack().getType().name());
+ ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table);
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
for (Player player : Bukkit.getOnlinePlayers()) {
- manager.callEvent(EventType.EntityDeath, player, event);
+ LuaTable table = new LuaTable();
+ table.set("type", event.getEntityType().name());
+ ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table);
}
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java
deleted file mode 100644
index 9bf807fb..00000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java
+++ /dev/null
@@ -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 .
- */
-
-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 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