use of org.spongepowered.api.event.message.PlayerChatEvent 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));
}
}));
}
}
}
use of org.spongepowered.api.event.message.PlayerChatEvent in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_API method simulateChat.
@Override
public PlayerChatEvent simulateChat(final Component message, final Cause cause) {
Objects.requireNonNull(message, "message");
Objects.requireNonNull(cause, "cause");
final PlayerChatFormatter originalRouter = this.chatFormatter();
final Audience audience = (Audience) this.server;
final PlayerChatEvent event = SpongeEventFactory.createPlayerChatEvent(cause, audience, Optional.of(audience), originalRouter, Optional.of(originalRouter), message, message);
if (!SpongeCommon.post(event)) {
event.chatFormatter().ifPresent(formatter -> event.audience().map(SpongeAdventure::unpackAudiences).ifPresent(targets -> {
for (final Audience target : targets) {
formatter.format(this, target, event.message(), event.originalMessage()).ifPresent(formattedMessage -> target.sendMessage(this, formattedMessage));
}
}));
}
return event;
}
Aggregations