mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 00:51:34 +01:00
Added NodeMaker + ArgumentCommand
This commit is contained in:
parent
601ee71744
commit
1a2fd4f743
@ -5,10 +5,7 @@ import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandDispatcher;
|
||||
import net.minestom.server.command.builder.CommandResult;
|
||||
import net.minestom.server.command.builder.CommandSyntax;
|
||||
import net.minestom.server.command.builder.*;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -203,6 +200,11 @@ public final class CommandManager {
|
||||
return execute(serverSender, command);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CommandDispatcher getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the callback executed once an unknown command is run.
|
||||
*
|
||||
@ -422,9 +424,10 @@ public final class CommandManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
NodeMaker nodeMaker = new NodeMaker();
|
||||
|
||||
// Represent the last nodes computed in the last iteration
|
||||
DeclareCommandsPacket.Node[] lastNodes = null;
|
||||
//DeclareCommandsPacket.Node[] lastNodes = null;
|
||||
|
||||
// Represent the children of the last node
|
||||
IntList argChildren = null;
|
||||
@ -442,7 +445,7 @@ public final class CommandManager {
|
||||
final Argument<?> sharedArgument = parsedArguments[i];
|
||||
|
||||
argChildren = new IntArrayList();
|
||||
lastNodes = storedArgumentsNodes.get(sharedArgument);
|
||||
nodeMaker.setLastNodes(storedArgumentsNodes.get(sharedArgument));
|
||||
foundSharedPart = true;
|
||||
}
|
||||
}
|
||||
@ -451,7 +454,8 @@ public final class CommandManager {
|
||||
}
|
||||
|
||||
|
||||
final DeclareCommandsPacket.Node[] argumentNodes = argument.toNodes(isLast);
|
||||
argument.processNodes(nodeMaker, isLast);
|
||||
final DeclareCommandsPacket.Node[] argumentNodes = nodeMaker.getCurrentNodes();
|
||||
storedArgumentsNodes.put(argument, argumentNodes);
|
||||
for (DeclareCommandsPacket.Node node : argumentNodes) {
|
||||
final int childId = nodes.size();
|
||||
@ -464,6 +468,7 @@ public final class CommandManager {
|
||||
argChildren.add(childId);
|
||||
}
|
||||
|
||||
final DeclareCommandsPacket.Node[] lastNodes = nodeMaker.getLastNodes();
|
||||
if (lastNodes != null) {
|
||||
final int[] children = ArrayUtils.toArray(argChildren);
|
||||
|
||||
@ -491,7 +496,7 @@ public final class CommandManager {
|
||||
} else {
|
||||
// Create children list which will be filled during next iteration
|
||||
argChildren = new IntArrayList();
|
||||
lastNodes = argumentNodes;
|
||||
nodeMaker.setLastNodes(argumentNodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class CommandDispatcher {
|
||||
result.type = CommandResult.Type.SUCCESS;
|
||||
result.parsedCommand = parsedCommand;
|
||||
} else {
|
||||
// Syntax not found, use the default executor
|
||||
// Syntax not found, use the default executor (if any)
|
||||
result.type = CommandResult.Type.INVALID_SYNTAX;
|
||||
result.parsedCommand = ParsedCommand.withDefaultExecutor(command);
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package net.minestom.server.command.builder;
|
||||
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NodeMaker {
|
||||
|
||||
private DeclareCommandsPacket.Node[] lastNodes;
|
||||
private DeclareCommandsPacket.Node[] currentNodes;
|
||||
|
||||
public DeclareCommandsPacket.Node[] getCurrentNodes() {
|
||||
return currentNodes;
|
||||
}
|
||||
|
||||
public void setCurrentNodes(@NotNull DeclareCommandsPacket.Node[] nodes) {
|
||||
this.currentNodes = nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the nodes computed in the last iteration.
|
||||
*
|
||||
* @return the previous nodes, null if none
|
||||
*/
|
||||
@Nullable
|
||||
public DeclareCommandsPacket.Node[] getLastNodes() {
|
||||
return lastNodes;
|
||||
}
|
||||
|
||||
public void setLastNodes(DeclareCommandsPacket.Node[] lastNodes) {
|
||||
this.lastNodes = lastNodes;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.command.builder.ArgumentCallback;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandExecutor;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -78,10 +79,10 @@ public abstract class Argument<T> {
|
||||
/**
|
||||
* Turns the argument into a list of nodes for command dispatching. Make sure to set the Node's parser.
|
||||
*
|
||||
* @return the argument as a list of command packet nodes
|
||||
* @param nodeMaker helper object used to create and modify nodes
|
||||
* @param executable true if this will be the last argument, false otherwise
|
||||
*/
|
||||
@NotNull
|
||||
public abstract DeclareCommandsPacket.Node[] toNodes(boolean executable);
|
||||
public abstract void processNodes(@NotNull NodeMaker nodeMaker, boolean executable);
|
||||
|
||||
/**
|
||||
* Builds an argument node.
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -28,14 +29,12 @@ public class ArgumentBoolean extends Argument<Boolean> {
|
||||
throw new ArgumentSyntaxException("Not a boolean", input, NOT_BOOLEAN_ERROR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:bool";
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.CommandDispatcher;
|
||||
import net.minestom.server.command.builder.CommandResult;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArgumentCommand extends Argument<CommandResult> {
|
||||
|
||||
public static final int INVALID_COMMAND_ERROR = 1;
|
||||
|
||||
public ArgumentCommand(@NotNull String id) {
|
||||
super(id, true, true); // TODO don't use remaining?
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandResult parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
CommandDispatcher dispatcher = MinecraftServer.getCommandManager().getDispatcher();
|
||||
CommandResult result = dispatcher.parse(input);
|
||||
|
||||
if (result.getType() != CommandResult.Type.SUCCESS)
|
||||
throw new ArgumentSyntaxException("Invalid command", input, INVALID_COMMAND_ERROR);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
final DeclareCommandsPacket.Node[] lastNodes = nodeMaker.getLastNodes();
|
||||
|
||||
// FIXME check if lastNodes is null
|
||||
for (DeclareCommandsPacket.Node node : lastNodes) {
|
||||
node.flags |= 0x08; // Redirection mask
|
||||
node.redirectedNode = 0; // Redirect to root
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.callback.validator.StringArrayValidator;
|
||||
@ -37,9 +38,8 @@ public class ArgumentDynamicStringArray extends Argument<String[]> {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, true);
|
||||
|
||||
argumentNode.parser = "brigadier:string";
|
||||
@ -48,7 +48,7 @@ public class ArgumentDynamicStringArray extends Argument<String[]> {
|
||||
};
|
||||
argumentNode.suggestionsType = "minecraft:ask_server";
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.SuggestionType;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
@ -44,9 +45,8 @@ public class ArgumentDynamicWord extends Argument<String> {
|
||||
return input;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, true);
|
||||
|
||||
final SuggestionType suggestionType = this.getSuggestionType();
|
||||
@ -56,7 +56,8 @@ public class ArgumentDynamicWord extends Argument<String> {
|
||||
packetWriter.writeVarInt(0); // Single word
|
||||
};
|
||||
argumentNode.suggestionsType = suggestionType.getIdentifier();
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,15 +1,14 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArgumentLiteral extends Argument<String> {
|
||||
|
||||
public static final int SPACE_ERROR = 1;
|
||||
public static final int INVALID_VALUE_ERROR = 2;
|
||||
public static final int INVALID_VALUE_ERROR = 1;
|
||||
|
||||
public ArgumentLiteral(@NotNull String id) {
|
||||
super(id);
|
||||
@ -18,22 +17,18 @@ public class ArgumentLiteral extends Argument<String> {
|
||||
@NotNull
|
||||
@Override
|
||||
public String parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
if (input.contains(StringUtils.SPACE))
|
||||
throw new ArgumentSyntaxException("Literals cannot contain space character", input, SPACE_ERROR);
|
||||
|
||||
if (!input.equals(getId()))
|
||||
throw new ArgumentSyntaxException("Invalid literal value", input, INVALID_VALUE_ERROR);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node literalNode = new DeclareCommandsPacket.Node();
|
||||
literalNode.flags = COMMAND_MANAGER.getFlag(CommandManager.NodeType.LITERAL, executable, false, false);
|
||||
literalNode.name = getId();
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{literalNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{literalNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
@ -24,16 +25,16 @@ public class ArgumentString extends Argument<String> {
|
||||
return staticParse(input);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:string";
|
||||
argumentNode.properties = packetWriter -> {
|
||||
packetWriter.writeVarInt(1); // Quotable phrase
|
||||
};
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -23,15 +24,15 @@ public class ArgumentStringArray extends Argument<String[]> {
|
||||
return input.split(Pattern.quote(StringUtils.SPACE));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:string";
|
||||
argumentNode.properties = packetWriter -> {
|
||||
packetWriter.writeVarInt(2); // Greedy phrase
|
||||
};
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ public class ArgumentType {
|
||||
return new ArgumentDynamicStringArray(id);
|
||||
}
|
||||
|
||||
public static ArgumentCommand Command(@NotNull String id) {
|
||||
return new ArgumentCommand(id);
|
||||
}
|
||||
|
||||
// Minecraft specific arguments
|
||||
|
||||
public static ArgumentColor Color(@NotNull String id) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
@ -71,9 +72,8 @@ public class ArgumentWord extends Argument<String> {
|
||||
return input;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
|
||||
// Add the single word properties + parser
|
||||
final Consumer<DeclareCommandsPacket.Node> wordConsumer = node -> {
|
||||
@ -99,12 +99,12 @@ public class ArgumentWord extends Argument<String> {
|
||||
nodes[i] = argumentNode;
|
||||
|
||||
}
|
||||
return nodes;
|
||||
nodeMaker.setCurrentNodes(nodes);
|
||||
} else {
|
||||
// Can be any word, add only one argument node
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
wordConsumer.accept(argumentNode);
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
@ -29,11 +30,11 @@ public class ArgumentColor extends Argument<ChatColor> {
|
||||
return color;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:color";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
@ -66,9 +67,8 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
return staticParse(input, onlySingleEntity, onlyPlayers);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:entity";
|
||||
argumentNode.properties = packetWriter -> {
|
||||
@ -82,7 +82,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
packetWriter.writeByte(mask);
|
||||
};
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.math.FloatRange;
|
||||
@ -54,11 +55,11 @@ public class ArgumentFloatRange extends ArgumentRange<FloatRange> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:float_range";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.math.IntRange;
|
||||
@ -59,11 +60,11 @@ public class ArgumentIntRange extends ArgumentRange<IntRange> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:int_range";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
@ -63,11 +64,11 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:item_stack";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
@ -39,11 +40,11 @@ public class ArgumentNbtCompoundTag extends Argument<NBTCompound> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:nbt_compound_tag";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
@ -35,11 +36,11 @@ public class ArgumentNbtTag extends Argument<NBT> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:nbt_tag";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import it.unimi.dsi.fastutil.chars.CharArrayList;
|
||||
import it.unimi.dsi.fastutil.chars.CharList;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
@ -58,11 +59,11 @@ public class ArgumentTime extends Argument<UpdateOption> {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:time";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.registry.Registries;
|
||||
@ -16,11 +17,11 @@ public class ArgumentBlockState extends ArgumentRegistry<Block> {
|
||||
return Registries.getBlock(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:block_state";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.item.Enchantment;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.registry.Registries;
|
||||
@ -19,11 +20,11 @@ public class ArgumentEnchantment extends ArgumentRegistry<Enchantment> {
|
||||
return Registries.getEnchantment(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:item_enchantment";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.registry.Registries;
|
||||
@ -19,11 +20,11 @@ public class ArgumentEntityType extends ArgumentRegistry<EntityType> {
|
||||
return Registries.getEntityType(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:entity_summon";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.registry.Registries;
|
||||
@ -19,11 +20,11 @@ public class ArgumentParticle extends ArgumentRegistry<Particle> {
|
||||
return Registries.getParticle(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:particle";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.potion.PotionEffect;
|
||||
import net.minestom.server.registry.Registries;
|
||||
@ -19,11 +20,11 @@ public class ArgumentPotionEffect extends ArgumentRegistry<PotionEffect> {
|
||||
return Registries.getPotionEffect(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:mob_effect";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.number;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -41,9 +42,8 @@ public class ArgumentDouble extends ArgumentNumber<Double> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:double";
|
||||
@ -55,7 +55,7 @@ public class ArgumentDouble extends ArgumentNumber<Double> {
|
||||
packetWriter.writeDouble(this.getMax());
|
||||
};
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.number;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -41,9 +42,8 @@ public class ArgumentFloat extends ArgumentNumber<Float> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:float";
|
||||
@ -55,7 +55,7 @@ public class ArgumentFloat extends ArgumentNumber<Float> {
|
||||
packetWriter.writeFloat(this.getMax());
|
||||
};
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.number;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -32,9 +33,8 @@ public class ArgumentInteger extends ArgumentNumber<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "brigadier:integer";
|
||||
@ -46,7 +46,7 @@ public class ArgumentInteger extends ArgumentNumber<Integer> {
|
||||
packetWriter.writeInt(this.getMax());
|
||||
};
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.number;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -32,9 +33,8 @@ public class ArgumentLong extends ArgumentNumber<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
// TODO maybe use ArgumentLiteral/ArgumentWord and impose long restriction server side?
|
||||
@ -48,7 +48,7 @@ public class ArgumentLong extends ArgumentNumber<Long> {
|
||||
packetWriter.writeInt(this.getMax().intValue());
|
||||
};
|
||||
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.relative;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
@ -80,11 +81,11 @@ public class ArgumentRelativeBlockPosition extends ArgumentRelative<RelativeBloc
|
||||
return new RelativeBlockPosition(blockPosition, relativeX, relativeY, relativeZ);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:block_pos";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.relative;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.Vector;
|
||||
@ -68,12 +69,12 @@ public class ArgumentRelativeVec2 extends ArgumentRelative<RelativeVec> {
|
||||
return new RelativeVec(vector, relativeX, false, relativeZ);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:vec2";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.relative;
|
||||
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.Vector;
|
||||
@ -75,11 +76,11 @@ public class ArgumentRelativeVec3 extends ArgumentRelative<RelativeVec> {
|
||||
return new RelativeVec(vector, relativeX, relativeY, relativeZ);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:vec3";
|
||||
return new DeclareCommandsPacket.Node[]{argumentNode};
|
||||
|
||||
nodeMaker.setCurrentNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user