UuidArgument .java

net.minecraft.commands.arguments.UuidArgument (class): members: ALLOWED_CHARACTERS, ERROR_INVALID_UUID, getUuid, uuid, getExamples, EXAMPLES, parse.

net.minecraft.commands.argumentsclass51 linescommon1.7 KB

Implements

API Surface (4)

UUID getUuid(final CommandContext<CommandSourceStack> source, final String name)
UuidArgument uuid()
UUID parse(final StringReader reader)
Collection<String> getExamples()

Fields & Constants (3)

ERROR_INVALID_UUID
EXAMPLES
ALLOWED_CHARACTERS

String literals (1)

"argument.uuid.invalid"

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

UuidArgument.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.arguments;
2
3
import com.mojang.brigadier.StringReader;
4
import com.mojang.brigadier.arguments.ArgumentType;
5
import com.mojang.brigadier.context.CommandContext;
6
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
8
import java.util.Arrays;
9
import java.util.Collection;
10
import java.util.UUID;
11
import java.util.regex.Matcher;
12
import java.util.regex.Pattern;
13
import net.minecraft.commands.CommandSourceStack;
14
import net.minecraft.network.chat.Component;
15
16
public class UuidArgument implements ArgumentType<UUID> {
17
	public static final SimpleCommandExceptionType ERROR_INVALID_UUID = new SimpleCommandExceptionType(Component.translatable("argument.uuid.invalid"));
18
	private static final Collection<String> EXAMPLES = Arrays.asList("dd12be42-52a9-4a91-a8a1-11c01849e498");
19
	private static final Pattern ALLOWED_CHARACTERS = Pattern.compile("^([-A-Fa-f0-9]+)");
20
21
	public static UUID getUuid(final CommandContext<CommandSourceStack> source, final String name) {
22
		return source.getArgument(name, UUID.class);
23
	}
24
25
	public static UuidArgument uuid() {
26
		return new UuidArgument();
27
	}
28
29
	public UUID parse(final StringReader reader) throws CommandSyntaxException {
30
		String remaining = reader.getRemaining();
31
		Matcher matcher = ALLOWED_CHARACTERS.matcher(remaining);
32
		if (matcher.find()) {
33
			String maybeUUID = matcher.group(1);
34
35
			try {
36
				UUID result = UUID.fromString(maybeUUID);
37
				reader.setCursor(reader.getCursor() + maybeUUID.length());
38
				return result;
39
			} catch (IllegalArgumentException var6) {
40
			}
41
		}
42
43
		throw ERROR_INVALID_UUID.createWithContext(reader);
44
	}
45
46
	@Override
47
	public Collection<String> getExamples() {
48
		return EXAMPLES;
49
	}
50
}
51

Decompiled Minecraft 26.3 source of UuidArgument (net/minecraft/commands/arguments/UuidArgument.java) with Mojang official mappings, stored verbatim on the site.