@Override public boolean isTagged() { return entity instanceof LivingEntity && entity.getCustomName() != null; }
/** * 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; }
@Override public String getCustomName() { return e.getCustomName(); }
/** * Checks if an ball armorstand is inside of the chunk and spawns a ball at the location- * * @param event event */ @EventHandler public void onChunkLoadEvent(ChunkLoadEvent event) { for (final Entity entity : event.getChunk().getEntities()) { if (entity.getCustomName() != null) { if (entity.getCustomName().equals("ResourceBallsPlugin")) { this.plugin.getLogger().log(Level.INFO, "Removed unknown ball."); entity.remove(); } else if (entity.getCustomName().startsWith("balluuid-")) { entity.remove(); this.ballController.loadAndSpawn(UUID.fromString(entity.getCustomName().replace("balluuid-", ""))); } } } }
public static String getDisplayName(Entity entity) { if (entity instanceof Player) { return ((Player)entity).getDisplayName(); } String customName = entity.getCustomName(); if (customName != null && !customName.isEmpty()) { return customName; } return getName(entity.getType()); }
@Override public void run() { String customName = entity.getCustomName(); if (customName != null) { EntityData customMob = mobsByName.get(customName); if (customMob != null) { customMob.modify(controller, entity); } } else if (entity.getType() != EntityType.PLAYER) { EntityData customMob = defaultMobs.get(entity.getType()); if (customMob != null) { customMob.modify(controller, entity); } } } }, 1);
@SuppressWarnings("RedundantCast") public static MonsterExperience getMonsterExperience(Entity entity) { String name = null; if (MyPetApi.getCompatUtil().isCompatible("1.8")) { name = entity.getCustomName(); } else if (entity instanceof LivingEntity) { // casting for 1.7.10 name = ((LivingEntity) entity).getCustomName(); } List<MonsterExperienceHook> hooks = MyPetApi.getPluginHookManager().getHooks(MonsterExperienceHook.class); for (MonsterExperienceHook hook : hooks) { MonsterExperience monsterExperience = hook.getMonsterExperience(entity); if (monsterExperience != null) { return monsterExperience; } } if (name != null) { if (!PLUGIN_CONFIG_PATTERN.matcher(name).matches() && CUSTOM_MOB_EXP.containsKey(name)) { return CUSTOM_MOB_EXP.get(name); } } if (mobExp.containsKey(entity.getType().name())) { return mobExp.get(entity.getType().name()); } return UNKNOWN; }
if (entity.getCustomName() != null && player.hasPermission(category.toPermName() + '.' + entity.getCustomName())) { foundAchievements.addAll(findAchievementsByCategoryAndName(category, entity.getCustomName()));
public static ArmorStand getArmorStand(Block projector) { String nametag = ChatColor.translateAlternateColorCodes('&', BlockStorage.getLocationInfo(projector.getLocation(), "text")); double offset = Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), "offset")); Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomName(nametag); return hologram; }
public static Item findItem(Block b) { for (Entity n: b.getChunk().getEntities()) { if (n instanceof Item) { if (b.getLocation().add(0.5, 1.2, 0.5).distanceSquared(n.getLocation()) < 0.5D && n.getCustomName() != null) return (Item) n; } } return null; }
@EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { Entity entity = event.getRightClicked(); EntityData mob = controller.getMobByName(entity.getCustomName()); if (mob == null) return; String interactSpell = mob.getInteractSpell(); if (interactSpell == null || interactSpell.isEmpty()) return; Player player = event.getPlayer(); Mage mage = controller.getMage(player); event.setCancelled(true); ConfigurationSection config = new MemoryConfiguration(); config.set("entity", entity.getUniqueId().toString()); controller.cast(mage, interactSpell, config, player, player); }
@EventHandler public void onShear(PlayerShearEntityEvent event) { if (event.getEntity().getType() != EntityType.SHEEP) return; String playerID = PlayerConverter.getID(event.getPlayer()); if (!containsPlayer(playerID)) return; if (name != null && (event.getEntity().getCustomName() == null || !event.getEntity().getCustomName().equals(name))) return; if (color != null && !((Sheep) event.getEntity()).getColor().toString().equalsIgnoreCase(color)) return; SheepData data = (SheepData) dataMap.get(playerID); if (checkConditions(playerID)) { data.shearSheep(); // complete quest or notify if (data.getAmount() <= 0) completeObjective(playerID); else if (notify && data.getAmount() % notifyInterval == 0) Config.sendMessage(playerID, "sheep_to_shear", new String[] { String.valueOf(data.getAmount()) }); } }
public void spawnPet(Player player) { boolean cat_is_found = false; String cat_name = REDIS.get("pet:" + player.getUniqueId()); for (World w : Bukkit.getWorlds()) { List<Entity> entities = w.getEntities(); for (Entity entity : entities) { if (entity instanceof Ocelot) { if (entity.getCustomName() != null && entity.getCustomName().equals(cat_name)) { if (cat_is_found == false) { entity.teleport(player.getLocation()); ((Ocelot) entity).setTamed(true); ((Ocelot) entity).setOwner(player); cat_is_found = true; } else { entity.remove(); } } } } } if (cat_is_found == false) { final Ocelot ocelot = (Ocelot) player.getWorld().spawnEntity(player.getLocation(), EntityType.OCELOT); ocelot.setCustomName(cat_name); ocelot.setCustomNameVisible(true); } player.setMetadata("pet", new FixedMetadataValue(this, cat_name)); }
private static ArmorStand getArmorStand(Block b) { Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.7F, b.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); return hologram; }
private static ArmorStand getArmorStand(Block b) { Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.7F, b.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); return hologram; }
public static ArmorStand getArmorStand(Block hopper) { Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY(), hopper.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }
public static ArmorStand getArmorStand(Block hopper) { Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY() + offset, hopper.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }
private static ArmorStand getArmorStand(Block b) { Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + offset, b.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }
public static ArmorStand getArmorStand(Block hopper) { Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY() + offset, hopper.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }
public static ArmorStand getArmorStand(Block hopper, boolean createIfNoneFound) { Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY() + offset, hopper.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } if (!createIfNoneFound) { return null; } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }