KillCommand .java

net.minecraft.server.commands.KillCommand (class): members: RESPONSE_KILL, register. strings: "commands.kill.success.multiple", "kill", "targets".

net.minecraft.server.commandsclass39 linesserver1.6 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

Fields & Constants (1)

RESPONSE_KILL

String literals (4)

"commands.kill.success.single"
"commands.kill.success.multiple"
"kill"
"targets"

Code Graph: Dependencies (6)

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

Full Source

KillCommand.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.collect.ImmutableList;
4
import com.mojang.brigadier.CommandDispatcher;
5
import com.mojang.brigadier.exceptions.CommandSyntaxException;
6
import java.util.Collection;
7
import net.minecraft.commands.CommandSourceStack;
8
import net.minecraft.commands.Commands;
9
import net.minecraft.commands.arguments.EntityArgument;
10
import net.minecraft.network.chat.Component;
11
import net.minecraft.world.entity.Entity;
12
13
public class KillCommand {
14
	private static final CommandResponseTracker.Messages<Entity> RESPONSE_KILL = CommandResponseTracker.messages(
15
		(entity, var1) -> Component.translatable("commands.kill.success.single", entity.getDisplayName()),
16
		(entityCount, var1) -> Component.translatable("commands.kill.success.multiple", entityCount)
17
	);
18
19
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
20
		dispatcher.register(
21
			Commands.literal("kill")
22
				.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
23
				.executes(c -> kill(c.getSource(), ImmutableList.of(c.getSource().getEntityOrException())))
24
				.then(Commands.argument("targets", EntityArgument.entities()).executes(c -> kill(c.getSource(), EntityArgument.getEntities(c, "targets"))))
25
		);
26
	}
27
28
	private static int kill(final CommandSourceStack source, final Collection<? extends Entity> victims) throws CommandSyntaxException {
29
		CommandResponseTracker<Entity> tracker = CommandResponseTracker.create();
30
31
		for (Entity entity : victims) {
32
			entity.kill(source.getLevel());
33
			tracker.track(entity);
34
		}
35
36
		return tracker.sendFeedback(source, true, RESPONSE_KILL);
37
	}
38
}
39

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