DefaultGameModeCommands.java

net.minecraft.server.commands.DefaultGameModeCommands

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

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

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

参数:

  • dispatcher: CommandDispatcher

说明:

TODO

private static int setMode(CommandSourceStack source, GameType type) @ L23

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

参数:

  • source: CommandSourceStack
  • type: GameType

说明:

TODO

代码

public class DefaultGameModeCommands {
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
            Commands.literal("defaultgamemode")
                .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
                .then(
                    Commands.argument("gamemode", GameModeArgument.gameMode())
                        .executes(c -> setMode(c.getSource(), GameModeArgument.getGameMode(c, "gamemode")))
                )
        );
    }
 
    private static int setMode(CommandSourceStack source, GameType type) {
        MinecraftServer server = source.getServer();
        server.setDefaultGameType(type);
        int count = server.enforceGameTypeForPlayers(server.getForcedGameType());
        source.sendSuccess(() -> Component.translatable("commands.defaultgamemode.success", type.getLongDisplayName()), true);
        return count;
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

    • 引用位置: 方法调用
    • 关联成员: GameModeArgument.gameMode(), GameModeArgument.getGameMode()
  • Component

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

    • 引用位置: 参数