2015-05-09 22:23:26 +02:00
From 8f680acc75bec4ef8a27cdb4b71056d02355023f Mon Sep 17 00:00:00 2001
2014-07-21 22:46:54 +02:00
From: Andy Shulman <andy.shulman@hotmail.com>
Date: Mon, 15 Apr 2013 20:06:37 -0500
Subject: [PATCH] Implement SpawnerSpawnEvent.
Adds BUKKIT-267
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2015-05-09 22:23:26 +02:00
index 056d447..0695fe2 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2014-11-28 02:17:45 +01:00
@@ -4,7 +4,11 @@ import com.google.common.collect.Lists;
2014-07-21 22:46:54 +02:00
import java.util.Iterator;
import java.util.List;
-import org.bukkit.event.entity.CreatureSpawnEvent; // CraftBukkit
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.SpawnerSpawnEvent;
+// CraftBukkit end
public abstract class MobSpawnerAbstract {
2014-12-02 07:02:15 +01:00
@@ -136,7 +140,12 @@ public abstract class MobSpawnerAbstract {
2014-07-21 22:46:54 +02:00
entity.f(nbttagcompound);
2014-11-28 02:17:45 +01:00
if (entity.world != null && flag) {
2014-07-21 22:46:54 +02:00
- entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
+ // CraftBukkit start - call SpawnerSpawnEvent, abort if cancelled
2014-11-28 02:17:45 +01:00
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity, this.b().getX(), this.b().getY(), this.b().getZ());
2014-07-21 22:46:54 +02:00
+ if (!event.isCancelled()) {
+ entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
+ }
+ // CraftBukkit end
}
NBTTagCompound nbttagcompound1;
2014-12-02 07:02:15 +01:00
@@ -160,6 +169,11 @@ public abstract class MobSpawnerAbstract {
2014-07-21 22:46:54 +02:00
entity2.f(nbttagcompound2);
entity2.setPositionRotation(entity1.locX, entity1.locY, entity1.locZ, entity1.yaw, entity1.pitch);
+ // CraftBukkit start - call SpawnerSpawnEvent, skip if cancelled
2014-11-28 02:17:45 +01:00
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity2, this.b().getX(), this.b().getY(), this.b().getZ());
2014-07-21 22:46:54 +02:00
+ if (event.isCancelled()) {
+ continue;
+ }
2014-11-28 02:17:45 +01:00
if (entity.world != null && flag) {
2014-07-21 22:46:54 +02:00
entity.world.addEntity(entity2, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
}
2015-02-28 12:36:22 +01:00
@@ -173,8 +187,12 @@ public abstract class MobSpawnerAbstract {
if (entity instanceof EntityInsentient) {
((EntityInsentient) entity).prepare(entity.world.E(new BlockPosition(entity)), (GroupDataEntity) null);
2014-07-21 22:46:54 +02:00
}
2015-02-28 12:36:22 +01:00
-
2014-11-28 02:17:45 +01:00
- entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
2014-07-21 22:46:54 +02:00
+ // Spigot start - call SpawnerSpawnEvent, abort if cancelled
2014-11-28 02:17:45 +01:00
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity, this.b().getX(), this.b().getY(), this.b().getZ());
2014-07-21 22:46:54 +02:00
+ if (!event.isCancelled()) {
2014-11-28 02:17:45 +01:00
+ entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
2014-07-21 22:46:54 +02:00
+ }
+ // Spigot end
}
return entity;
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2015-04-16 12:19:45 +02:00
index 10ac959..c5eca56 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2014-11-28 02:17:45 +01:00
@@ -18,6 +18,7 @@ import org.bukkit.Statistic.Type;
2014-07-21 22:46:54 +02:00
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
+import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.craftbukkit.CraftWorld;
2015-04-16 12:19:45 +02:00
@@ -128,6 +129,22 @@ public class CraftEventFactory {
2014-07-21 22:46:54 +02:00
}
/**
+ * Mob spawner event
+ */
+ public static SpawnerSpawnEvent callSpawnerSpawnEvent(Entity spawnee, int spawnerX, int spawnerY, int spawnerZ) {
+ org.bukkit.craftbukkit.entity.CraftEntity entity = spawnee.getBukkitEntity();
+ BlockState state = entity.getWorld().getBlockAt(spawnerX, spawnerY, spawnerZ).getState();
+
+ if (!(state instanceof CreatureSpawner)) {
+ state = null;
+ }
+
+ SpawnerSpawnEvent event = new SpawnerSpawnEvent(entity, (CreatureSpawner) state);
+ entity.getServer().getPluginManager().callEvent(event);
+ return event;
+ }
+
+ /**
* Bucket methods
*/
2014-11-28 02:17:45 +01:00
public static PlayerBucketEmptyEvent callPlayerBucketEmptyEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, EnumDirection clickedFace, ItemStack itemInHand) {
2014-07-21 22:46:54 +02:00
--
2015-05-09 22:23:26 +02:00
2.1.4
2014-07-21 22:46:54 +02:00