package org.dynmap.fabric_1_18.mixin;

import net.minecraft.server.filter.TextStream;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import org.dynmap.fabric_1_18.event.ServerChatEvents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkHandlerMixin {
    @Shadow
    public ServerPlayerEntity player;

    @Inject(
            method = "handleMessage",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
                    shift = At.Shift.BEFORE
            )
    )
    public void onGameMessage(TextStream.Message message, CallbackInfo info) {
        ServerChatEvents.EVENT.invoker().onChatMessage(player, message.getRaw());
    }
}

@@ -57,150 +57,554 @@
 aft.
-server.filter.TextStream;%0Aimport net.minecraft.server.network.ServerPlayNetworkHandler;%0Aimport net.minecraft.server.network.ServerPlayerEntity
+block.BlockState;%0Aimport net.minecraft.block.entity.BlockEntity;%0Aimport net.minecraft.block.entity.SignBlockEntity;%0Aimport net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;%0Aimport net.minecraft.server.filter.TextStream;%0Aimport net.minecraft.server.network.ServerPlayNetworkHandler;%0Aimport net.minecraft.server.network.ServerPlayerEntity;%0Aimport net.minecraft.server.world.ServerWorld;%0Aimport net.minecraft.text.LiteralText;%0Aimport net.minecraft.util.math.BlockPos;%0A%0Aimport java.util.List;%0A%0Aimport org.dynmap.fabric_1_18.event.BlockEvents
 ;%0Aim
@@ -909,16 +909,84 @@
 ackInfo;
+%0Aimport org.spongepowered.asm.mixin.injection.callback.LocalCapture;
 %0A%0A@Mixin
@@ -1651,10 +1651,1139 @@
 ;%0A    %7D%0A
-%7D
 %0A
+    @Inject(%0A            method = %22onSignUpdate%22,%0A            at = @At(%0A                    value = %22INVOKE%22,%0A                    target = %22Lnet/minecraft/block/entity/SignBlockEntity;markDirty()V%22,%0A                    shift = At.Shift.BEFORE%0A            ),%0A            locals = LocalCapture.CAPTURE_FAILHARD%0A    )%0A    public void onSignUpdate(UpdateSignC2SPacket packet, List%3CTextStream.Message%3E signText, CallbackInfo info,%0A            ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, SignBlockEntity signBlockEntity)%0A    %7B%0A        // Pull the raw text from the input.%0A        String%5B%5D rawTexts = new String%5B4%5D;%0A        for (int i=0; i%3CsignText.size(); i++)%0A            rawTexts%5Bi%5D = signText.get(i).getRaw();%0A%0A        // Fire the event.%0A        BlockEvents.SIGN_CHANGE_EVENT.invoker().onSignChange(serverWorld, blockPos, rawTexts, blockState.getMaterial(), player);%0A%0A        // Put the (possibly updated) texts in the sign. Ignore filtering (is this OK?).%0A        for (int i=0; i%3CsignText.size(); i++)%0A            signBlockEntity.setTextOnRow(i, new LiteralText(rawTexts%5Bi%5D));%0A    %7D%0A%7D

add ServerPlayNetworkHandlerMixin.onSignUpdate()