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

jalse.entities.methods.KillEntitiesMethod 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.KillEntities;
import jalse.entities.functions.KillEntitiesFunction;

import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;

/**
 * This is used for mapping calls to {@link EntityContainer#killEntities()}.
 *
 * @author Elliot Ford
 *
 * @see KillEntities
 * @see KillEntitiesFunction
 *
 */
public class KillEntitiesMethod implements EntityMethod {

    private final Set> idSuppliers;

    /**
     * Creates a kill entities method.
     *
     * @param idSuppliers
     *            Entity ID suppliers for filtering.
     */
    public KillEntitiesMethod(final Set> idSuppliers) {
	this.idSuppliers = Objects.requireNonNull(idSuppliers);
    }

    /**
     * Gets entity ID suppliers.
     *
     * @return ID suppliers.
     */
    public Set> getIDSuppliers() {
	return idSuppliers;
    }

    @Override
    public Object invoke(final Object proxy, final Entity entity, final Object[] args) throws Throwable {
	// Kill all
	if (idSuppliers.isEmpty()) {
	    entity.killEntities();
	}
	// Kill selected
	else {
	    idSuppliers.stream().map(Supplier::get).forEach(entity::killEntity);
	}
	// void return
	return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy