mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-10 02:17:41 +01:00
Replace NbtCompound to CommandData
This commit is contained in:
parent
3c7bbc9d2d
commit
004b4563c2
@ -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 {
|
||||
@ -206,7 +207,7 @@ public final class CommandManager {
|
||||
* @see #execute(CommandSender, String)
|
||||
*/
|
||||
@Nullable
|
||||
public NBTCompound executeServerCommand(@NotNull String command) {
|
||||
public CommandData executeServerCommand(@NotNull String command) {
|
||||
return execute(serverSender, command);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public final class Arguments {
|
||||
|
||||
private Map<String, Object> args = new HashMap<>();
|
||||
|
||||
private NBTCompound commandReturn;
|
||||
private CommandData returnData;
|
||||
|
||||
@NotNull
|
||||
public <T> T get(@NotNull Argument<T> 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) {
|
||||
|
@ -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<String, Object> dataMap = new ConcurrentHashMap<>();
|
||||
|
||||
public void set(@NotNull String key, Object value) {
|
||||
this.dataMap.put(key, value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T get(@NotNull String key) {
|
||||
return (T) dataMap.get(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> getDataMap() {
|
||||
return dataMap;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user