mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
Small literal argument cleanup
This commit is contained in:
parent
7da3a16978
commit
a0d5ac12bc
@ -6,7 +6,6 @@ import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@ -41,14 +40,6 @@ public class ArgumentEnum<E extends Enum> extends Argument<E> {
|
||||
|
||||
@Override
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
// Add the single word properties + parser
|
||||
final Consumer<DeclareCommandsPacket.Node> wordConsumer = node -> {
|
||||
node.parser = "brigadier:string";
|
||||
node.properties = packetWriter -> {
|
||||
packetWriter.writeVarInt(0); // Single word
|
||||
};
|
||||
};
|
||||
|
||||
// Create a primitive array for mapping
|
||||
DeclareCommandsPacket.Node[] nodes = new DeclareCommandsPacket.Node[this.values.length];
|
||||
|
||||
@ -59,7 +50,6 @@ public class ArgumentEnum<E extends Enum> extends Argument<E> {
|
||||
argumentNode.flags = DeclareCommandsPacket.getFlag(DeclareCommandsPacket.NodeType.LITERAL,
|
||||
executable, false, false);
|
||||
argumentNode.name = this.format.formatter.apply(this.values[i].name());
|
||||
wordConsumer.accept(argumentNode);
|
||||
nodes[i] = argumentNode;
|
||||
}
|
||||
nodeMaker.addNodes(nodes);
|
||||
|
@ -8,8 +8,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Represents a single word in the command.
|
||||
* <p>
|
||||
@ -72,20 +70,10 @@ public class ArgumentWord extends Argument<String> {
|
||||
|
||||
@Override
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
|
||||
// Add the single word properties + parser
|
||||
final Consumer<DeclareCommandsPacket.Node> wordConsumer = node -> {
|
||||
node.parser = "brigadier:string";
|
||||
node.properties = packetWriter -> {
|
||||
packetWriter.writeVarInt(0); // Single word
|
||||
};
|
||||
};
|
||||
|
||||
final boolean hasRestriction = this.hasRestrictions();
|
||||
if (hasRestriction) {
|
||||
if (restrictions != null) {
|
||||
|
||||
// Create a primitive array for mapping
|
||||
DeclareCommandsPacket.Node[] nodes = new DeclareCommandsPacket.Node[this.getRestrictions().length];
|
||||
DeclareCommandsPacket.Node[] nodes = new DeclareCommandsPacket.Node[this.restrictions.length];
|
||||
|
||||
// Create a node for each restrictions as literal
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
@ -93,8 +81,7 @@ public class ArgumentWord extends Argument<String> {
|
||||
|
||||
argumentNode.flags = DeclareCommandsPacket.getFlag(DeclareCommandsPacket.NodeType.LITERAL,
|
||||
executable, false, false);
|
||||
argumentNode.name = this.getRestrictions()[i];
|
||||
wordConsumer.accept(argumentNode);
|
||||
argumentNode.name = this.restrictions[i];
|
||||
nodes[i] = argumentNode;
|
||||
|
||||
}
|
||||
@ -102,7 +89,10 @@ public class ArgumentWord extends Argument<String> {
|
||||
} else {
|
||||
// Can be any word, add only one argument node
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
wordConsumer.accept(argumentNode);
|
||||
argumentNode.parser = "brigadier:string";
|
||||
argumentNode.properties = packetWriter -> {
|
||||
packetWriter.writeVarInt(0); // Single word
|
||||
};
|
||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user