jalse.entities.methods.KillEntityMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JALSE Show documentation
Show all versions of JALSE Show documentation
Java Artificial Life Simulation Engine
package jalse.entities.methods;
import jalse.entities.Entity;
import jalse.entities.EntityContainer;
import jalse.entities.annotations.KillEntity;
import jalse.entities.functions.KillEntityFunction;
import java.util.UUID;
import java.util.function.Supplier;
/**
* This is used for mapping calls to {@link EntityContainer#killEntity(UUID)}.
*
* @author Elliot Ford
*
* @see KillEntity
* @see KillEntityFunction
*
*/
public class KillEntityMethod implements EntityMethod {
private Supplier idSupplier;
/**
* Creates a new kill entity method.
*/
public KillEntityMethod() {
idSupplier = null;
}
/**
* Gets the entity ID supplier.
*
* @return ID supplier.
*/
public Supplier getIDSupplier() {
return idSupplier;
}
@Override
public Object invoke(final Object proxy, final Entity entity, final Object[] args) throws Throwable {
// Entity ID
final UUID id = idSupplier != null ? idSupplier.get() : (UUID) args[0];
// Kill
return entity.killEntity(id);
}
/**
* Sets the entity ID supplier.
*
* @param idSupplier
* ID supplier.
*/
public void setIDSupplier(final Supplier idSupplier) {
this.idSupplier = idSupplier;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy