diff --git a/src/main/java/net/minestom/server/command/CommandManager.java b/src/main/java/net/minestom/server/command/CommandManager.java index 232872125..12c9e13f6 100644 --- a/src/main/java/net/minestom/server/command/CommandManager.java +++ b/src/main/java/net/minestom/server/command/CommandManager.java @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import net.minestom.server.MinecraftServer; import net.minestom.server.command.builder.Command; +import net.minestom.server.command.builder.CommandData; import net.minestom.server.command.builder.CommandDispatcher; import net.minestom.server.command.builder.CommandSyntax; import net.minestom.server.command.builder.arguments.*; @@ -157,7 +158,7 @@ public final class CommandManager { * @return true if the command hadn't been cancelled and has been successful */ @Nullable - public NBTCompound execute(@NotNull CommandSender sender, @NotNull String command) { + public CommandData execute(@NotNull CommandSender sender, @NotNull String command) { // Command event if (sender instanceof Player) { @@ -176,7 +177,7 @@ public final class CommandManager { { // Check for rich-command - final NBTCompound commandData = this.dispatcher.execute(sender, command); + final CommandData commandData = this.dispatcher.execute(sender, command); if (commandData != null) { return commandData; } else { @@ -202,11 +203,11 @@ public final class CommandManager { /** * Executes the command using a {@link ServerSender} to do not * print the command messages, and rely instead on the command return data. - * - * @see #execute(CommandSender, String) + * + * @see #execute(CommandSender, String) */ @Nullable - public NBTCompound executeServerCommand(@NotNull String command) { + public CommandData executeServerCommand(@NotNull String command) { return execute(serverSender, command); } diff --git a/src/main/java/net/minestom/server/command/builder/Arguments.java b/src/main/java/net/minestom/server/command/builder/Arguments.java index 9e057c504..eee8f7293 100644 --- a/src/main/java/net/minestom/server/command/builder/Arguments.java +++ b/src/main/java/net/minestom/server/command/builder/Arguments.java @@ -35,7 +35,7 @@ public final class Arguments { private Map args = new HashMap<>(); - private NBTCompound commandReturn; + private CommandData returnData; @NotNull public T get(@NotNull Argument argument) { @@ -253,12 +253,12 @@ public final class Arguments { } @Nullable - public NBTCompound getCommandReturn() { - return commandReturn; + public CommandData getReturnData() { + return returnData; } - public void setCommandReturn(@Nullable NBTCompound commandReturn) { - this.commandReturn = commandReturn; + public void setReturnData(@Nullable CommandData returnData) { + this.returnData = returnData; } protected void setArg(@NotNull String id, Object value) { diff --git a/src/main/java/net/minestom/server/command/builder/CommandData.java b/src/main/java/net/minestom/server/command/builder/CommandData.java new file mode 100644 index 000000000..99de74932 --- /dev/null +++ b/src/main/java/net/minestom/server/command/builder/CommandData.java @@ -0,0 +1,26 @@ +package net.minestom.server.command.builder; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class CommandData { + + private final Map dataMap = new ConcurrentHashMap<>(); + + public void set(@NotNull String key, Object value) { + this.dataMap.put(key, value); + } + + @Nullable + public T get(@NotNull String key) { + return (T) dataMap.get(key); + } + + @NotNull + public Map getDataMap() { + return dataMap; + } +} diff --git a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java index fe8129e3a..7f132c4da 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java +++ b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java @@ -8,7 +8,6 @@ import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.util.*; import java.util.regex.Pattern; @@ -87,7 +86,7 @@ public class CommandDispatcher { * @return the command data, null if none */ @Nullable - public NBTCompound execute(@NotNull CommandSender source, @NotNull String commandString) { + public CommandData execute(@NotNull CommandSender source, @NotNull String commandString) { CommandResult result = parse(commandString); if (result != null) { return result.execute(source, commandString); @@ -382,7 +381,7 @@ public class CommandDispatcher { * @return the command data, null if none */ @Nullable - public NBTCompound execute(@NotNull CommandSender source, @NotNull String commandString) { + public CommandData execute(@NotNull CommandSender source, @NotNull String commandString) { // Global listener command.globalListener(source, arguments, commandString); // Command condition check @@ -413,7 +412,7 @@ public class CommandDispatcher { callback.apply(source, argumentSyntaxException); } - return arguments.getCommandReturn(); + return arguments.getReturnData(); } }