From d77deffcc95f1aa21fdafbdb1f6a6845c9aa9b50 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Jul 2021 14:54:13 +0200 Subject: [PATCH] CustomCommandListener on steroids Signed-off-by: yoyosource --- .../script/CustomCommandListener.java | 19 ++++--------------- .../features/script/ScriptExecutor.java | 4 ++-- .../features/script/variables/Value.java | 4 ++++ 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomCommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomCommandListener.java index 05205cc3..551fac93 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomCommandListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomCommandListener.java @@ -35,7 +35,10 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Linked(LinkageType.LISTENER) public class CustomCommandListener implements Listener { @@ -126,20 +129,6 @@ public class CustomCommandListener implements Listener { } customCommands.stream().map(customCommand -> customCommand.execute(e)).filter(b -> !b).findFirst(); - - - /*String[] command = e.getMessage().split(" "); - - BookMeta bookMeta = bookMetaMap.get(e.getMessage()); - if (bookMeta == null) { - return; - } - e.setCancelled(true); - try { - new ScriptExecutor(bookMeta, e.getPlayer()); - } catch (StackOverflowError exception) { - // Ignored - }*/ } private boolean isNoBook(ItemStack item) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index dade614d..01ffc8e6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -52,7 +52,7 @@ public final class ScriptExecutor { command = command.replaceAll(" +", " "); if (command.startsWith("#") || command.trim().isEmpty()) { if (initial && command.startsWith("#!CMD /")) { - specialCommand = command.substring(7); + specialCommand = command.substring(7).split(" ")[0]; } initial = false; continue; @@ -102,7 +102,7 @@ public final class ScriptExecutor { } - PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (command.equals(specialCommand) ? "script:" : "") + command); + PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (specialCommand != null && command.startsWith(specialCommand) ? "script:" : "") + command); Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); if (preprocessEvent.isCancelled()) { continue; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java index 9333b0e8..98c1cb46 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java @@ -1,6 +1,7 @@ package de.steamwar.bausystem.features.script.variables; import lombok.AllArgsConstructor; +import lombok.ToString; public interface Value { long asLong(); @@ -12,6 +13,7 @@ public interface Value { void fromString(String value); @AllArgsConstructor + @ToString class LongValue implements Value { private long value; @@ -52,6 +54,7 @@ public interface Value { } @AllArgsConstructor + @ToString class BooleanValue implements Value { private boolean value; @@ -88,6 +91,7 @@ public interface Value { } @AllArgsConstructor + @ToString class StringValue implements Value { private String value;