SaveAllCommand .java

net.minecraft.server.commands.SaveAllCommand (class): members: ERROR_FAILED, register. strings: "commands.save.success", "commands.save.failed", "flush".

net.minecraft.server.commandsclass35 linesserver1.3 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

Fields & Constants (1)

ERROR_FAILED

String literals (5)

"commands.save.failed"
"save-all"
"flush"
"commands.save.saving"
"commands.save.success"

Code Graph: Dependencies (4)

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

Full Source

SaveAllCommand.java35 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.mojang.brigadier.CommandDispatcher;
4
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
6
import net.minecraft.commands.CommandSourceStack;
7
import net.minecraft.commands.Commands;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.server.MinecraftServer;
10
11
public class SaveAllCommand {
12
	private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.save.failed"));
13
14
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
15
		dispatcher.register(
16
			Commands.literal("save-all")
17
				.requires(Commands.hasPermission(Commands.LEVEL_OWNERS))
18
				.executes(c -> saveAll(c.getSource(), false))
19
				.then(Commands.literal("flush").executes(c -> saveAll(c.getSource(), true)))
20
		);
21
	}
22
23
	private static int saveAll(final CommandSourceStack source, final boolean flush) throws CommandSyntaxException {
24
		source.sendSuccess(() -> Component.translatable("commands.save.saving"), false);
25
		MinecraftServer server = source.getServer();
26
		boolean success = server.saveEverything(true, flush, true);
27
		if (!success) {
28
			throw ERROR_FAILED.create();
29
		}
30
31
		source.sendSuccess(() -> Component.translatable("commands.save.success"), true);
32
		return 1;
33
	}
34
}
35

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