minecraft-src/net/minecraft/server/commands/TellRawCommand.java
2025-07-04 01:41:11 +03:00

39 lines
1.3 KiB
Java

package net.minecraft.server.commands;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.ComponentArgument;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.server.level.ServerPlayer;
public class TellRawCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
dispatcher.register(
Commands.literal("tellraw")
.requires(commandSourceStack -> commandSourceStack.hasPermission(2))
.then(
Commands.argument("targets", EntityArgument.players())
.then(
Commands.argument("message", ComponentArgument.textComponent(context))
.executes(
commandContext -> {
int i = 0;
for (ServerPlayer serverPlayer : EntityArgument.getPlayers(commandContext, "targets")) {
serverPlayer.sendSystemMessage(
ComponentUtils.updateForEntity(commandContext.getSource(), ComponentArgument.getComponent(commandContext, "message"), serverPlayer, 0), false
);
i++;
}
return i;
}
)
)
)
);
}
}