From dc9b151b648c62a659aa9f94110845c50ea67271 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Fri, 11 Dec 2020 08:18:32 +0100 Subject: [PATCH] Fixes #42 --- gradle.properties | 6 +++--- .../samo_lego/simpleauth/event/AuthEventHandler.java | 11 +++++------ .../simpleauth/event/entity/player/ChatCallback.java | 6 +++--- .../mixin/MixinServerPlayNetworkHandler.java | 9 ++++----- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/gradle.properties b/gradle.properties index c445787..2c47151 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx1G # Fabric properties minecraft_version=1.16.4 -yarn_mappings=1.16.4+build.1 -loader_version=0.10.6+build.214 +yarn_mappings=1.16.4+build.7 +loader_version=0.10.8 #Fabric api -fabric_version=0.25.1+build.416-1.16 +fabric_version=0.28.0+1.16 # Mod Properties mod_version = 1.7.3 diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 90b79e2..760d4cf 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -117,7 +117,7 @@ public class AuthEventHandler { // Setting the session expire time if(config.main.sessionTimeoutTime != -1) - playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000; + playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000L; } else if(config.main.spawnOnJoin) { ((PlayerAuth) player).hidePosition(false); @@ -128,14 +128,13 @@ public class AuthEventHandler { } // Player chatting - public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) { + public static ActionResult onPlayerChat(PlayerEntity player, String message) { // Getting the message to then be able to check it - String msg = chatMessageC2SPacket.getChatMessage(); if( !((PlayerAuth) player).isAuthenticated() && - !msg.startsWith("/login") && - !msg.startsWith("/register") && - (!config.experimental.allowChat || msg.startsWith("/")) + !message.startsWith("/login") && + !message.startsWith("/register") && + (!config.experimental.allowChat || message.startsWith("/")) ) { player.sendMessage(((PlayerAuth) player).getAuthMessage(), false); return ActionResult.FAIL; diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java index 0257117..ae1549f 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java +++ b/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java @@ -7,9 +7,9 @@ import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; import net.minecraft.util.ActionResult; public interface ChatCallback { - Event EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, chatMessageC2SPacket) -> { + Event EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, message) -> { for (ChatCallback event : listeners) { - ActionResult result = event.onPlayerChat(player, chatMessageC2SPacket); + ActionResult result = event.onPlayerChat(player, message); if (result != ActionResult.PASS) { return result; @@ -18,5 +18,5 @@ public interface ChatCallback { return ActionResult.PASS; }); - ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket); + ActionResult onPlayerChat(PlayerEntity player, String message); } \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java index 223f6ff..4437a03 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java @@ -24,17 +24,16 @@ public abstract class MixinServerPlayNetworkHandler { public ServerPlayerEntity player; @Inject( - method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V", + method = "method_31286(Ljava/lang/String;)V", at = @At( value = "INVOKE", - // Thanks to Liach for helping me out! - target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V", + target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V", shift = At.Shift.AFTER ), cancellable = true ) - private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket, CallbackInfo ci) { - ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, chatMessageC2SPacket); + private void onPlayerChat(String message, CallbackInfo ci) { + ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, message); if (result == ActionResult.FAIL) { ci.cancel(); }