2013-12-22 00:05:27 +01:00
From 454beaba6139be7b6f789ccef11ba7b979bf76a2 Mon Sep 17 00:00:00 2001
2013-06-15 11:10:13 +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
2013-12-01 04:40:53 +01:00
index 67c3397..bb6b3d5 100644
2013-06-15 11:10:13 +02:00
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
@@ -5,7 +5,11 @@ import java.util.Collection;
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 {
2013-12-01 04:40:53 +01:00
@@ -128,7 +132,12 @@ public abstract class MobSpawnerAbstract {
2013-06-15 11:10:13 +02:00
entity.f(nbttagcompound);
if (entity.world != null) {
- entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
+ // CraftBukkit start - call SpawnerSpawnEvent, abort if cancelled
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity, this.b(), this.c(), this.d());
+ if (!event.isCancelled()) {
2013-07-02 05:03:56 +02:00
+ entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
2013-06-15 11:10:13 +02:00
+ }
+ // CraftBukkit end
}
NBTTagCompound nbttagcompound1;
2013-12-01 04:40:53 +01:00
@@ -152,6 +161,11 @@ public abstract class MobSpawnerAbstract {
2013-06-15 11:10:13 +02:00
entity2.f(nbttagcompound2);
entity2.setPositionRotation(entity1.locX, entity1.locY, entity1.locZ, entity1.yaw, entity1.pitch);
+ // CraftBukkit start - call SpawnerSpawnEvent, skip if cancelled
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity2, this.b(), this.c(), this.d());
+ if (event.isCancelled()) {
+ continue;
+ }
2013-07-02 05:03:56 +02:00
if (entity.world != null) {
entity.world.addEntity(entity2, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
}
2013-12-01 04:40:53 +01:00
@@ -163,7 +177,12 @@ public abstract class MobSpawnerAbstract {
2013-06-15 11:10:13 +02:00
}
} else if (entity instanceof EntityLiving && entity.world != null) {
2013-07-02 05:03:56 +02:00
((EntityInsentient) entity).a((GroupDataEntity) null);
- this.a().addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
2013-06-15 11:10:13 +02:00
+ // CraftBukkit start - call SpawnerSpawnEvent, abort if cancelled
+ SpawnerSpawnEvent event = CraftEventFactory.callSpawnerSpawnEvent(entity, this.b(), this.c(), this.d());
+ if (!event.isCancelled()) {
2013-07-02 05:03:56 +02:00
+ this.a().addEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
2013-06-15 11:10:13 +02:00
+ }
+ // CraftBukkit 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
2013-12-22 00:05:27 +01:00
index a654a3e..f100884 100644
2013-06-15 11:10:13 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2013-08-04 00:51:09 +02:00
@@ -35,6 +35,7 @@ import org.bukkit.Server;
2013-06-15 11:10:13 +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.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
2013-12-01 04:40:53 +01:00
@@ -116,6 +117,22 @@ public class CraftEventFactory {
2013-06-15 11:10:13 +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
*/
public static PlayerBucketEmptyEvent callPlayerBucketEmptyEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemInHand) {
--
2013-12-01 04:40:53 +01:00
1.8.3.2
2013-06-15 11:10:13 +02:00