From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Thu, 14 Jan 2021 16:48:10 -0600
Subject: [PATCH] Fix stuck in portals


diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 85ffb2e72dbf08604c004732f17aee9ec7e1ff9d..49a1447bae91294a23ccab27c2809bea0c4c90a3 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2424,12 +2424,15 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
         return new Vec2F(this.pitch, this.yaw);
     }
 
+    public BlockPosition portalPos = BlockPosition.ZERO; // Purpur
     public void d(BlockPosition blockposition) {
         if (this.ai()) {
+            if (!(world.purpurConfig.playerFixStuckPortal && this instanceof EntityPlayer && !blockposition.equals(portalPos))) // Purpur
             this.resetPortalCooldown();
         } else if (world.purpurConfig.entitiesCanUsePortals || this instanceof EntityPlayer) { // Purpur
             if (!this.world.isClientSide && !blockposition.equals(this.ac)) {
                 this.ac = blockposition.immutableCopy();
+                portalPos = BlockPosition.ZERO; // Purpur
             }
 
             this.inPortal = true;
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 44a10c656c9b131c8889da81b7999dc492077e58..ac9238e1de65efe9fea7d9e623478c61066e8d68 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -1161,6 +1161,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
                 playerlist.d(this);
                 worldserver1.removePlayer(this);
                 this.dead = false;
+                this.portalPos = MCUtil.toBlockPosition(exit); // Purpur
 
                 // CraftBukkit end
                 this.spawnIn(worldserver);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index a494a9e15456cf684c62957e8563ef06627695f9..c268ec1b3b3e558283d869629079049343b2f15d 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -350,6 +350,11 @@ public class PurpurWorldConfig {
         });
     }
 
+    public boolean playerFixStuckPortal = false;
+    private void playerFixStuckPortal() {
+        playerFixStuckPortal = getBoolean("gameplay-mechanics.player.fix-stuck-in-portal", playerFixStuckPortal);
+    }
+
     public boolean teleportIfOutsideBorder = false;
     private void teleportIfOutsideBorder() {
         teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
