Refine search
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); } }
/** * Checks if an Entity of the specified type is allowed to be a leash holder. * * @param type type of the entity which wishes to become a leash holder * @return if the type is allowed as a leash holder true, otherwise false */ public static boolean isAllowedLeashHolder(EntityType type) { return !(EntityType.ENDER_DRAGON.equals(type) || EntityType.WITHER.equals(type) || EntityType.PLAYER.equals(type) || EntityType.BAT.equals(type)); }
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()); } } } }
/** * Handles placing items into ItemFrames * @param e - event */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerHitEntity(PlayerInteractEntityEvent e) { if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS); } }
@Override public HashMap<String, Integer> getValues(HashMap<String, Integer> hashMap) { for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) { for (Disguise disg : list) { if (disg.getEntity() == null || !disg.isDisguiseInUse()) continue; String name = disg.getEntity().getType().name(); hashMap.put(name, hashMap.containsKey(name) ? hashMap.get(name) + 1 : 1); } } return hashMap; } });
@Override public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) { List<String> options = new ArrayList<>(); if (!sender.hasPermission("Magic.commands.mmob")) return options; if (args.length == 1) { options.add("spawn"); options.add("list"); options.add("clear"); } else if (args.length == 2 && (args[0].equalsIgnoreCase("spawn") || args[0].equalsIgnoreCase("clear"))) { options.addAll(api.getController().getMobKeys()); for (EntityType entityType : EntityType.values()) { if (entityType.isAlive() && entityType.isSpawnable()) { options.add(entityType.name().toLowerCase()); } } } else if (args.length == 3 && args[0].equalsIgnoreCase("clear")) { List<World> worlds = api.getPlugin().getServer().getWorlds(); for (World world : worlds) { options.add(world.getName()); } } return options; } }
/** * Gets the name of an entity. * * @param entity an entity * @return the first of the following that exists and is non-empty: {@code * entity.getCustomName()}, {@code entity.getName()}, {@code * entity.getType().getName()} */ public static String getName(Entity entity) { String customName = entity.getCustomName(); if (customName != null && !customName.isEmpty()) { return customName; } String name = entity.getName(); if (name == null || name.isEmpty()) { name = entity.getType().getName(); } return name; }
public CustomEntity getEntity(Entity entity) { CustomEntity customEntity = customEntityTypeMap.get(entity.getType().toString()); if (customEntity == null) { try { customEntity = customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName()); } catch (Exception e) { if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) { customEntity = customEntityClassMap.get(entity.getClass().getName()); } else { e.printStackTrace(); } } } return customEntity; }
String mageType = mageEntity == null ? "Non-Entity" : mageEntity.getType().name(); String message = ChatColor.AQUA + "Mage " + mageColor + mage.getId() + ChatColor.GRAY + " (" + mage.getName() + ")" + ChatColor.AQUA + " of type " World world = Bukkit.getWorlds().get(0); NumberFormat formatter = new DecimalFormat("#0.0"); List<EntityType> types = Arrays.asList(EntityType.values()); Collections.sort(types, new Comparator<EntityType>() { @Override showEntityInfo(sender, player, EntityType.PLAYER.name() + ChatColor.GRAY + " (" + player.getName() + " [" + (player.isSneaking() ? "sneaking" : "standing") + "])", formatter); break; if (entityType.isSpawnable()) String entityName = "Entity" + entityType.getEntityClass().getSimpleName(); entityName = "EntityMinecartTNT"; } else if (entityName.contains("Minecart")) { entityName = entityType.getEntityClass().getSimpleName(); entityName = entityName.replace("Minecart", ""); entityName = "EntityMinecart" + entityName; sender.sendMessage(ChatColor.BLACK + entityType.name() + ": " + ChatColor.RED + "Spawning error " + ChatColor.DARK_RED + "(" + errorMessage + ")"); continue; String label = entityType.name(); label = entityType.name() + ChatColor.GRAY + " (Baby)";
/** * Creates a show_entity action: when the component is hovered some entity information will be displayed * * @param entity the item to display * @return a new HoverAction instance */ static HoverAction showEntity(Entity entity) { return showEntity(entity.getUniqueId(), entity.getType().getName(), entity.getName()); }
/** * Get a list of creature names. * * @param requireSpawnable Whether to only show entries that are spawnable * @return */ public static String getCreatureNameList(boolean requireSpawnable) { StringBuilder str = new StringBuilder(); for (EntityType type : EntityType.values()) { Class<?> entityClass = type.getEntityClass(); if (entityClass == null) { continue; } if (!LivingEntity.class.isAssignableFrom(entityClass)) { continue; } if (!requireSpawnable || type.isSpawnable()) { if (str.length() > 0) { str.append(", "); } str.append(type.getName()); } } return str.toString(); } }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityHit(EntityDamageByEntityEvent e){ if(!isEnabled(e.getEntity().getWorld())) return; EntityType type = e.getDamager().getType(); switch(type){ case SNOWBALL: case EGG: case ENDER_PEARL: e.setDamage(module().getDouble("damage." + type.toString().toLowerCase(Locale.ROOT))); default: break; } } }
/** * 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 void debugNestedVehicleEnter(Player player) { debug(player, "Vehicle enter: Skip on nested vehicles, possibly with multiple players involved, who would do that?"); List<String> vehicles = new LinkedList<String>(); Entity tempVehicle = player.getVehicle(); while (tempVehicle != null) { vehicles.add(tempVehicle.getType().toString()); tempVehicle = tempVehicle.getVehicle(); } if (!vehicles.isEmpty()) { debug(player, "Vehicle enter: Nested vehicles: " + StringUtil.join(vehicles, ", ")); } }
/** * Spawns the mob. * * @return the spawned mob */ public LivingEntity spawn() { Location spawnLoc = getSign().getLocation().add(0.5, 0, 0.5); LivingEntity spawned = null; if (provider == null) { ExMob type = plugin.getCaliburn().getExMob(mob); if (type == null || !type.getSpecies().isAlive()) { return null; } spawned = (LivingEntity) type.toEntity(spawnLoc); spawned.setRemoveWhenFarAway(false); } else { provider.summon(mob, spawnLoc); for (Entity entity : spawnLoc.getChunk().getEntities()) { Location entityLoc = entity.getLocation(); if (entityLoc.getX() >= spawnLoc.getX() - 1 && entityLoc.getX() <= spawnLoc.getX() + 1 && entityLoc.getY() >= spawnLoc.getY() - 1 && entityLoc.getY() <= spawnLoc.getY() + 1 && entityLoc.getZ() >= spawnLoc.getZ() - 1 && entityLoc.getZ() <= spawnLoc.getZ() + 1 && entity instanceof LivingEntity && !spawnedMobs.contains((LivingEntity) entity) && !(entity instanceof Player)) { spawned = (LivingEntity) entity; } } } spawnedMobs.add(spawned); return spawned; }
/** * Create a WorldEdit EntityType from a Bukkit one. * * @param entityType Bukkit EntityType * @return WorldEdit EntityType */ public static EntityType adapt(org.bukkit.entity.EntityType entityType) { return EntityTypes.get(entityType.name().toLowerCase()); }
@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; } }
/** * Tests if we have an entry for every Bukkit entry. */ @Test public void testBukkitTypesExistInMobNames() { for (EntityType type : EntityType.values()) { if (type.isAlive() && type.isSpawnable() && type != EntityType.ARMOR_STAND) { // Throws IllegalArgumentException if no entry exists MobNames.valueOf(type.toString()); } } }