aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java
diff options
context:
space:
mode:
authorYuuta Liang <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
commit85045e1e4a15e0a5657d189e83dd202a2c37f2b0 (patch)
tree944bc9ee7a86bd413dfc940e210f21d2434ec7d3 /src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java
downloadacron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.gz
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.bz2
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.zip
First Commit
Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java')
-rw-r--r--src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java b/src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java
new file mode 100644
index 0000000..7e4115e
--- /dev/null
+++ b/src/main/java/moe/ymc/acron/mixin/ServerLoginNetworkHandlerMixin.java
@@ -0,0 +1,47 @@
+package moe.ymc.acron.mixin;
+
+import com.mojang.authlib.GameProfile;
+import moe.ymc.acron.s2c.Entity;
+import moe.ymc.acron.s2c.EventDisconnected;
+import moe.ymc.acron.s2c.EventPlayerJoined;
+import moe.ymc.acron.s2c.EventQueue;
+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 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) {
+ LOGGER.debug("addToServer: {}",
+ entity.getUuid());
+ EventQueue.enqueue(new EventPlayerJoined(new Entity(entity)));
+ }
+}