TeamArgument .java

net.minecraft.commands.arguments.TeamArgument (class): members: ERROR_TEAM_NOT_FOUND, team, getTeam, listSuggestions, getExamples, EXAMPLES, parse.

net.minecraft.commands.argumentsclass56 linescommon2.1 KB

Implements

API Surface (5)

TeamArgument team()
PlayerTeam getTeam(final CommandContext<CommandSourceStack> context, final String name)
String parse(final StringReader reader)
<S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder)
Collection<String> getExamples()

Fields & Constants (2)

EXAMPLES
ERROR_TEAM_NOT_FOUND

String literals (1)

"team.notFound"

Code Graph: Dependencies (5)

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

Full Source

TeamArgument.java56 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.PlayerTeam;
17
import net.minecraft.world.scores.Scoreboard;
18
19
public class TeamArgument implements ArgumentType<String> {
20
	private static final Collection<String> EXAMPLES = Arrays.asList("foo", "123");
21
	private static final DynamicCommandExceptionType ERROR_TEAM_NOT_FOUND = new DynamicCommandExceptionType(
22
		name -> Component.translatableEscape("team.notFound", name)
23
	);
24
25
	public static TeamArgument team() {
26
		return new TeamArgument();
27
	}
28
29
	public static PlayerTeam getTeam(final CommandContext<CommandSourceStack> context, final String name) throws CommandSyntaxException {
30
		String id = context.getArgument(name, String.class);
31
		Scoreboard scoreboard = context.getSource().getServer().getScoreboard();
32
		PlayerTeam team = scoreboard.getPlayerTeam(id);
33
		if (team == null) {
34
			throw ERROR_TEAM_NOT_FOUND.create(id);
35
		} else {
36
			return team;
37
		}
38
	}
39
40
	public String parse(final StringReader reader) throws CommandSyntaxException {
41
		return reader.readUnquotedString();
42
	}
43
44
	@Override
45
	public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> contextBuilder, final SuggestionsBuilder builder) {
46
		return contextBuilder.getSource() instanceof SharedSuggestionProvider
47
			? SharedSuggestionProvider.suggest(((SharedSuggestionProvider)contextBuilder.getSource()).getAllTeams(), builder)
48
			: Suggestions.empty();
49
	}
50
51
	@Override
52
	public Collection<String> getExamples() {
53
		return EXAMPLES;
54
	}
55
}
56

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