mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 01:47:54 +01:00
Added ArgumentUUID
This commit is contained in:
parent
fe7b48df48
commit
5320beddb8
@ -197,6 +197,13 @@ public class ArgumentType {
|
||||
return new ArgumentComponent(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentUUID
|
||||
*/
|
||||
public static ArgumentUUID UUID(@NotNull String id) {
|
||||
return new ArgumentUUID(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentNbtTag
|
||||
*/
|
||||
|
@ -0,0 +1,36 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArgumentUUID extends Argument<UUID> {
|
||||
|
||||
public static final int INVALID_UUID = -1;
|
||||
|
||||
public ArgumentUUID(@NotNull String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public UUID parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
try {
|
||||
return UUID.fromString(input);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw new ArgumentSyntaxException("Invalid UUID", input, INVALID_UUID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
argumentNode.parser = "minecraft:uuid";
|
||||
|
||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user