DefaultGameModeCommands .java

net.minecraft.server.commands.DefaultGameModeCommands (class, 28 lines): members: register. strings: "commands.defaultgamemode.success", "defaultgamemode".

net.minecraft.server.commandsclass28 linesserver1.1 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

String literals (3)

"defaultgamemode"
"gamemode"
"commands.defaultgamemode.success"

Code Graph: Dependencies (6)

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

Full Source

DefaultGameModeCommands.java28 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.mojang.brigadier.CommandDispatcher;
4
import net.minecraft.commands.CommandSourceStack;
5
import net.minecraft.commands.Commands;
6
import net.minecraft.commands.arguments.GameModeArgument;
7
import net.minecraft.network.chat.Component;
8
import net.minecraft.server.MinecraftServer;
9
import net.minecraft.world.level.GameType;
10
11
public class DefaultGameModeCommands {
12
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
13
		dispatcher.register(
14
			Commands.literal("defaultgamemode")
15
				.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
16
				.then(Commands.argument("gamemode", GameModeArgument.gameMode()).executes(c -> setMode(c.getSource(), GameModeArgument.getGameMode(c, "gamemode"))))
17
		);
18
	}
19
20
	private static int setMode(final CommandSourceStack source, final GameType type) {
21
		MinecraftServer server = source.getServer();
22
		server.setDefaultGameType(type);
23
		int count = server.enforceGameTypeForPlayers(server.getForcedGameType());
24
		source.sendSuccess(() -> Component.translatable("commands.defaultgamemode.success", type.getLongDisplayName()), true);
25
		return count;
26
	}
27
}
28

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