HelpCommand.java

net.minecraft.server.commands.HelpCommand

信息

  • 全限定名:net.minecraft.server.commands.HelpCommand
  • 类型:public class
  • 包:net.minecraft.server.commands
  • 源码路径:src/main/java/net/minecraft/server/commands/HelpCommand.java
  • 起始行号:L14
  • 职责:

    TODO

字段/常量

  • ERROR_FAILED
    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L17

  • 方法名:register
  • 源码定位:L17
  • 返回类型:void
  • 修饰符:public static

参数:

  • dispatcher: CommandDispatcher

说明:

TODO

代码

public class HelpCommand {
    private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.help.failed"));
 
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
            Commands.literal("help")
                .executes(s -> {
                    Map<CommandNode<CommandSourceStack>, String> usage = dispatcher.getSmartUsage(dispatcher.getRoot(), s.getSource());
 
                    for (String line : usage.values()) {
                        s.getSource().sendSuccess(() -> Component.literal("/" + line), false);
                    }
 
                    return usage.size();
                })
                .then(
                    Commands.argument("command", StringArgumentType.greedyString())
                        .executes(
                            s -> {
                                ParseResults<CommandSourceStack> command = dispatcher.parse(StringArgumentType.getString(s, "command"), s.getSource());
                                if (command.getContext().getNodes().isEmpty()) {
                                    throw ERROR_FAILED.create();
                                } else {
                                    Map<CommandNode<CommandSourceStack>, String> usage = dispatcher.getSmartUsage(
                                        Iterables.getLast(command.getContext().getNodes()).getNode(), s.getSource()
                                    );
 
                                    for (String line : usage.values()) {
                                        s.getSource().sendSuccess(() -> Component.literal("/" + command.getReader().getString() + " " + line), false);
                                    }
 
                                    return usage.size();
                                }
                            }
                        )
                )
        );
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.argument(), Commands.literal()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.literal(), Component.translatable()