Search in sources :

Example 1 with Aquatic

use of org.spongepowered.api.entity.living.Aquatic in project RedProtect by FabioZumbi12.

the class RPEntityListener method onCreatureSpawn.

@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
    for (Entity e : event.getEntities()) {
        if (e == null || e.getType() == null) {
            continue;
        }
        if (!(e instanceof Living)) {
            continue;
        }
        Optional<SpawnTypes> cause = event.getCause().first(SpawnTypes.class);
        RedProtect.get().logger.debug("entity", "SpawnCause: " + (cause.map(Object::toString).orElse(" null")));
        if (e instanceof Wither && cause.isPresent() && cause.get().equals(SpawnTypes.PLACEMENT)) {
            Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
            if (r != null && !r.canSpawnWhiter()) {
                event.isCancelled();
                return;
            }
        }
        if (e instanceof Monster) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnMonsters()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of monster " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        if (e instanceof Animal || e instanceof Golem || e instanceof Ambient || e instanceof Aquatic) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnPassives()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of animal " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        RedProtect.get().logger.debug("entity", "RPEntityListener - Spawn mob " + e.getType().getName());
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) World(org.spongepowered.api.world.World) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) Aquatic(org.spongepowered.api.entity.living.Aquatic) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 Entity (org.spongepowered.api.entity.Entity)1 Ambient (org.spongepowered.api.entity.living.Ambient)1 Aquatic (org.spongepowered.api.entity.living.Aquatic)1 Living (org.spongepowered.api.entity.living.Living)1 Animal (org.spongepowered.api.entity.living.animal.Animal)1 Golem (org.spongepowered.api.entity.living.golem.Golem)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Wither (org.spongepowered.api.entity.living.monster.Wither)1 Listener (org.spongepowered.api.event.Listener)1 SpawnTypes (org.spongepowered.api.event.cause.entity.spawn.SpawnTypes)1 IsCancelled (org.spongepowered.api.event.filter.IsCancelled)1 World (org.spongepowered.api.world.World)1