mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 09:17:36 +01:00
Implement pre-spawn API to allow modifications to spawned entities.
See preceding commit for why this change was included. By: Xor Boole <mcyoung@mit.edu>
This commit is contained in:
parent
ef84e6b90f
commit
eae60ccc96
@ -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;
|
||||
|
||||
/**
|
||||
@ -701,6 +702,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.
|
||||
|
17
paper-api/src/main/java/org/bukkit/util/Consumer.java
Normal file
17
paper-api/src/main/java/org/bukkit/util/Consumer.java
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user