From 65fba7fb1041d1f722ec8c042964d99639830f23 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Thu, 21 May 2015 17:28:21 +1000
Subject: [PATCH] SPIGOT-834: Stop EnderMites from spawning when EnderPearl
 event is cancelled.

---
 nms-patches/EntityEnderPearl.patch | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/nms-patches/EntityEnderPearl.patch b/nms-patches/EntityEnderPearl.patch
index 645715b868..1129ef5b9b 100644
--- a/nms-patches/EntityEnderPearl.patch
+++ b/nms-patches/EntityEnderPearl.patch
@@ -1,5 +1,5 @@
---- /home/matt/mc-dev-private//net/minecraft/server/EntityEnderPearl.java	2015-02-26 22:40:22.523608140 +0000
-+++ src/main/java/net/minecraft/server/EntityEnderPearl.java	2015-02-26 22:40:22.523608140 +0000
+--- ../work/decompile-c2c33c10/net/minecraft/server/EntityEnderPearl.java	2015-05-21 17:27:14.743333223 +1000
++++ src/main/java/net/minecraft/server/EntityEnderPearl.java	2015-05-21 17:27:14.743333223 +1000
 @@ -1,5 +1,11 @@
  package net.minecraft.server;
  
@@ -12,12 +12,16 @@
  public class EntityEnderPearl extends EntityProjectile {
  
      private EntityLiving c;
-@@ -41,13 +47,27 @@
-                         this.world.addEntity(entityendermite);
-                     }
+@@ -33,21 +39,35 @@
+                 EntityPlayer entityplayer = (EntityPlayer) entityliving;
  
--                    if (entityliving.au()) {
--                        entityliving.mount((Entity) null);
+                 if (entityplayer.playerConnection.a().g() && entityplayer.world == this.world && !entityplayer.isSleeping()) {
+-                    if (this.random.nextFloat() < 0.05F && this.world.getGameRules().getBoolean("doMobSpawning")) {
+-                        EntityEndermite entityendermite = new EntityEndermite(this.world);
+-
+-                        entityendermite.a(true);
+-                        entityendermite.setPositionRotation(entityliving.locX, entityliving.locY, entityliving.locZ, entityliving.yaw, entityliving.pitch);
+-                        this.world.addEntity(entityendermite);
 +                    // CraftBukkit start - Fire PlayerTeleportEvent
 +                    org.bukkit.craftbukkit.entity.CraftPlayer player = entityplayer.getBukkitEntity();
 +                    org.bukkit.Location location = getBukkitEntity().getLocation();
@@ -28,6 +32,14 @@
 +                    Bukkit.getPluginManager().callEvent(teleEvent);
 +
 +                    if (!teleEvent.isCancelled() && !entityplayer.playerConnection.isDisconnected()) {
++                        if (this.random.nextFloat() < 0.05F && this.world.getGameRules().getBoolean("doMobSpawning")) {
++                            EntityEndermite entityendermite = new EntityEndermite(this.world);
++
++                            entityendermite.a(true);
++                            entityendermite.setPositionRotation(entityliving.locX, entityliving.locY, entityliving.locZ, entityliving.yaw, entityliving.pitch);
++                            this.world.addEntity(entityendermite);
++                        }
++
 +                        if (entityliving.au()) {
 +                            entityliving.mount((Entity) null);
 +                        }
@@ -39,6 +51,10 @@
 +                        CraftEventFactory.entityDamage = null;
                      }
 -
+-                    if (entityliving.au()) {
+-                        entityliving.mount((Entity) null);
+-                    }
+-
 -                    entityliving.enderTeleportTo(this.locX, this.locY, this.locZ);
 -                    entityliving.fallDistance = 0.0F;
 -                    entityliving.damageEntity(DamageSource.FALL, 5.0F);