From 653230e5342bee6d98d50feb74f77212158aedce Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Tue, 26 Nov 2019 22:11:56 +0100 Subject: [PATCH] Update to 1.15pre2 Added chat protection and movement protection. Mod should now enter polishing state. --- gradle.properties | 13 ++++--- .../simpleauth/event/AuthEventHandler.java | 8 ++--- .../simpleauth/mixin/MixinPlayerEntity.java | 6 ++-- .../mixin/MixinServerPlayNetworkHandler.java | 35 +++++++++++++------ src/main/resources/mixins.simpleauth.json | 2 +- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/gradle.properties b/gradle.properties index 228331c..bdd5fcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,13 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G -# Fabric Properties - minecraft_version=1.15-pre1 - yarn_mappings=1.15-pre1+build.3 - loader_version=0.7.1+build.173 +# Fabric properties +minecraft_version=1.15-pre2 +yarn_mappings=1.15-pre2+build.3 +loader_version=0.7.1+build.173 -# Dependencies - # Fabric API - fabric_version=0.4.13+build.264-1.15 +#Fabric api +fabric_version=0.4.16+build.268-1.15 # Mod Properties mod_version = 1.0.0 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 ed312f5..50394e7 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -35,20 +35,16 @@ public class AuthEventHandler { // todo public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) { String msg = chatMessageC2SPacket.getChatMessage(); - System.out.println(msg); - if(!SimpleAuth.authenticatedUsers.contains(player) || !msg.startsWith("/login") || !msg.startsWith("/register")) { - System.out.println("Ok."); + if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) { player.sendMessage(notAuthenticated); return ActionResult.FAIL; } - System.out.println("Pass "+ msg.startsWith("/login")+msg.startsWith("/register")); return ActionResult.PASS; } //todo public static ActionResult onPlayerMove(PlayerEntity player) { if(!SimpleAuth.authenticatedUsers.contains(player)) { - System.out.println("Ok. Moved & should fail. AuthEventHandler"); - player.sendMessage(notAuthenticated); + // TP player back? return ActionResult.FAIL; } return ActionResult.PASS; diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java index fb13c31..d1d2de7 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java @@ -26,10 +26,12 @@ public abstract class MixinPlayerEntity { ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player); if (result == ActionResult.FAIL) { - // Canceling the item drop, as well as giving the items back to player - cir.cancel(); + // Canceling the item drop, as well as giving the items back to player (and updating inv with packet) player.giveItemStack(stack); + + player.inventory.updateItems(); playerContainer.sendContentUpdates(); + cir.cancel(); } } } \ 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 a8d3621..22043f3 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java @@ -12,7 +12,6 @@ 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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ServerPlayNetworkHandler.class) public class MixinServerPlayNetworkHandler { @@ -20,24 +19,38 @@ public class MixinServerPlayNetworkHandler { public ServerPlayerEntity player; // TODO - @Inject(method = "onChatMessage", at = @At(value = "HEAD"), cancellable = true) - private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfoReturnable cir) { + @Inject( + method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)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", + shift = At.Shift.AFTER + ), + cancellable = true + ) + private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfo ci) { ActionResult result = OnChatCallback.EVENT.invoker().onPlayerChat(player, chatMessageC2SPacket_1); - - System.out.println("Mixined"); if (result == ActionResult.FAIL) { - cir.cancel(); + ci.cancel(); } } // TODO - @Inject(method="onPlayerMove", at = @At(value = "HEAD"), cancellable = true) - private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo cir) { + @Inject( + method="onPlayerMove(Lnet/minecraft/server/network/packet/PlayerMoveC2SPacket;)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", + shift = At.Shift.AFTER + ), + cancellable = true + ) + private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) { ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player); - - System.out.println("Player move"); if (result == ActionResult.FAIL) { - cir.cancel(); + ci.cancel(); } } } diff --git a/src/main/resources/mixins.simpleauth.json b/src/main/resources/mixins.simpleauth.json index 5d45aef..90ef875 100644 --- a/src/main/resources/mixins.simpleauth.json +++ b/src/main/resources/mixins.simpleauth.json @@ -5,7 +5,7 @@ "mixins": [ ], "server": [ - + "MixinServerPlayNetworkHandler", "MixinPlayerManager", "MixinPlayerEntity" ],