HelpCommand .java

net.minecraft.server.commands.HelpCommand (class): members: ERROR_FAILED, register. strings: "commands.help.failed", "command", "help". imports: Iterables.

net.minecraft.server.commandsclass42 linesserver1.7 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

Fields & Constants (1)

ERROR_FAILED

String literals (3)

"commands.help.failed"
"help"
"command"

Code Graph: Dependencies (3)

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

Full Source

HelpCommand.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.collect.Iterables;
4
import com.mojang.brigadier.CommandDispatcher;
5
import com.mojang.brigadier.ParseResults;
6
import com.mojang.brigadier.arguments.StringArgumentType;
7
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
8
import com.mojang.brigadier.tree.CommandNode;
9
import java.util.Map;
10
import net.minecraft.commands.CommandSourceStack;
11
import net.minecraft.commands.Commands;
12
import net.minecraft.network.chat.Component;
13
14
public class HelpCommand {
15
	private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.help.failed"));
16
17
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
18
		dispatcher.register(Commands.literal("help").executes(s -> {
19
			Map<CommandNode<CommandSourceStack>, String> usage = dispatcher.getSmartUsage(dispatcher.getRoot(), s.getSource());
20
21
			for (String line : usage.values()) {
22
				s.getSource().sendSuccess(() -> Component.literal("/" + line), false);
23
			}
24
25
			return usage.size();
26
		}).then(Commands.argument("command", StringArgumentType.greedyString()).executes(s -> {
27
			ParseResults<CommandSourceStack> command = dispatcher.parse(StringArgumentType.getString(s, "command"), s.getSource());
28
			if (command.getContext().getNodes().isEmpty()) {
29
				throw ERROR_FAILED.create();
30
			}
31
32
			Map<CommandNode<CommandSourceStack>, String> usage = dispatcher.getSmartUsage(Iterables.getLast(command.getContext().getNodes()).getNode(), s.getSource());
33
34
			for (String line : usage.values()) {
35
				s.getSource().sendSuccess(() -> Component.literal("/" + command.getReader().getString() + " " + line), false);
36
			}
37
38
			return usage.size();
39
		})));
40
	}
41
}
42

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