ReloadCommand .java

net.minecraft.server.commands.ReloadCommand (class, 54 lines): members: reloadPacks, register, LOGGER. strings: "Failed to execute reload", "reload".

net.minecraft.server.commandsclass54 linesserver2.2 KB

API Surface (2)

void reloadPacks(final Collection<String> selectedPacks, final CommandSourceStack source)
void register(final CommandDispatcher<CommandSourceStack> dispatcher)

Fields & Constants (1)

LOGGER

String literals (4)

"Failed to execute reload"
"commands.reload.failure"
"reload"
"commands.reload.success"

Code Graph: Dependencies (6)

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

Full Source

ReloadCommand.java54 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.collect.Lists;
4
import com.mojang.brigadier.CommandDispatcher;
5
import com.mojang.logging.LogUtils;
6
import java.util.Collection;
7
import net.minecraft.commands.CommandSourceStack;
8
import net.minecraft.commands.Commands;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.server.MinecraftServer;
11
import net.minecraft.server.packs.repository.PackRepository;
12
import net.minecraft.world.level.storage.WorldData;
13
import org.slf4j.Logger;
14
15
public class ReloadCommand {
16
	private static final Logger LOGGER = LogUtils.getLogger();
17
18
	public static void reloadPacks(final Collection<String> selectedPacks, final CommandSourceStack source) {
19
		source.getServer().reloadResources(selectedPacks).exceptionally(throwable -> {
20
			LOGGER.warn("Failed to execute reload", throwable);
21
			source.sendFailure(Component.translatable("commands.reload.failure"));
22
			return null;
23
		});
24
	}
25
26
	private static Collection<String> discoverNewPacks(final PackRepository packRepository, final WorldData worldData, final Collection<String> currentPacks) {
27
		packRepository.reload();
28
		Collection<String> selected = Lists.newArrayList(currentPacks);
29
		Collection<String> disabled = worldData.getDataConfiguration().dataPacks().getDisabled();
30
31
		for (String pack : packRepository.getAvailableIds()) {
32
			if (!disabled.contains(pack) && !selected.contains(pack)) {
33
				selected.add(pack);
34
			}
35
		}
36
37
		return selected;
38
	}
39
40
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
41
		dispatcher.register(Commands.literal("reload").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)).executes(s -> {
42
			CommandSourceStack source = s.getSource();
43
			MinecraftServer server = source.getServer();
44
			PackRepository packRepository = server.getPackRepository();
45
			WorldData worldData = server.getWorldData();
46
			Collection<String> currentPacks = packRepository.getSelectedIds();
47
			Collection<String> newSelectedPacks = discoverNewPacks(packRepository, worldData, currentPacks);
48
			source.sendSuccess(() -> Component.translatable("commands.reload.success"), true);
49
			reloadPacks(newSelectedPacks, source);
50
			return 0;
51
		}));
52
	}
53
}
54

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