DialogCommand.java

net.minecraft.server.commands.DialogCommand

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

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

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

参数:

  • dispatcher: CommandDispatcher
  • context: CommandBuildContext

说明:

TODO

private static int showDialog(CommandSourceStack sender, Collection<ServerPlayer> targets, Holder<Dialog> dialog) @ L47

  • 方法名:showDialog
  • 源码定位:L47
  • 返回类型:int
  • 修饰符:private static

参数:

  • sender: CommandSourceStack
  • targets: Collection
  • dialog: Holder

说明:

TODO

private static int clearDialog(CommandSourceStack sender, Collection<ServerPlayer> targets) @ L61

  • 方法名:clearDialog
  • 源码定位:L61
  • 返回类型:int
  • 修饰符:private static

参数:

  • sender: CommandSourceStack
  • targets: Collection

说明:

TODO

代码

public class DialogCommand {
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
        dispatcher.register(
            Commands.literal("dialog")
                .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
                .then(
                    Commands.literal("show")
                        .then(
                            Commands.argument("targets", EntityArgument.players())
                                .then(
                                    Commands.argument("dialog", ResourceOrIdArgument.dialog(context))
                                        .executes(
                                            c -> showDialog(
                                                (CommandSourceStack)c.getSource(),
                                                EntityArgument.getPlayers(c, "targets"),
                                                ResourceOrIdArgument.getDialog(c, "dialog")
                                            )
                                        )
                                )
                        )
                )
                .then(
                    Commands.literal("clear")
                        .then(
                            Commands.argument("targets", EntityArgument.players())
                                .executes(c -> clearDialog(c.getSource(), EntityArgument.getPlayers(c, "targets")))
                        )
                )
        );
    }
 
    private static int showDialog(CommandSourceStack sender, Collection<ServerPlayer> targets, Holder<Dialog> dialog) {
        for (ServerPlayer target : targets) {
            target.openDialog(dialog);
        }
 
        if (targets.size() == 1) {
            sender.sendSuccess(() -> Component.translatable("commands.dialog.show.single", targets.iterator().next().getDisplayName()), true);
        } else {
            sender.sendSuccess(() -> Component.translatable("commands.dialog.show.multiple", targets.size()), true);
        }
 
        return targets.size();
    }
 
    private static int clearDialog(CommandSourceStack sender, Collection<ServerPlayer> targets) {
        for (ServerPlayer target : targets) {
            target.connection.send(ClientboundClearDialogPacket.INSTANCE);
        }
 
        if (targets.size() == 1) {
            sender.sendSuccess(() -> Component.translatable("commands.dialog.clear.single", targets.iterator().next().getDisplayName()), true);
        } else {
            sender.sendSuccess(() -> Component.translatable("commands.dialog.clear.multiple", targets.size()), true);
        }
 
        return targets.size();
    }
}

引用的其他类

  • CommandBuildContext

    • 引用位置: 参数
  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

    • 引用位置: 方法调用
    • 关联成员: EntityArgument.getPlayers(), EntityArgument.players()
  • ResourceOrIdArgument

    • 引用位置: 方法调用
    • 关联成员: ResourceOrIdArgument.dialog(), ResourceOrIdArgument.getDialog()
  • Holder

    • 引用位置: 参数
  • Component

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

    • 引用位置: 参数
  • ServerPlayer

    • 引用位置: 参数