From b250a524263568501615fbaf748216ddb949eebe Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Mon, 18 May 2020 13:22:43 +0200 Subject: [PATCH] Finishing portal rescue overhaul --- .../org/samo_lego/simpleauth/SimpleAuth.java | 14 ++++++++++++-- .../simpleauth/event/AuthEventHandler.java | 17 +++++++++-------- ...s.java => BlockUpdateS2CPacketAccessor.java} | 2 +- src/main/resources/mixins.simpleauth.json | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) rename src/main/java/org/samo_lego/simpleauth/mixin/{BlockUpdateS2CPacketAccess.java => BlockUpdateS2CPacketAccessor.java} (90%) diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 9cd1b74..251c895 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -11,6 +11,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -157,8 +159,16 @@ public class SimpleAuth implements DedicatedServerModInitializer { if(config.main.spawnOnJoin) teleportPlayer(player, false); - // Updating chunk if needed (if portal rescue action happened) - if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) + // Updating blocks if needed (if portal rescue action happened) + if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) { + World world = player.getEntityWorld(); + BlockPos pos = player.getBlockPos(); + + // Sending updates to portal blocks + // This is technically not needed, but it cleans the "messed portal" on the client + world.updateListeners(pos, world.getBlockState(pos), world.getBlockState(pos), 3); + world.updateListeners(pos.up(), world.getBlockState(pos.up()), world.getBlockState(pos.up()), 3); + } deauthenticatedUsers.remove(convertUuid(player)); 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 ea36b95..231f52f 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -14,7 +14,7 @@ import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; -import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccess; +import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor; import org.samo_lego.simpleauth.storage.PlayerCache; import java.net.SocketAddress; @@ -96,8 +96,10 @@ public class AuthEventHandler { else player.sendMessage(new LiteralText(config.lang.notRegistered), false); } - else + else { deauthenticatePlayer(player); + playerCache = deauthenticatedUsers.get(uuid); + } if(config.main.spawnOnJoin) teleportPlayer(player, true); @@ -105,23 +107,22 @@ public class AuthEventHandler { // Tries to rescue player from nether portal if(config.main.tryPortalRescue && player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) { - PlayerCache newPlayerCache = deauthenticatedUsers.get(uuid); BlockPos pos = player.getBlockPos(); // Faking portal blocks to be air BlockUpdateS2CPacket feetPacket = new BlockUpdateS2CPacket(); - ((BlockUpdateS2CPacketAccess) feetPacket).setState(new BlockState(Blocks.AIR, null)); - ((BlockUpdateS2CPacketAccess) feetPacket).setBlockPos(pos); + ((BlockUpdateS2CPacketAccessor) feetPacket).setState(new BlockState(Blocks.AIR, null)); + ((BlockUpdateS2CPacketAccessor) feetPacket).setBlockPos(pos); player.networkHandler.sendPacket(feetPacket); BlockUpdateS2CPacket headPacket = new BlockUpdateS2CPacket(); - ((BlockUpdateS2CPacketAccess) headPacket).setState(new BlockState(Blocks.AIR, null)); - ((BlockUpdateS2CPacketAccess) headPacket).setBlockPos(pos.up()); + ((BlockUpdateS2CPacketAccessor) headPacket).setState(new BlockState(Blocks.AIR, null)); + ((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up()); player.networkHandler.sendPacket(headPacket); // Teleporting player to the middle of the block player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); - newPlayerCache.wasInPortal = true; + playerCache.wasInPortal = true; } } diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccess.java b/src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccessor.java similarity index 90% rename from src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccess.java rename to src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccessor.java index b3778ce..3e63319 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccess.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/BlockUpdateS2CPacketAccessor.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(BlockUpdateS2CPacket.class) -public interface BlockUpdateS2CPacketAccess { +public interface BlockUpdateS2CPacketAccessor { @Accessor("state") void setState(BlockState state); diff --git a/src/main/resources/mixins.simpleauth.json b/src/main/resources/mixins.simpleauth.json index 5b109a5..ddab9d2 100644 --- a/src/main/resources/mixins.simpleauth.json +++ b/src/main/resources/mixins.simpleauth.json @@ -4,7 +4,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [], "server": [ - "BlockUpdateS2CPacketAccess", + "BlockUpdateS2CPacketAccessor", "MixinPlayerEntity", "MixinPlayerManager", "MixinServerPlayNetworkHandler",