Search in sources :

Example 1 with ChatType

use of net.minecraft.network.chat.ChatType 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));
                }
            }));
        }
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) Inventory(org.spongepowered.api.item.inventory.Inventory) NonNull(org.checkerframework.checker.nullness.qual.NonNull) RecipeBookMenu(net.minecraft.world.inventory.RecipeBookMenu) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) PlayerList(net.minecraft.server.players.PlayerList) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) ServerboundCustomPayloadPacket(net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket) CauseStackManager(org.spongepowered.api.event.CauseStackManager) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ServerGamePacketListener(net.minecraft.network.protocol.game.ServerGamePacketListener) LocalCapture(org.spongepowered.asm.mixin.injection.callback.LocalCapture) At(org.spongepowered.asm.mixin.injection.At) TextComponent(net.kyori.adventure.text.TextComponent) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) EngineConnection(org.spongepowered.api.network.EngineConnection) Sponge(org.spongepowered.api.Sponge) PlayerChatEvent(org.spongepowered.api.event.message.PlayerChatEvent) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) Group(org.spongepowered.asm.mixin.injection.Group) ChatType(net.minecraft.network.chat.ChatType) SpongeCommon(org.spongepowered.common.SpongeCommon) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) QueryTypes(org.spongepowered.api.item.inventory.query.QueryTypes) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) PlayerChatFormatter(org.spongepowered.api.entity.living.player.PlayerChatFormatter) Audience(net.kyori.adventure.audience.Audience) Recipe(net.minecraft.world.item.crafting.Recipe) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) ServerboundCustomPayloadPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundCustomPayloadPacketAccessor) ChatFormatter(org.spongepowered.vanilla.chat.ChatFormatter) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) PlayerChatEvent(org.spongepowered.api.event.message.PlayerChatEvent) Audience(net.kyori.adventure.audience.Audience) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PlayerChatFormatter(org.spongepowered.api.entity.living.player.PlayerChatFormatter) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Optional (java.util.Optional)1 UUID (java.util.UUID)1 Audience (net.kyori.adventure.audience.Audience)1 Component (net.kyori.adventure.text.Component)1 TextComponent (net.kyori.adventure.text.TextComponent)1 ChatType (net.minecraft.network.chat.ChatType)1 ServerGamePacketListener (net.minecraft.network.protocol.game.ServerGamePacketListener)1 ServerboundCustomPayloadPacket (net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)1 PlayerList (net.minecraft.server.players.PlayerList)1 RecipeBookMenu (net.minecraft.world.inventory.RecipeBookMenu)1 Recipe (net.minecraft.world.item.crafting.Recipe)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 Sponge (org.spongepowered.api.Sponge)1 PlayerChatFormatter (org.spongepowered.api.entity.living.player.PlayerChatFormatter)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 SpongeEventFactory (org.spongepowered.api.event.SpongeEventFactory)1 PlayerChatEvent (org.spongepowered.api.event.message.PlayerChatEvent)1