Put getNumberProperties into Number arg

This commit is contained in:
LeoDog896 2021-02-09 10:58:27 -05:00
parent bedc91427e
commit becd876dcd
6 changed files with 19 additions and 14 deletions

View File

@ -10,7 +10,6 @@ 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.*;
import net.minestom.server.command.builder.arguments.number.ArgumentNumber;
import net.minestom.server.command.builder.condition.CommandCondition;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerCommandEvent;
@ -518,6 +517,7 @@ public final class CommandManager {
return literalNode;
}
// TODO should we even have this function?
/**
* Converts an argument to a node with the correct brigadier parser.
*
@ -539,15 +539,6 @@ public final class CommandManager {
return argument.toNodes(executable);
}
public byte getNumberProperties(@NotNull ArgumentNumber<? extends Number> argumentNumber) {
byte result = 0;
if (argumentNumber.hasMin())
result += 1;
if (argumentNumber.hasMax())
result += 2;
return result;
}
public byte getFlag(@NotNull NodeType type, boolean executable, boolean redirect, boolean suggestionType) {
byte result = (byte) type.mask;

View File

@ -49,7 +49,7 @@ public class ArgumentDouble extends ArgumentNumber<Double> {
argumentNode.parser = "brigadier:double";
argumentNode.properties = packetWriter -> {
packetWriter.writeByte(MinecraftServer.getCommandManager().getNumberProperties(this));
packetWriter.writeByte(getNumberProperties());
if (this.hasMin())
packetWriter.writeDouble(this.getMin());
if (this.hasMax())

View File

@ -49,7 +49,7 @@ public class ArgumentFloat extends ArgumentNumber<Float> {
argumentNode.parser = "brigadier:float";
argumentNode.properties = packetWriter -> {
packetWriter.writeByte(MinecraftServer.getCommandManager().getNumberProperties(this));
packetWriter.writeByte(getNumberProperties());
if (this.hasMin())
packetWriter.writeFloat(this.getMin());
if (this.hasMax())

View File

@ -40,7 +40,7 @@ public class ArgumentInteger extends ArgumentNumber<Integer> {
argumentNode.parser = "brigadier:integer";
argumentNode.properties = packetWriter -> {
packetWriter.writeByte(MinecraftServer.getCommandManager().getNumberProperties(this));
packetWriter.writeByte(getNumberProperties());
if (this.hasMin())
packetWriter.writeInt(this.getMin());
if (this.hasMax())

View File

@ -42,7 +42,7 @@ public class ArgumentLong extends ArgumentNumber<Long> {
argumentNode.parser = "brigadier:int";
argumentNode.properties = packetWriter -> {
packetWriter.writeByte(MinecraftServer.getCommandManager().getNumberProperties(this));
packetWriter.writeByte(getNumberProperties());
if (this.hasMin())
packetWriter.writeInt(this.getMin().intValue());
if (this.hasMax())

View File

@ -43,6 +43,20 @@ public abstract class ArgumentNumber<T extends Number> extends Argument<T> {
return this;
}
/**
* Creates the byteflag based on the number's min/max existance.
*
* @return A byteflag for argument specification.
*/
public byte getNumberProperties() {
byte result = 0;
if (this.hasMin())
result += 1;
if (this.hasMax())
result += 2;
return result;
}
/**
* Gets if the argument has a minimum.
*