@Override public Entity spawnEntity(Location loc, EntityType type) { checkNotNull(loc); checkNotNull(type); return spawn(loc, type.getEntityClass()); }
public static Class<? extends GlowEntity> getEntity(EntityType type) { return ENTITIES.get(type.getEntityClass()); }
private static void generateEntityStatistics() { for (EntityType entityType : EntityType.values()) { Class<? extends Entity> entityClass = entityType.getEntityClass(); if (entityClass == null) { continue; } if (Monster.class.isAssignableFrom(entityClass)) { set(ENTITY_KILLED_BY, entityType, "entityKilledBy." + entityClass.getSimpleName()); } if (Creature.class.isAssignableFrom(entityClass)) { set(KILL_ENTITY, entityType, "killEntity." + entityClass.getSimpleName()); } } } }
int sourceZ = chunk.getZ() << 4; EntityType type = entityTypes[random.nextInt(entityTypes.length)]; if ((!allowAnimals && Animals.class.isAssignableFrom(type.getEntityClass())) || !allowMonsters && Monster.class.isAssignableFrom(type.getEntityClass())) { return;
public Class<? extends Entity> getEntityClass() { if (entityType != null && getEntityType().getEntityClass() != null) { return getEntityType().getEntityClass(); } return Entity.class; }
public static boolean isMonster(EntityType entityType) { return isMonster(entityType.getEntityClass()); }
public static boolean isNPC(EntityType entityType) { return isNPC(entityType.getEntityClass()); }
public static EntityCategory getCategory(EntityType type) { return getCategory(type.getEntityClass()); }
public static boolean isMob(EntityType entityType) { return isMob(entityType.getEntityClass()); }
public static boolean isAnimal(EntityType entityType) { return isAnimal(entityType.getEntityClass()); }
public static Entity createEntity(Location location, EntityType entityType) { Entity bukkitEntity = null; try { Class<? extends Entity> entityClass = entityType.getEntityClass(); Object newEntity = class_CraftWorld_createEntityMethod.invoke(location.getWorld(), location, entityClass); if (newEntity != null) { bukkitEntity = getBukkitEntity(newEntity); if (bukkitEntity == null || !entityClass.isAssignableFrom(bukkitEntity.getClass())) return null; } } catch (Throwable ex) { ex.printStackTrace(); } return bukkitEntity; }
/** * Gets the lower-cased name of a given Entity Class * * @param entityClass to get the name of * @return Entity name */ public static String getName(Class<? extends Entity> entityClass) { if (entityClass == null) { return ""; } for (EntityType type : EntityType.values()) { Class<?> typeEntityClass = type.getEntityClass(); if (typeEntityClass != null && typeEntityClass.isAssignableFrom(entityClass)) { return getName(type); } } return entityClass.getSimpleName().toLowerCase(Locale.ENGLISH); }
public static Entity spawnEntity(Location target, EntityType entityType, CreatureSpawnEvent.SpawnReason spawnReason) { if (class_CraftWorld_spawnMethod == null) { return target.getWorld().spawnEntity(target, entityType); } Entity entity = null; try { World world = target.getWorld(); try { if (!class_CraftWorld_spawnMethod_isLegacy) { entity = (Entity)class_CraftWorld_spawnMethod.invoke(world, target, entityType.getEntityClass(), null, spawnReason); } else { entity = (Entity)class_CraftWorld_spawnMethod.invoke(world, target, entityType.getEntityClass(), spawnReason); } } catch (Exception ex) { entity = target.getWorld().spawnEntity(target, entityType); } } catch (Exception ex) { ex.printStackTrace(); } return entity; }
public static Enum getSoundCategory(DisguiseType disguiseType) { if (disguiseType == DisguiseType.PLAYER) return getSoundCategory("player"); Class<? extends Entity> entityClass = disguiseType.getEntityType().getEntityClass(); if (Monster.class.isAssignableFrom(entityClass)) return getSoundCategory("hostile"); if (Ambient.class.isAssignableFrom(entityClass)) return getSoundCategory("ambient"); return getSoundCategory("neutral"); }
@Override public MCProjectile launchProjectile(MCProjectileType projectile) { EntityType et = EntityType.valueOf(projectile.name()); Class<? extends Entity> c = et.getEntityClass(); Projectile proj = eps.launchProjectile(c.asSubclass(Projectile.class)); MCEntity mcproj = BukkitConvertor.BukkitGetCorrectEntity(proj); if(mcproj instanceof MCProjectile) { return (MCProjectile) mcproj; } else { return null; } }
@Override public MCProjectile launchProjectile(MCProjectileType projectile) { EntityType et = EntityType.valueOf(projectile.name()); Class<? extends Entity> c = et.getEntityClass(); Projectile proj = bps.launchProjectile(c.asSubclass(Projectile.class)); MCEntity e = BukkitConvertor.BukkitGetCorrectEntity(proj); if(e instanceof MCProjectile) { return (MCProjectile) e; } else { return null; } }
@Override public void run(String playerID) throws QuestRuntimeException { Location location = loc.getLocation(playerID); final double radius_squared = this.radius.getDouble(playerID) * this.radius.getDouble(playerID); location .getWorld() .getEntitiesByClass(type.getEntityClass()) .stream() //get only nearby entities .filter(entity -> entity.getLocation().distanceSquared(location) <= radius_squared) //only entities with given name .filter(entity -> { if (name == null) return true; return name.equals(entity.getName()); }) //only entities marked .filter(entity -> { if (marked == null) return true; return entity .getMetadata("betonquest-marked") .stream() .anyMatch(metadataValue -> metadataValue.asString().equals(marked)); }) //remove them .forEach(Entity::remove); } }
@Override public MCProjectile launchProjectile(MCProjectileType projectile, Vector3D init) { EntityType et = EntityType.valueOf(projectile.name()); Class<? extends Entity> c = et.getEntityClass(); Vector vector = new Vector(init.X(), init.Y(), init.Z()); Projectile proj = eps.launchProjectile(c.asSubclass(Projectile.class), vector); MCEntity mcproj = BukkitConvertor.BukkitGetCorrectEntity(proj); if(mcproj instanceof MCProjectile) { return (MCProjectile) mcproj; } else { return null; } }
@Override public MCProjectile launchProjectile(MCProjectileType projectile, Vector3D init) { EntityType et = EntityType.valueOf(projectile.name()); Class<? extends Entity> c = et.getEntityClass(); Vector vector = new Vector(init.X(), init.Y(), init.Z()); Projectile proj = bps.launchProjectile(c.asSubclass(Projectile.class), vector); MCEntity e = BukkitConvertor.BukkitGetCorrectEntity(proj); if(e instanceof MCProjectile) { return (MCProjectile) e; } else { return null; } }
@Override public MCEntity spawn(MCLocation l, MCEntityType entType, final CClosure closure) { EntityType type = (EntityType) entType.getConcrete(); Consumer<? extends Entity> consumer = (Consumer<Entity>) entity -> { MCEntity temp = BukkitConvertor.BukkitGetCorrectEntity(entity); Static.InjectEntity(temp); try { closure.execute(new CString(entity.getUniqueId().toString(), Target.UNKNOWN)); } catch (FunctionReturnException ex) { // do nothing } finally { Static.UninjectEntity(temp); } }; Entity ent = this.spawn((Location) l.getHandle(), type.getEntityClass(), consumer); return BukkitConvertor.BukkitGetCorrectEntity(ent); }