From 4187a855fb935e92924457660df33d22006845a0 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sat, 30 Nov 2019 22:07:23 +0100 Subject: [PATCH] Disable movement Update player's position --- gradle.properties | 8 ++++---- .../samo_lego/simpleauth/event/AuthEventHandler.java | 9 +++++---- .../samo_lego/simpleauth/mixin/MixinPlayerEntity.java | 6 +++--- .../mixin/MixinServerPlayNetworkHandler.java | 11 +++++++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index bdd5fcf..153ad76 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric properties -minecraft_version=1.15-pre2 -yarn_mappings=1.15-pre2+build.3 -loader_version=0.7.1+build.173 +minecraft_version=1.15-pre3 +yarn_mappings=1.15-pre3+build.2 +loader_version=0.7.2+build.174 #Fabric api -fabric_version=0.4.16+build.268-1.15 +fabric_version=0.4.18+build.271-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 50394e7..4b26195 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -1,7 +1,10 @@ package org.samo_lego.simpleauth.event; +import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; +import net.minecraft.client.network.packet.InventoryS2CPacket; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketEncoder; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.ChatMessageC2SPacket; import net.minecraft.text.TranslatableText; @@ -32,19 +35,17 @@ public class AuthEventHandler { SimpleAuth.authenticatedUsers.remove(player); } - // todo public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) { String msg = chatMessageC2SPacket.getChatMessage(); - if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) { + if(!SimpleAuth.authenticatedUsers.contains(player) && !msg.startsWith("/login") && !msg.startsWith("/register")) { player.sendMessage(notAuthenticated); return ActionResult.FAIL; } return ActionResult.PASS; } - //todo + // Player movement public static ActionResult onPlayerMove(PlayerEntity player) { if(!SimpleAuth.authenticatedUsers.contains(player)) { - // 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 d1d2de7..597078c 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java @@ -1,10 +1,12 @@ package org.samo_lego.simpleauth.mixin; +import net.minecraft.client.network.packet.InventoryS2CPacket; import net.minecraft.container.PlayerContainer; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.packet.UpdateSelectedSlotC2SPacket; import net.minecraft.util.ActionResult; import org.samo_lego.simpleauth.event.item.DropItemCallback; import org.spongepowered.asm.mixin.Final; @@ -20,7 +22,7 @@ public abstract class MixinPlayerEntity { @Shadow @Final public PlayerContainer playerContainer; // Thanks to PR https://github.com/FabricMC/fabric/pull/260 and AbusedLib https://github.com/abused/AbusedLib - @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("HEAD"), cancellable = true) + @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("INVOKE"), cancellable = true) private void dropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower, CallbackInfoReturnable cir) { ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player); @@ -28,8 +30,6 @@ public abstract class MixinPlayerEntity { if (result == ActionResult.FAIL) { // 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(); } 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 22043f3..9aaa6b0 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java @@ -1,5 +1,9 @@ package org.samo_lego.simpleauth.mixin; +import net.minecraft.client.network.packet.InventoryS2CPacket; +import net.minecraft.client.network.packet.PlayerSpawnPositionS2CPacket; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.Packet; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.ChatMessageC2SPacket; @@ -14,11 +18,12 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayNetworkHandler.class) -public class MixinServerPlayNetworkHandler { +public abstract class MixinServerPlayNetworkHandler { @Shadow public ServerPlayerEntity player; - // TODO + @Shadow public abstract void sendPacket(Packet packet_1); + @Inject( method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V", at = @At( @@ -50,6 +55,8 @@ public class MixinServerPlayNetworkHandler { private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) { ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player); if (result == ActionResult.FAIL) { + // A bit ugly, I know. (we need to update player position) + player.teleport(player.getX(), player.getY(), player.getZ()); ci.cancel(); } }