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

25 lines
1 KiB
Java

package net.minecraft.server.commands;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.MessageArgument;
import net.minecraft.network.chat.ChatType;
import net.minecraft.server.players.PlayerList;
public class SayCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("say")
.requires(commandSourceStack -> commandSourceStack.hasPermission(2))
.then(Commands.argument("message", MessageArgument.message()).executes(commandContext -> {
MessageArgument.resolveChatMessage(commandContext, "message", playerChatMessage -> {
CommandSourceStack commandSourceStack = commandContext.getSource();
PlayerList playerList = commandSourceStack.getServer().getPlayerList();
playerList.broadcastChatMessage(playerChatMessage, commandSourceStack, ChatType.bind(ChatType.SAY_COMMAND, commandSourceStack));
});
return 1;
}))
);
}
}