use of org.bukkit.util.Consumer in project EliteMobs by MagmaGuy.
the class NPCEntity method initializeRole.
// Can't be used after the NPCEntity is done initialising
private void initializeRole() {
Vector offSet;
if (!isDisguised)
offSet = new Vector(0, 1.72, 0);
else
offSet = new Vector(0, 1.70, 0);
roleDisplay = this.villager.getWorld().spawn(villager.getLocation().add(offSet), ArmorStand.class, new Consumer<ArmorStand>() {
@Override
public void accept(ArmorStand armorStand) {
armorStand.setCustomName(npCsConfigFields.getRole());
armorStand.setCustomNameVisible(true);
armorStand.setMarker(true);
armorStand.setVisible(false);
armorStand.setGravity(false);
armorStand.setPersistent(false);
}
});
EntityTracker.registerVisualEffects(roleDisplay);
}
use of org.bukkit.util.Consumer in project Glowstone by GlowstoneMC.
the class GlowWorld method spawnGlowEntity.
/**
* Spawns an entity.
*
* @param location the {@link Location} to spawn the entity at
* @param clazz the class of the {@link Entity} to spawn
* @param reason the reason for the spawning of the entity
* @return an instance of the spawned {@link Entity}
* @throws IllegalArgumentException TODO: document the reason this can happen
*/
public <T extends GlowEntity, E extends Entity> GlowEntity spawnGlowEntity(Location location, Class<T> clazz, SpawnReason reason, @Nullable Consumer<E> function) throws IllegalArgumentException {
checkNotNull(location);
checkNotNull(clazz);
GlowEntity entity = null;
try {
if (EntityRegistry.getEntity(clazz) != null) {
entity = EntityStorage.create(clazz, location);
}
if (entity != null && function != null) {
function.accept((E) entity);
}
EntitySpawnEvent spawnEvent = null;
if (entity instanceof LivingEntity) {
spawnEvent = EventFactory.getInstance().callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
} else if (!(entity instanceof Item)) {
// ItemSpawnEvent is called elsewhere
spawnEvent = EventFactory.getInstance().callEvent(new EntitySpawnEvent(entity));
}
if (spawnEvent != null && spawnEvent.isCancelled()) {
// TODO: separate spawning and construction for better event cancellation
entity.remove();
} else {
List<Message> spawnMessage = entity.createSpawnMessage();
final GlowEntity finalEntity = entity;
getRawPlayers().stream().filter(player -> player.canSeeEntity(finalEntity)).forEach(player -> player.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
} catch (NoSuchMethodError | IllegalAccessError e) {
GlowServer.logger.log(Level.WARNING, "Invalid entity spawn: ", e);
} catch (Throwable t) {
GlowServer.logger.log(Level.SEVERE, "Unable to spawn entity: ", t);
}
if (entity != null) {
return entity;
}
throw new UnsupportedOperationException("Not supported yet.");
}
Aggregations