/** * Evaluates a condition for an entity. * * @param entity the entity * @param condition the condition string to evaluate * @return true if the condition is satisfied; false otherwise */ public static boolean conditionValue(GlowLivingEntity entity, String condition) { if (condition.equals("ENTITY_ONFIRE")) { return entity.getFireTicks() > 0; } if (condition.startsWith("ENTITY_KILLER_")) { EntityType type = EntityType.valueOf(condition.substring("ENTITY_KILLER_".length())); return entity.getLastDamager() != null && entity.getLastDamager().getType() == type; } if (condition.contains(".")) { return (boolean) process(entity, condition); } // todo: more conditions, reflection return false; }
private List<EntityType> getTypes() { if (arguments.containsKey("type")) { SelectorValue value = arguments.get("type"); if (!value.isInverted()) { EntityType type = EntityType.fromName(value.getValue()); if (type == null) { try { type = EntityType.valueOf(value.getValue().toUpperCase()); } catch (IllegalArgumentException ex) { return Collections.emptyList(); } } return Arrays.asList(type); } else { return Arrays.stream(EntityType.values()).filter(mode -> { if (mode.getName() == null) { return !mode.name().equalsIgnoreCase(value.getValue()); } return !mode.getName().equalsIgnoreCase(value.getValue()); }).collect(Collectors.toList()); } } if (selector == SelectorType.ALL_ENTITIES) { return Arrays.asList(EntityType.values()); } else { return Arrays.asList(EntityType.PLAYER); } }
public static BukkitMCEntityType valueOfConcrete(String test) { try { return valueOfConcrete(EntityType.valueOf(test)); } catch (IllegalArgumentException iae) { return (BukkitMCEntityType) NULL; } }
private static EntityType getBukkitType(MCVanillaEntityType v) { switch(v) { case ENDER_EYE: return EntityType.ENDER_SIGNAL; } return EntityType.valueOf(v.name()); }
@Nullable @SuppressWarnings("deprecation") public static EntityType parseEntityType(String typeString) { if (typeString == null) return null; EntityType returnType = null; try { returnType = EntityType.valueOf(typeString.toUpperCase()); } catch (Exception ex) { returnType = null; } if (returnType == null) { returnType = EntityType.fromName(typeString); } return returnType; }
protected void loadMobSkins(ConfigurationSection skins) { mobSkins.clear(); Set<String> keys = skins.getKeys(false); for (String key : keys) { try { EntityType entityType = EntityType.valueOf(key.toUpperCase()); mobSkins.put(entityType, skins.getString(key)); } catch (Exception ignore) { } } }
public VehicleObjective(Instruction instruction) throws InstructionParseException { super(instruction); template = ObjectiveData.class; String name = instruction.next(); if (name.equalsIgnoreCase("any")) { any = true; } else try { vehicle = EntityType.valueOf(name.toUpperCase()); } catch (IllegalArgumentException e) { throw new InstructionParseException("Entity type " + name + " does not exist."); } }
public VehicleCondition(Instruction instruction) throws InstructionParseException { super(instruction); String name = instruction.next(); if (name.equalsIgnoreCase("any")) { any = true; } else try { vehicle = EntityType.valueOf(name.toUpperCase()); } catch (IllegalArgumentException e) { throw new InstructionParseException("Entity type " + name + " does not exist."); } }
protected void loadMobEggs(ConfigurationSection skins) { mobEggs.clear(); Set<String> keys = skins.getKeys(false); for (String key : keys) { try { EntityType entityType = EntityType.valueOf(key.toUpperCase()); Material material = getVersionedMaterial(skins, key); if (material != null) { mobEggs.put(entityType, material); } } catch (Exception ignore) { } } }
public static void configureHeadSizes(ConfigurationSection config) { headSizes.clear(); Collection<String> keys = config.getKeys(false); for (String key : keys) { try { double size = config.getDouble(key); EntityType entityType = EntityType.valueOf(key.toUpperCase()); if (size > 0) { headSizes.put(entityType, size); } } catch (Exception ignore) { } } }
protected void populateEntityTypes(Set<EntityType> entityTypes, ConfigurationSection configuration, String key) { entityTypes.clear(); if (configuration.contains(key)) { Collection<String> typeStrings = ConfigurationUtils.getStringList(configuration, key); for (String typeString : typeStrings) { try { entityTypes.add(EntityType.valueOf(typeString.toUpperCase())); } catch (Exception ex) { getLogger().warning("Unknown entity type: " + typeString + " in " + key); } } } }
@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; } }
@SuppressWarnings("deprecation") private static EntityType matchEntityType(String toMatch) { EntityType type; try { type = EntityType.valueOf(toMatch); } catch (IllegalArgumentException ex) { type = EntityType.fromName(toMatch); } if (type != null) return type; return matchEnum(EntityType.values(), toMatch); }
@Override @SuppressWarnings("deprecation") public void load(DataKey key) { try { type = EntityType.valueOf(key.getString("")); } catch (IllegalArgumentException ex) { type = EntityType.fromName(key.getString("")); } if (type == null) { type = EntityType.PLAYER; } }
@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 boolean onBlockPlace(BlockPlaceEvent e, ItemStack item) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REPAIRED_SPAWNER, false)) { EntityType type = null; for (String line: item.getItemMeta().getLore()) { if (ChatColor.stripColor(line).startsWith("Type: ")) type = EntityType.valueOf(ChatColor.stripColor(line).replace("Type: ", "").replace(" ", "_").toUpperCase()); } if (type != null) { CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState(); spawner.setSpawnedType(type); spawner.update(true, false); } return true; } else return false; } });
@Override public void setType(MCEntityType type) { e.setCancelled(true); e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.valueOf(type.name())); } }
@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; } }
/** * Tests if Bukkit has an entry for all our entries. */ @Test public void testMobNamesExistInBukkit() { // Check if all our entries exist in Bukkit for (MobNames name : MobNames.values()) { // Also throws IllegalArgumentException if no entry exists EntityType.valueOf(name.toString()); } }