Improve ArgumentNumber.

This commit is contained in:
Articdive 2020-08-01 07:35:16 +02:00
parent 7b947ba09b
commit 4b47245c90
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
5 changed files with 15 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntities;
import net.minestom.server.entity.Entity;
import java.util.ArrayList;
import java.util.List;
public class EntitySelectorCommand extends Command {
@ -21,6 +21,6 @@ public class EntitySelectorCommand extends Command {
}
private void executor(CommandSender commandSender, Arguments arguments) {
ArrayList<Entity> entities = arguments.getEntities("entities");
List<Entity> entities = arguments.getEntities("entities");
}
}

View File

@ -378,7 +378,7 @@ public class CommandManager {
return literalNode;
}
private List<DeclareCommandsPacket.Node> toNodes(Argument argument, boolean executable) {
private List<DeclareCommandsPacket.Node> toNodes(Argument<?> argument, boolean executable) {
List<DeclareCommandsPacket.Node> nodes = new ArrayList<>();
/*DeclareCommandsPacket.Node testNode = simpleArgumentNode(nodes, argument, executable);
@ -515,7 +515,7 @@ public class CommandManager {
return nodes;
}
private byte getNumberProperties(ArgumentNumber argumentNumber) {
private byte getNumberProperties(ArgumentNumber<? extends Number> argumentNumber) {
byte result = 0;
if (argumentNumber.hasMin())
result += 1;
@ -525,7 +525,7 @@ public class CommandManager {
}
private DeclareCommandsPacket.Node simpleArgumentNode(List<DeclareCommandsPacket.Node> nodes,
Argument argument, boolean executable) {
Argument<?> argument, boolean executable) {
DeclareCommandsPacket.Node argumentNode = new DeclareCommandsPacket.Node();
nodes.add(argumentNode);

View File

@ -11,13 +11,13 @@ import net.minestom.server.utils.math.FloatRange;
import net.minestom.server.utils.math.IntRange;
import net.minestom.server.utils.time.UpdateOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Arguments {
private Map<String, Object> args = new HashMap<>();
private final Map<String, Object> args = new HashMap<>();
public Structure getStructure(String id) {
return (Structure) getObject(id);
@ -87,8 +87,8 @@ public class Arguments {
return (FloatRange) getObject(id);
}
public ArrayList<Entity> getEntities(String id) {
return (ArrayList<Entity>) getObject(id);
public List<Entity> getEntities(String id) {
return (List<Entity>) getObject(id);
}
public Object getObject(String id) {

View File

@ -29,7 +29,7 @@ public class ArgumentTime extends Argument<UpdateOption> {
value = value.substring(0, value.length() - 1);
try {
// Check if value is a number
Integer.valueOf(value);
Integer.parseInt(value);
return SUCCESS;
} catch (NumberFormatException e) {
@ -49,7 +49,7 @@ public class ArgumentTime extends Argument<UpdateOption> {
timeUnit = TimeUnit.TICK;
}
value = value.substring(0, value.length() - 1);
final int time = Integer.valueOf(value);
final int time = Integer.parseInt(value);
return new UpdateOption(time, timeUnit);
}

View File

@ -5,7 +5,7 @@ import net.minestom.server.command.builder.arguments.Argument;
import java.math.BigDecimal;
import java.util.regex.Pattern;
public abstract class ArgumentNumber<T> extends Argument<T> {
public abstract class ArgumentNumber<T extends Number> extends Argument<T> {
public static final int NOT_NUMBER_ERROR = 1;
public static final int RANGE_ERROR = 2;
@ -17,19 +17,19 @@ public abstract class ArgumentNumber<T> extends Argument<T> {
super(id, false);
}
public ArgumentNumber min(T value) {
public ArgumentNumber<T> min(T value) {
this.min = value;
this.hasMin = true;
return this;
}
public ArgumentNumber max(T value) {
public ArgumentNumber<T> max(T value) {
this.max = value;
this.hasMax = true;
return this;
}
public ArgumentNumber between(T min, T max) {
public ArgumentNumber<T> between(T min, T max) {
this.min = min;
this.max = max;
this.hasMin = true;