ScoreboardSlotArgument .java

net.minecraft.commands.arguments.ScoreboardSlotArgument (class): members: getDisplaySlot, displaySlot, ERROR_INVALID_VALUE, listSuggestions, getExamples.

net.minecraft.commands.argumentsclass55 linescommon2.0 KB

Implements

API Surface (5)

ScoreboardSlotArgument displaySlot()
DisplaySlot getDisplaySlot(final CommandContext<CommandSourceStack> context, final String name)
DisplaySlot parse(final StringReader reader)
<S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder)
Collection<String> getExamples()

Fields & Constants (2)

EXAMPLES
ERROR_INVALID_VALUE

String literals (3)

"sidebar"
"foo.bar"
"argument.scoreboardDisplaySlot.invalid"

Code Graph: Dependencies (4)

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

Full Source

ScoreboardSlotArgument.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.DisplaySlot;
17
18
public class ScoreboardSlotArgument implements ArgumentType<DisplaySlot> {
19
	private static final Collection<String> EXAMPLES = Arrays.asList("sidebar", "foo.bar");
20
	public static final DynamicCommandExceptionType ERROR_INVALID_VALUE = new DynamicCommandExceptionType(
21
		value -> Component.translatableEscape("argument.scoreboardDisplaySlot.invalid", value)
22
	);
23
24
	private ScoreboardSlotArgument() {
25
	}
26
27
	public static ScoreboardSlotArgument displaySlot() {
28
		return new ScoreboardSlotArgument();
29
	}
30
31
	public static DisplaySlot getDisplaySlot(final CommandContext<CommandSourceStack> context, final String name) {
32
		return context.getArgument(name, DisplaySlot.class);
33
	}
34
35
	public DisplaySlot parse(final StringReader reader) throws CommandSyntaxException {
36
		String name = reader.readUnquotedString();
37
		DisplaySlot result = DisplaySlot.CODEC.byName(name);
38
		if (result == null) {
39
			throw ERROR_INVALID_VALUE.createWithContext(reader, name);
40
		} else {
41
			return result;
42
		}
43
	}
44
45
	@Override
46
	public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
47
		return SharedSuggestionProvider.suggest(Arrays.stream(DisplaySlot.values()).map(DisplaySlot::getSerializedName), builder);
48
	}
49
50
	@Override
51
	public Collection<String> getExamples() {
52
		return EXAMPLES;
53
	}
54
}
55

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