SaveAllCommand.java

net.minecraft.server.commands.SaveAllCommand

信息

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

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

构造器

方法

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

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

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

参数:

  • dispatcher: CommandDispatcher

说明:

TODO

private static int saveAll(CommandSourceStack source, boolean flush) @ L23

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

参数:

  • source: CommandSourceStack
  • flush: boolean

说明:

TODO

代码

public class SaveAllCommand {
    private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.save.failed"));
 
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
            Commands.literal("save-all")
                .requires(Commands.hasPermission(Commands.LEVEL_OWNERS))
                .executes(c -> saveAll(c.getSource(), false))
                .then(Commands.literal("flush").executes(c -> saveAll(c.getSource(), true)))
        );
    }
 
    private static int saveAll(CommandSourceStack source, boolean flush) throws CommandSyntaxException {
        source.sendSuccess(() -> Component.translatable("commands.save.saving"), false);
        MinecraftServer server = source.getServer();
        boolean success = server.saveEverything(true, flush, true);
        if (!success) {
            throw ERROR_FAILED.create();
        } else {
            source.sendSuccess(() -> Component.translatable("commands.save.success"), true);
            return 1;
        }
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

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