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/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
index 35b26e520be7c06b296ae219be18ef38a1de5dfc..9cedd9c7aa79540710ae248c61eeb7076a84fca4 100644
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
@@ -1293,6 +1293,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/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index ee1f0ccce5c5c920b2595ced9e72fd1544e2459a..fcbbf100990faf60250357b744cbd58701da0b0c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2520,12 +2520,15 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
         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/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index a3e6844602b8baea643ec1ae65ef7161789cac6c..8e4843e47abf4a084653b0e338eb72f1e5c1e1b3 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -362,6 +362,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);
