From 27b8bf91169642a61f9cf888432cf018773d7df0 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 8 Aug 2017 20:35:29 +1000
Subject: [PATCH] SPIGOT-3497: Cancelled EntityPortalEvent leads to incorrect
 behaviour

---
 nms-patches/Entity.patch | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/nms-patches/Entity.patch b/nms-patches/Entity.patch
index d4882f35de..2bae50a00f 100644
--- a/nms-patches/Entity.patch
+++ b/nms-patches/Entity.patch
@@ -539,7 +539,7 @@
          }
  
      }
-@@ -1893,19 +2236,75 @@
+@@ -1893,19 +2236,76 @@
          if (!this.world.isClientSide && !this.dead) {
              this.world.methodProfiler.a("changeDimension");
              MinecraftServer minecraftserver = this.C_();
@@ -583,6 +583,7 @@
 +            event.useTravelAgent(useTravelAgent);
 +            event.getEntity().getServer().getPluginManager().callEvent(event);
 +            if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !this.isAlive()) {
++                agent.setCanCreatePortal(oldCanCreate);
 +                return null;
 +            }
 +            exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
@@ -618,7 +619,7 @@
              BlockPosition blockposition;
  
              if (i == 1) {
-@@ -1934,12 +2333,18 @@
+@@ -1934,12 +2334,18 @@
                  blockposition = new BlockPosition(this);
              }
  
@@ -638,7 +639,7 @@
                  if (j == 1 && i == 1) {
                      BlockPosition blockposition1 = worldserver1.q(worldserver1.getSpawn());
  
-@@ -1947,6 +2352,7 @@
+@@ -1947,6 +2353,7 @@
                  } else {
                      entity.setPositionRotation(blockposition, entity.yaw, entity.pitch);
                  }
@@ -646,7 +647,7 @@
  
                  boolean flag = entity.attachedToPlayer;
  
-@@ -1954,13 +2360,21 @@
+@@ -1954,13 +2361,21 @@
                  worldserver1.addEntity(entity);
                  entity.attachedToPlayer = flag;
                  worldserver1.entityJoinedWorld(entity, false);
@@ -669,7 +670,7 @@
              return entity;
          } else {
              return null;
-@@ -2064,6 +2478,11 @@
+@@ -2064,6 +2479,11 @@
      }
  
      public void setCustomName(String s) {
@@ -681,7 +682,7 @@
          this.datawatcher.set(Entity.aB, s);
      }
  
-@@ -2121,7 +2540,26 @@
+@@ -2121,7 +2541,26 @@
      }
  
      public void a(AxisAlignedBB axisalignedbb) {
@@ -709,7 +710,7 @@
      }
  
      public float getHeadHeight() {
-@@ -2295,7 +2733,7 @@
+@@ -2295,7 +2734,7 @@
          for (Iterator iterator = this.bF().iterator(); iterator.hasNext(); entity.a(oclass, set)) {
              entity = (Entity) iterator.next();
              if (oclass.isAssignableFrom(entity.getClass())) {