TeamMsgCommand.java
net.minecraft.server.commands.TeamMsgCommand
信息
- 全限定名:net.minecraft.server.commands.TeamMsgCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/TeamMsgCommand.java
- 起始行号:L22
- 职责:
TODO
字段/常量
-
SUGGEST_STYLE- 类型:
Style - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
ERROR_NOT_ON_TEAM- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L28
- 方法名:register
- 源码定位:L28
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static void sendMessage(CommandSourceStack source, Entity entity, PlayerTeam team, List<ServerPlayer> receivers, PlayerChatMessage message) @ L60
- 方法名:sendMessage
- 源码定位:L60
- 返回类型:void
- 修饰符:private static
参数:
- source: CommandSourceStack
- entity: Entity
- team: PlayerTeam
- receivers: List
- message: PlayerChatMessage
说明:
TODO
代码
public class TeamMsgCommand {
private static final Style SUGGEST_STYLE = Style.EMPTY
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.type.team.hover")))
.withClickEvent(new ClickEvent.SuggestCommand("/teammsg "));
private static final SimpleCommandExceptionType ERROR_NOT_ON_TEAM = new SimpleCommandExceptionType(Component.translatable("commands.teammsg.failed.noteam"));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
LiteralCommandNode<CommandSourceStack> msg = dispatcher.register(
Commands.literal("teammsg")
.then(
Commands.argument("message", MessageArgument.message())
.executes(
c -> {
CommandSourceStack source = c.getSource();
Entity entity = source.getEntityOrException();
PlayerTeam team = entity.getTeam();
if (team == null) {
throw ERROR_NOT_ON_TEAM.create();
} else {
List<ServerPlayer> receivers = source.getServer()
.getPlayerList()
.getPlayers()
.stream()
.filter(receiver -> receiver == entity || receiver.getTeam() == team)
.toList();
if (!receivers.isEmpty()) {
MessageArgument.resolveChatMessage(c, "message", message -> sendMessage(source, entity, team, receivers, message));
}
return receivers.size();
}
}
)
)
);
dispatcher.register(Commands.literal("tm").redirect(msg));
}
private static void sendMessage(CommandSourceStack source, Entity entity, PlayerTeam team, List<ServerPlayer> receivers, PlayerChatMessage message) {
Component teamName = team.getFormattedDisplayName().withStyle(SUGGEST_STYLE);
ChatType.Bound incomingChatType = ChatType.bind(ChatType.TEAM_MSG_COMMAND_INCOMING, source).withTargetName(teamName);
ChatType.Bound outgoingChatType = ChatType.bind(ChatType.TEAM_MSG_COMMAND_OUTGOING, source).withTargetName(teamName);
OutgoingChatMessage tracked = OutgoingChatMessage.create(message);
boolean wasFullyFiltered = false;
for (ServerPlayer teamPlayer : receivers) {
ChatType.Bound chatType = teamPlayer == entity ? outgoingChatType : incomingChatType;
boolean filtered = source.shouldFilterMessageTo(teamPlayer);
teamPlayer.sendChatMessage(tracked, filtered, chatType);
wasFullyFiltered |= filtered && message.isFullyFiltered();
}
if (wasFullyFiltered) {
source.sendSystemMessage(PlayerList.CHAT_FILTERED_FULL);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
MessageArgument.message(), MessageArgument.resolveChatMessage()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ChatType.bind()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
ClickEvent.SuggestCommand(), SuggestCommand()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
HoverEvent.ShowText(), ShowText()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
OutgoingChatMessage.create()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: