diff options
author | Xor Boole <mcyoung@mit.edu> | 2016-12-06 21:39:20 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-12-06 21:42:41 +1100 |
commit | bfbd868a37b8c02e34965469cde894b3cbe0331a (patch) | |
tree | 1355b8541187d1a1c4ff31c0b2905ff0bd8357a4 /src/main/java/org | |
parent | 04202c0ace026b51160ea18dec5434a3263c936d (diff) | |
download | craftbukkit-bfbd868a37b8c02e34965469cde894b3cbe0331a.tar craftbukkit-bfbd868a37b8c02e34965469cde894b3cbe0331a.tar.gz craftbukkit-bfbd868a37b8c02e34965469cde894b3cbe0331a.tar.lz craftbukkit-bfbd868a37b8c02e34965469cde894b3cbe0331a.tar.xz craftbukkit-bfbd868a37b8c02e34965469cde894b3cbe0331a.zip |
Implement pre-spawn API to allow modifications to spawned entities.
See preceding commit for why this change was included.
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 80e65f59..0987a779 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -58,6 +58,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionType; +import org.bukkit.util.Consumer; import org.bukkit.util.Vector; public class CraftWorld implements World { @@ -852,7 +853,12 @@ public class CraftWorld implements World { } public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException { - return spawn(location, clazz, SpawnReason.CUSTOM); + return spawn(location, clazz, null, SpawnReason.CUSTOM); + } + + @Override + public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function) throws IllegalArgumentException { + return spawn(location, clazz, function, SpawnReason.CUSTOM); } @Override @@ -1174,20 +1180,29 @@ public class CraftWorld implements World { @SuppressWarnings("unchecked") public <T extends Entity> T addEntity(net.minecraft.server.Entity entity, SpawnReason reason) throws IllegalArgumentException { + return addEntity(entity, reason, null); + } + + @SuppressWarnings("unchecked") + public <T extends Entity> T addEntity(net.minecraft.server.Entity entity, SpawnReason reason, Consumer<T> function) throws IllegalArgumentException { Preconditions.checkArgument(entity != null, "Cannot spawn null entity"); if (entity instanceof EntityInsentient) { ((EntityInsentient) entity).prepare(getHandle().D(new BlockPosition(entity)), (GroupDataEntity) null); } + if (function != null) { + function.accept((T) entity.getBukkitEntity()); + } + world.addEntity(entity, reason); return (T) entity.getBukkitEntity(); } - public <T extends Entity> T spawn(Location location, Class<T> clazz, SpawnReason reason) throws IllegalArgumentException { + public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function, SpawnReason reason) throws IllegalArgumentException { net.minecraft.server.Entity entity = createEntity(location, clazz); - return addEntity(entity, reason); + return addEntity(entity, reason, function); } public ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome, boolean includeBiomeTempRain) { |