TeamColorArgument .java

net.minecraft.commands.arguments.TeamColorArgument (class): members: teamColor, getTeamColor, ERROR_INVALID_VALUE, listSuggestions, getExamples, EXAMPLES.

net.minecraft.commands.argumentsclass55 linescommon1.9 KB

Implements

API Surface (5)

TeamColorArgument teamColor()
TeamColor getTeamColor(final CommandContext<CommandSourceStack> context, final String name)
TeamColor parse(final StringReader reader)
<S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder)
Collection<String> getExamples()

Fields & Constants (2)

EXAMPLES
ERROR_INVALID_VALUE

String literals (2)

"green"
"argument.color.invalid"

Code Graph: Dependencies (4)

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

Full Source

TeamColorArgument.java55 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.DynamicCommandExceptionType;
8
import com.mojang.brigadier.suggestion.Suggestions;
9
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
10
import java.util.Arrays;
11
import java.util.Collection;
12
import java.util.concurrent.CompletableFuture;
13
import net.minecraft.commands.CommandSourceStack;
14
import net.minecraft.commands.SharedSuggestionProvider;
15
import net.minecraft.network.chat.Component;
16
import net.minecraft.world.scores.TeamColor;
17
18
public class TeamColorArgument implements ArgumentType<TeamColor> {
19
	private static final Collection<String> EXAMPLES = Arrays.asList("red", "green");
20
	public static final DynamicCommandExceptionType ERROR_INVALID_VALUE = new DynamicCommandExceptionType(
21
		value -> Component.translatableEscape("argument.color.invalid", value)
22
	);
23
24
	private TeamColorArgument() {
25
	}
26
27
	public static TeamColorArgument teamColor() {
28
		return new TeamColorArgument();
29
	}
30
31
	public static TeamColor getTeamColor(final CommandContext<CommandSourceStack> context, final String name) {
32
		return context.getArgument(name, TeamColor.class);
33
	}
34
35
	public TeamColor parse(final StringReader reader) throws CommandSyntaxException {
36
		String id = reader.readUnquotedString();
37
		TeamColor result = TeamColor.byName(id);
38
		if (result == null) {
39
			throw ERROR_INVALID_VALUE.createWithContext(reader, id);
40
		} else {
41
			return result;
42
		}
43
	}
44
45
	@Override
46
	public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder) {
47
		return SharedSuggestionProvider.suggest(TeamColor.VALUES.stream().map(TeamColor::getSerializedName), builder);
48
	}
49
50
	@Override
51
	public Collection<String> getExamples() {
52
		return EXAMPLES;
53
	}
54
}
55

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