use of org.spongepowered.vanilla.chat.ChatFormatter in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Vanilla method vanilla$onProcessChatMessage.
@Inject(method = "handleChat(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void vanilla$onProcessChatMessage(String var1, CallbackInfo ci, net.minecraft.network.chat.Component component) {
ChatFormatter.formatChatComponent((net.minecraft.network.chat.TranslatableComponent) component);
final ServerPlayer player = (ServerPlayer) this.player;
final PlayerChatFormatter chatFormatter = player.chatFormatter();
final TextComponent rawMessage = Component.text(var1);
try (CauseStackManager.StackFrame frame = PhaseTracker.SERVER.pushCauseFrame()) {
frame.pushCause(this.player);
final Audience audience = (Audience) this.server;
final PlayerChatEvent event = SpongeEventFactory.createPlayerChatEvent(frame.currentCause(), audience, Optional.of(audience), chatFormatter, Optional.of(chatFormatter), rawMessage, rawMessage);
if (SpongeCommon.post(event)) {
ci.cancel();
} else {
event.chatFormatter().ifPresent(formatter -> event.audience().map(SpongeAdventure::unpackAudiences).ifPresent(targets -> {
for (Audience target : targets) {
formatter.format(player, target, event.message(), event.originalMessage()).ifPresent(formattedMessage -> target.sendMessage(player, formattedMessage));
}
}));
}
}
}
Aggregations