Put simpleArgumentNode into Argument

This commit is contained in:
LeoDog896 2021-02-08 21:03:55 -05:00
parent b770710e0d
commit f20d8941a5
26 changed files with 42 additions and 42 deletions

View File

@ -534,24 +534,6 @@ public final class CommandManager {
return result; return result;
} }
/**
* Builds an argument node.
*
* @param argument the argument
* @param executable true if this will be the last argument, false otherwise
* @return the created {@link DeclareCommandsPacket.Node}
*/
@NotNull
public DeclareCommandsPacket.Node simpleArgumentNode(@NotNull Argument<?> argument,
boolean executable, boolean suggestion) {
DeclareCommandsPacket.Node argumentNode = new DeclareCommandsPacket.Node();
argumentNode.flags = getFlag(NodeType.ARGUMENT, executable, false, suggestion);
argumentNode.name = argument.getId();
return argumentNode;
}
public byte getFlag(@NotNull NodeType type, boolean executable, boolean redirect, boolean suggestionType) { public byte getFlag(@NotNull NodeType type, boolean executable, boolean redirect, boolean suggestionType) {
byte result = (byte) type.mask; byte result = (byte) type.mask;

View File

@ -84,6 +84,24 @@ public abstract class Argument<T> {
@NotNull @NotNull
public abstract DeclareCommandsPacket.Node[] toNodes(boolean executable); public abstract DeclareCommandsPacket.Node[] toNodes(boolean executable);
/**
* Builds an argument node.
*
* @param argument the argument
* @param executable true if this will be the last argument, false otherwise
* @return the created {@link DeclareCommandsPacket.Node}
*/
@NotNull
protected static DeclareCommandsPacket.Node simpleArgumentNode(@NotNull Argument<?> argument,
boolean executable, boolean suggestion) {
DeclareCommandsPacket.Node argumentNode = new DeclareCommandsPacket.Node();
argumentNode.flags = COMMAND_MANAGER.getFlag(CommandManager.NodeType.ARGUMENT, executable, false, suggestion);
argumentNode.name = argument.getId();
return argumentNode;
}
/** /**
* Gets the ID of the argument, showed in-game above the chat bar * Gets the ID of the argument, showed in-game above the chat bar
* and used to retrieve the data when the command is parsed in {@link net.minestom.server.command.builder.Arguments}. * and used to retrieve the data when the command is parsed in {@link net.minestom.server.command.builder.Arguments}.

View File

@ -31,7 +31,7 @@ public class ArgumentBoolean extends Argument<Boolean> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:bool"; argumentNode.parser = "brigadier:bool";

View File

@ -40,7 +40,7 @@ public class ArgumentDynamicStringArray extends Argument<String[]> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, true); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, true);
argumentNode.parser = "brigadier:string"; argumentNode.parser = "brigadier:string";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -47,7 +47,7 @@ public class ArgumentDynamicWord extends Argument<String> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, true); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, true);
final SuggestionType suggestionType = this.getSuggestionType(); final SuggestionType suggestionType = this.getSuggestionType();

View File

@ -27,7 +27,7 @@ public class ArgumentString extends Argument<String> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:string"; argumentNode.parser = "brigadier:string";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -27,7 +27,7 @@ public class ArgumentStringArray extends Argument<String[]> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:string"; argumentNode.parser = "brigadier:string";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -32,7 +32,7 @@ public class ArgumentColor extends Argument<ChatColor> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:color"; argumentNode.parser = "minecraft:color";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -57,7 +57,7 @@ public class ArgumentFloatRange extends ArgumentRange<FloatRange> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:float_range"; argumentNode.parser = "minecraft:float_range";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -62,7 +62,7 @@ public class ArgumentIntRange extends ArgumentRange<IntRange> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:int_range"; argumentNode.parser = "minecraft:int_range";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -66,7 +66,7 @@ public class ArgumentItemStack extends Argument<ItemStack> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:item_stack"; argumentNode.parser = "minecraft:item_stack";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -42,7 +42,7 @@ public class ArgumentNbtCompoundTag extends Argument<NBTCompound> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:nbt_compound_tag"; argumentNode.parser = "minecraft:nbt_compound_tag";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -38,7 +38,7 @@ public class ArgumentNbtTag extends Argument<NBT> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:nbt_tag"; argumentNode.parser = "minecraft:nbt_tag";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -61,7 +61,7 @@ public class ArgumentTime extends Argument<UpdateOption> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:time"; argumentNode.parser = "minecraft:time";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -19,7 +19,7 @@ public class ArgumentBlockState extends ArgumentRegistry<Block> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:block_state"; argumentNode.parser = "minecraft:block_state";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -22,7 +22,7 @@ public class ArgumentEnchantment extends ArgumentRegistry<Enchantment> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:item_enchantment"; argumentNode.parser = "minecraft:item_enchantment";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -22,7 +22,7 @@ public class ArgumentEntityType extends ArgumentRegistry<EntityType> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:entity_summon"; argumentNode.parser = "minecraft:entity_summon";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -22,7 +22,7 @@ public class ArgumentParticle extends ArgumentRegistry<Particle> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:particle"; argumentNode.parser = "minecraft:particle";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -22,7 +22,7 @@ public class ArgumentPotionEffect extends ArgumentRegistry<PotionEffect> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:mob_effect"; argumentNode.parser = "minecraft:mob_effect";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -45,7 +45,7 @@ public class ArgumentDouble extends ArgumentNumber<Double> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:double"; argumentNode.parser = "brigadier:double";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -45,7 +45,7 @@ public class ArgumentFloat extends ArgumentNumber<Float> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:float"; argumentNode.parser = "brigadier:float";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -36,7 +36,7 @@ public class ArgumentInteger extends ArgumentNumber<Integer> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "brigadier:integer"; argumentNode.parser = "brigadier:integer";
argumentNode.properties = packetWriter -> { argumentNode.properties = packetWriter -> {

View File

@ -36,7 +36,7 @@ public class ArgumentLong extends ArgumentNumber<Long> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
// TODO maybe use ArgumentLiteral/ArgumentWord and impose long restriction server side? // TODO maybe use ArgumentLiteral/ArgumentWord and impose long restriction server side?

View File

@ -83,7 +83,7 @@ public class ArgumentRelativeBlockPosition extends ArgumentRelative<RelativeBloc
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:block_pos"; argumentNode.parser = "minecraft:block_pos";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -71,7 +71,7 @@ public class ArgumentRelativeVec2 extends ArgumentRelative<RelativeVec> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:vec2"; argumentNode.parser = "minecraft:vec2";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }

View File

@ -78,7 +78,7 @@ public class ArgumentRelativeVec3 extends ArgumentRelative<RelativeVec> {
@NotNull @NotNull
@Override @Override
public DeclareCommandsPacket.Node[] toNodes(boolean executable) { public DeclareCommandsPacket.Node[] toNodes(boolean executable) {
DeclareCommandsPacket.Node argumentNode = COMMAND_MANAGER.simpleArgumentNode(this, executable, false); DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false);
argumentNode.parser = "minecraft:vec3"; argumentNode.parser = "minecraft:vec3";
return new DeclareCommandsPacket.Node[]{argumentNode}; return new DeclareCommandsPacket.Node[]{argumentNode};
} }