All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jalse.entities.methods.KillEntityMethod Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
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