package moe.ymc.acron.mixin; import com.mojang.authlib.GameProfile; import moe.ymc.acron.s2c.Entity; import moe.ymc.acron.s2c.EventQueue; import moe.ymc.acron.s2c.event.EventDisconnected; import moe.ymc.acron.s2c.event.EventPlayerJoined; import net.minecraft.network.ClientConnection; import net.minecraft.server.network.ServerLoginNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; 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(ServerLoginNetworkHandler.class) public class ServerLoginNetworkHandlerMixin { private static final Logger AC_LOGGER = LogManager.getLogger(); @Shadow @Nullable GameProfile profile; @Shadow @Final public ClientConnection connection; @Inject(at = @At("RETURN"), method = "onDisconnected") private void onDisconnected(Text reason, CallbackInfo ci) { EventQueue.enqueue(new EventDisconnected(profile == null ? null : new Entity(profile), reason.getString())); } @Inject(at = @At("RETURN"), method = "addToServer") private void addToServer(ServerPlayerEntity entity, CallbackInfo ci) { AC_LOGGER.debug("addToServer: {}", entity.getUuid()); EventQueue.enqueue(new EventPlayerJoined(new Entity(entity))); } }