From bab5b51bfb3420ca933c9f5c8157d78b121d2d16 Mon Sep 17 00:00:00 2001 From: Javier A <70771192+Espryth@users.noreply.github.com> Date: Fri, 27 May 2022 08:16:15 -0500 Subject: [PATCH 1/2] fix velocity command --- .../commandflow/velocity/ArrayUtils.java | 11 +++++++++++ .../velocity/VelocityCommandWrapper.java | 17 ++++++----------- pom.xml | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java diff --git a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java new file mode 100644 index 00000000..1859f9f5 --- /dev/null +++ b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java @@ -0,0 +1,11 @@ +package me.fixeddev.commandflow.velocity; + +public class ArrayUtils { + + public static String[] addElementAtStart(String[] array, String element) { + String[] newArray = new String[array.length + 1]; + newArray[0] = element; + System.arraycopy(array, 0, newArray, 1, newArray.length - 1); + return newArray; + } +} diff --git a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java index 7f71ae0e..847e6916 100644 --- a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java +++ b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java @@ -1,23 +1,19 @@ package me.fixeddev.commandflow.velocity; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.command.RawCommand; +import com.velocitypowered.api.command.SimpleCommand; import me.fixeddev.commandflow.CommandManager; import me.fixeddev.commandflow.Namespace; import me.fixeddev.commandflow.NamespaceImpl; import me.fixeddev.commandflow.command.Command; -import me.fixeddev.commandflow.exception.ArgumentParseException; import me.fixeddev.commandflow.exception.CommandException; -import me.fixeddev.commandflow.exception.CommandUsage; -import me.fixeddev.commandflow.exception.InvalidSubCommandException; -import me.fixeddev.commandflow.exception.NoMoreArgumentsException; -import me.fixeddev.commandflow.exception.NoPermissionsException; import me.fixeddev.commandflow.translator.Translator; import net.kyori.text.Component; +import java.util.Arrays; import java.util.List; -public class VelocityCommandWrapper implements RawCommand { +public class VelocityCommandWrapper implements SimpleCommand { protected final CommandManager commandManager; protected final Translator translator; @@ -41,14 +37,14 @@ public VelocityCommandWrapper(Command command, CommandManager commandManager, @Override public void execute(Invocation invocation) { CommandSource commandSource = invocation.source(); - String argumentLine = invocation.alias() + invocation.arguments(); + String[] arguments = ArrayUtils.addElementAtStart(invocation.arguments(), invocation.alias()); Namespace namespace = new NamespaceImpl(); namespace.setObject(CommandSource.class, VelocityCommandManager.SENDER_NAMESPACE, commandSource); namespace.setObject(String.class, "label", invocation.alias()); try { - commandManager.execute(namespace, argumentLine); + commandManager.execute(namespace, Arrays.asList(arguments)); } catch (CommandException e) { CommandException exceptionToSend = e; @@ -73,12 +69,11 @@ public String[] getAliases() { @Override public List suggest(Invocation invocation) { CommandSource commandSource = invocation.source(); - String argumentLine = invocation.arguments(); Namespace namespace = new NamespaceImpl(); namespace.setObject(CommandSource.class, VelocityCommandManager.SENDER_NAMESPACE, commandSource); - return commandManager.getSuggestions(namespace, argumentLine); + return commandManager.getSuggestions(namespace, Arrays.asList(invocation.arguments())); } protected static void sendMessageToSender(CommandException exception, Namespace namespace) { diff --git a/pom.xml b/pom.xml index 1dc97ba6..cc932001 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ 0.5.2 0.5.0 0.5.2 - 0.5.2 + 0.5.3 0.5.2 From b17f11961f111dc1f2e5e11b8f33e9c0d5b01d4e Mon Sep 17 00:00:00 2001 From: Javier A <70771192+Espryth@users.noreply.github.com> Date: Fri, 27 May 2022 08:29:46 -0500 Subject: [PATCH 2/2] back to raw command --- .../me/fixeddev/commandflow/velocity/ArrayUtils.java | 11 ----------- .../commandflow/velocity/VelocityCommandWrapper.java | 7 ++++--- 2 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java diff --git a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java deleted file mode 100644 index 1859f9f5..00000000 --- a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/ArrayUtils.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.fixeddev.commandflow.velocity; - -public class ArrayUtils { - - public static String[] addElementAtStart(String[] array, String element) { - String[] newArray = new String[array.length + 1]; - newArray[0] = element; - System.arraycopy(array, 0, newArray, 1, newArray.length - 1); - return newArray; - } -} diff --git a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java index 847e6916..3f1a8716 100644 --- a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java +++ b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandWrapper.java @@ -1,6 +1,7 @@ package me.fixeddev.commandflow.velocity; import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.RawCommand; import com.velocitypowered.api.command.SimpleCommand; import me.fixeddev.commandflow.CommandManager; import me.fixeddev.commandflow.Namespace; @@ -13,7 +14,7 @@ import java.util.Arrays; import java.util.List; -public class VelocityCommandWrapper implements SimpleCommand { +public class VelocityCommandWrapper implements RawCommand { protected final CommandManager commandManager; protected final Translator translator; @@ -37,14 +38,14 @@ public VelocityCommandWrapper(Command command, CommandManager commandManager, @Override public void execute(Invocation invocation) { CommandSource commandSource = invocation.source(); - String[] arguments = ArrayUtils.addElementAtStart(invocation.arguments(), invocation.alias()); + String argumentLine = invocation.alias() + " " + invocation.arguments(); Namespace namespace = new NamespaceImpl(); namespace.setObject(CommandSource.class, VelocityCommandManager.SENDER_NAMESPACE, commandSource); namespace.setObject(String.class, "label", invocation.alias()); try { - commandManager.execute(namespace, Arrays.asList(arguments)); + commandManager.execute(namespace, argumentLine); } catch (CommandException e) { CommandException exceptionToSend = e;