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());
}
}
Aggregations