From 2d0c9eea980589f5e966b88d6b544c833d26637b Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Mon, 27 Aug 2018 01:51:20 -0500 Subject: [PATCH] Add PhantomSpawnEvent (#1375) --- .../0142-Add-PhantomPreSpawnEvent.patch | 63 ++++++++++++++ ...d-source-block-to-BlockPhysicsEvent.patch} | 2 +- .../0350-Add-PhantomPreSpawnEvent.patch | 82 +++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 Spigot-API-Patches/0142-Add-PhantomPreSpawnEvent.patch rename Spigot-API-Patches/{0142-Add-source-block-to-BlockPhysicsEvent.patch => 0143-Add-source-block-to-BlockPhysicsEvent.patch} (96%) create mode 100644 Spigot-Server-Patches/0350-Add-PhantomPreSpawnEvent.patch diff --git a/Spigot-API-Patches/0142-Add-PhantomPreSpawnEvent.patch b/Spigot-API-Patches/0142-Add-PhantomPreSpawnEvent.patch new file mode 100644 index 0000000000..6e7859cd10 --- /dev/null +++ b/Spigot-API-Patches/0142-Add-PhantomPreSpawnEvent.patch @@ -0,0 +1,63 @@ +From 7afd89928f309b7d009f38af76e51235e65762ef Mon Sep 17 00:00:00 2001 +From: BillyGalbreath +Date: Sat, 25 Aug 2018 19:56:42 -0500 +Subject: [PATCH] Add PhantomPreSpawnEvent + + +diff --git a/src/main/java/com/destroystokyo/paper/event/entity/PhantomPreSpawnEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/PhantomPreSpawnEvent.java +new file mode 100644 +index 00000000..303a1ec9 +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/entity/PhantomPreSpawnEvent.java +@@ -0,0 +1,30 @@ ++package com.destroystokyo.paper.event.entity; ++ ++import org.bukkit.Location; ++import org.bukkit.entity.Entity; ++import org.bukkit.entity.EntityType; ++import org.bukkit.event.entity.CreatureSpawnEvent; ++ ++import javax.annotation.Nullable; ++ ++/** ++ * Called when a phantom is spawned for an exhausted player ++ */ ++public class PhantomPreSpawnEvent extends PreCreatureSpawnEvent { ++ private final Entity entity; ++ ++ public PhantomPreSpawnEvent(Location location, Entity entity, CreatureSpawnEvent.SpawnReason reason) { ++ super(location, EntityType.PHANTOM, reason); ++ this.entity = entity; ++ } ++ ++ /** ++ * Get the entity this phantom is spawning for ++ * ++ * @return Entity ++ */ ++ @Nullable ++ public Entity getSpawningEntity() { ++ return entity; ++ } ++} +diff --git a/src/main/java/org/bukkit/entity/Phantom.java b/src/main/java/org/bukkit/entity/Phantom.java +index 1a1044ed..65b703a2 100644 +--- a/src/main/java/org/bukkit/entity/Phantom.java ++++ b/src/main/java/org/bukkit/entity/Phantom.java +@@ -14,4 +14,13 @@ public interface Phantom extends Flying { + * @param sz The new size of the phantom. + */ + public void setSize(int sz); ++ ++ // Paper start ++ /** ++ * Get the UUID of the entity that caused this phantom to spawn ++ * ++ * @return UUID ++ */ ++ public java.util.UUID getSpawningEntity(); ++ // Paper end + } +-- +2.18.0 + diff --git a/Spigot-API-Patches/0142-Add-source-block-to-BlockPhysicsEvent.patch b/Spigot-API-Patches/0143-Add-source-block-to-BlockPhysicsEvent.patch similarity index 96% rename from Spigot-API-Patches/0142-Add-source-block-to-BlockPhysicsEvent.patch rename to Spigot-API-Patches/0143-Add-source-block-to-BlockPhysicsEvent.patch index e8a915df2e..a03cc487bc 100644 --- a/Spigot-API-Patches/0142-Add-source-block-to-BlockPhysicsEvent.patch +++ b/Spigot-API-Patches/0143-Add-source-block-to-BlockPhysicsEvent.patch @@ -1,4 +1,4 @@ -From a924b59822d15436017aaa9ab10288a06f7e5263 Mon Sep 17 00:00:00 2001 +From 30d73a5a4ab4628f42ac527d63715e8e16d5dfbe Mon Sep 17 00:00:00 2001 From: Sotr Date: Thu, 23 Aug 2018 16:14:25 +0800 Subject: [PATCH] Add source block to BlockPhysicsEvent diff --git a/Spigot-Server-Patches/0350-Add-PhantomPreSpawnEvent.patch b/Spigot-Server-Patches/0350-Add-PhantomPreSpawnEvent.patch new file mode 100644 index 0000000000..c5a7967d75 --- /dev/null +++ b/Spigot-Server-Patches/0350-Add-PhantomPreSpawnEvent.patch @@ -0,0 +1,82 @@ +From d3e097f190c84d5d109bd328c4e32c349ead4a25 Mon Sep 17 00:00:00 2001 +From: BillyGalbreath +Date: Sat, 25 Aug 2018 19:56:51 -0500 +Subject: [PATCH] Add PhantomPreSpawnEvent + + +diff --git a/src/main/java/net/minecraft/server/EntityPhantom.java b/src/main/java/net/minecraft/server/EntityPhantom.java +index 2429644e99..2778660acd 100644 +--- a/src/main/java/net/minecraft/server/EntityPhantom.java ++++ b/src/main/java/net/minecraft/server/EntityPhantom.java +@@ -128,6 +128,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { + } + + this.setSize(nbttagcompound.getInt("Size")); ++ this.spawningEntity = nbttagcompound.getUUID("Paper.SpawningEntity"); // Paper + } + + public void b(NBTTagCompound nbttagcompound) { +@@ -136,6 +137,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { + nbttagcompound.setInt("AY", this.c.getY()); + nbttagcompound.setInt("AZ", this.c.getZ()); + nbttagcompound.setInt("Size", this.getSize()); ++ nbttagcompound.setUUID("Paper.SpawningEntity", this.spawningEntity); // Paper + } + + public SoundCategory bV() { +@@ -171,6 +173,14 @@ public class EntityPhantom extends EntityFlying implements IMonster { + return true; + } + ++ // Paper start ++ java.util.UUID spawningEntity; ++ ++ public java.util.UUID getSpawningEntity() { ++ return spawningEntity; ++ } ++ // Paper end ++ + class b extends PathfinderGoal { + + private int b; +diff --git a/src/main/java/net/minecraft/server/MobSpawnerPhantom.java b/src/main/java/net/minecraft/server/MobSpawnerPhantom.java +index 0626b77904..413188e970 100644 +--- a/src/main/java/net/minecraft/server/MobSpawnerPhantom.java ++++ b/src/main/java/net/minecraft/server/MobSpawnerPhantom.java +@@ -50,8 +50,17 @@ public class MobSpawnerPhantom { + int k = 1 + random.nextInt(difficultydamagescaler.a().a() + 1); + + for (int l = 0; l < k; ++l) { ++ // Paper start ++ com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event = new com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent(MCUtil.toLocation(world, blockposition1), ((EntityPlayer) entityhuman).getBukkitEntity(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); ++ if (!event.callEvent()) { ++ if (event.shouldAbortSpawn()) { ++ break; ++ } ++ continue; ++ } ++ // Paper end + EntityPhantom entityphantom = new EntityPhantom(world); +- ++ entityphantom.spawningEntity = entityhuman.uniqueID; // Paper + entityphantom.setPositionRotation(blockposition1, 0.0F, 0.0F); + groupdataentity = entityphantom.prepare(difficultydamagescaler, groupdataentity, (NBTTagCompound) null); + world.addEntity(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java +index 9f9ee92390..2b97313694 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java +@@ -35,4 +35,10 @@ public class CraftPhantom extends CraftFlying implements Phantom { + public EntityType getType() { + return EntityType.PHANTOM; + } ++ ++ // Paper start ++ public java.util.UUID getSpawningEntity() { ++ return getHandle().getSpawningEntity(); ++ } ++ // Paper end + } +-- +2.18.0 +