summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorXor Boole <mcyoung@mit.edu>2016-12-06 21:38:05 +1100
committermd_5 <git@md-5.net>2016-12-06 21:40:01 +1100
commitb7a392c072a92bdeef8e6fc1e2849740bdb1ccca (patch)
treed51cdec00f5ba85e680a77c3d9c1eb55b1ea17bb /src/main
parent525ea1552b2e01d608cf10cf0b76be662862c188 (diff)
downloadbukkit-b7a392c072a92bdeef8e6fc1e2849740bdb1ccca.tar
bukkit-b7a392c072a92bdeef8e6fc1e2849740bdb1ccca.tar.gz
bukkit-b7a392c072a92bdeef8e6fc1e2849740bdb1ccca.tar.lz
bukkit-b7a392c072a92bdeef8e6fc1e2849740bdb1ccca.tar.xz
bukkit-b7a392c072a92bdeef8e6fc1e2849740bdb1ccca.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')
-rw-r--r--src/main/java/org/bukkit/World.java19
-rw-r--r--src/main/java/org/bukkit/util/Consumer.java17
2 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 02cad41c..f34b3a93 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.Metadatable;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
+import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
/**
@@ -702,6 +703,24 @@ public interface World extends PluginMessageRecipient, Metadatable {
public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException;
/**
+ * Spawn an entity of a specific class at the given {@link Location}, with
+ * the supplied function run before the entity is added to the world.
+ * <br>
+ * Note that when the function is run, the entity will not be actually in
+ * the world. Any operation involving such as teleporting the entity is undefined
+ * until after this function returns.
+ *
+ * @param location the {@link Location} to spawn the entity at
+ * @param clazz the class of the {@link Entity} to spawn
+ * @param function the function to be run before the entity is spawned.
+ * @param <T> the class of the {@link Entity} to spawn
+ * @return an instance of the spawned {@link Entity}
+ * @throws IllegalArgumentException if either parameter is null or the
+ * {@link Entity} requested cannot be spawned
+ */
+ public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function) throws IllegalArgumentException;
+
+ /**
* Spawn a {@link FallingBlock} entity at the given {@link Location} of
* the specified {@link Material}. The material dictates what is falling.
* When the FallingBlock hits the ground, it will place that block.
diff --git a/src/main/java/org/bukkit/util/Consumer.java b/src/main/java/org/bukkit/util/Consumer.java
new file mode 100644
index 00000000..fb9e6b90
--- /dev/null
+++ b/src/main/java/org/bukkit/util/Consumer.java
@@ -0,0 +1,17 @@
+package org.bukkit.util;
+
+/**
+ * Represents an operation that accepts a single input argument and returns no
+ * result.
+ *
+ * @param <T> the type of the input to the operation
+ */
+public interface Consumer<T> {
+
+ /**
+ * Performs this operation on the given argument.
+ *
+ * @param t the input argument
+ */
+ void accept(T t);
+}