Java Code Examples for org.bukkit.entity.Entity#getCustomName()
The following examples show how to use
org.bukkit.entity.Entity#getCustomName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HologramProjector.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private static ArmorStand getArmorStand(Block projector, boolean createIfNoneExists) { String nametag = BlockStorage.getLocationInfo(projector.getLocation(), "text"); double offset = Double.parseDouble(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 && n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) { return (ArmorStand) n; } } if (!createIfNoneExists) { return null; } ArmorStand hologram = SimpleHologram.create(l); hologram.setCustomName(nametag); return hologram; }
Example 2
Source File: EntityInfo.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public EntityInfo(Entity entity, @Nullable ParticipantState owner) { super(owner); this.entityType = entity.getType(); this.entityClass = entity.getClass(); this.customName = entity.getCustomName(); this.nameKey = NMSHacks.getTranslationKey(entity); }
Example 3
Source File: LoadEvent.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onChunkLoad(ChunkLoadEvent e) { if(sm.getCustomConfig().getStringList("no-stack-worlds") .contains(e.getWorld().getName())){ return; } for(Entity currentEntity : e.getChunk().getEntities()){ if(!(currentEntity instanceof Mob)){ continue; } // Check if has been cached. if(sm.getCache().containsKey(currentEntity.getUniqueId())){ int cacheSize = sm.getCache().get(currentEntity.getUniqueId()); sm.getCache().remove(currentEntity.getUniqueId()); StackTools.setSize(currentEntity, cacheSize); continue; } if(currentEntity.getCustomName() != null){ continue; } if(sm.getTraitManager().checkTraits(currentEntity)){ continue; } if(sm.getHookManager().cantStack(currentEntity)){ continue; } if(sm.getLogic().doChecks(currentEntity)){ continue; } StackTools.setSize(currentEntity, GlobalValues.NOT_ENOUGH_NEAR); } }
Example 4
Source File: SimpleHologram.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private static ArmorStand getArmorStand(Block b, boolean createIfNoneExists) { 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 && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) { return (ArmorStand) n; } } if (!createIfNoneExists) return null; else return create(l); }
Example 5
Source File: AncientAltarListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public Item findItem(Block b) { for (Entity n : b.getChunk().getEntities()) { if (n instanceof Item && b.getLocation().add(0.5, 1.2, 0.5).distanceSquared(n.getLocation()) < 0.5D && n.getCustomName() != null) { return (Item) n; } } return null; }
Example 6
Source File: GridManager.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Removes monsters around location l * * @param l location */ public void removeMobs(final Location l) { if (!inWorld(l)) { return; } //plugin.getLogger().info("DEBUG: removing mobs"); // Don't remove mobs if at spawn if (this.isAtSpawn(l)) { //plugin.getLogger().info("DEBUG: at spawn!"); return; } final int px = l.getBlockX(); final int py = l.getBlockY(); final int pz = l.getBlockZ(); for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { final Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16)); if (c.isLoaded()) { for (final Entity e : c.getEntities()) { //plugin.getLogger().info("DEBUG: " + e.getType()); // Don't remove if the entity is an NPC or has a name tag if (e.getCustomName() != null || e.hasMetadata("NPC")) continue; if (e instanceof Monster && !Settings.mobWhiteList.contains(e.getType())) { e.remove(); } } } } } }
Example 7
Source File: EntityInfo.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public EntityInfo(Entity entity, @Nullable ParticipantState owner) { this(entity.getType(), entity.getCustomName(), owner); }
Example 8
Source File: MatchEntityState.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static @Nullable MatchEntityState get(Entity entity) { Match match = Matches.get(entity.getWorld()); String customName = entity instanceof Player ? null : entity.getCustomName(); return match == null ? null : new MatchEntityState(match, entity.getClass(), entity.getUniqueId(), entity.getEntityLocation(), customName); }
Example 9
Source File: MobkillingCertainTaskType.java From Quests with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onMobKill(EntityDeathEvent event) { Player killer = event.getEntity().getKiller(); Entity mob = event.getEntity(); if (mob == null || mob instanceof Player) { return; } if (killer == null) { return; } QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(killer.getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } String configEntity = (String) task.getConfigValue("mob"); String configName = (String) task.getConfigValue("name"); EntityType entity; try { entity = EntityType.valueOf(configEntity); } catch (IllegalArgumentException ex) { continue; } if (configName != null) { configName = ChatColor.translateAlternateColorCodes('&', configName); if (mob.getCustomName() == null || !mob.getCustomName().equals(configName)) { return; } } if (mob.getType() != entity) { continue; } int mobKillsNeeded = (int) task.getConfigValue("amount"); int progressKills; if (taskProgress.getProgress() == null) { progressKills = 0; } else { progressKills = (int) taskProgress.getProgress(); } taskProgress.setProgress(progressKills + 1); if (((int) taskProgress.getProgress()) >= mobKillsNeeded) { taskProgress.setCompleted(true); } } } } }
Example 10
Source File: DeathStandsModule.java From UHC with MIT License | 4 votes |
protected boolean isProtectedArmourStand(Entity entity) { final String customName = entity.getCustomName(); return customName != null && customName.startsWith(STAND_PREFIX); }
Example 11
Source File: MonstersCondition.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@Override protected Boolean execute(String playerID) throws QuestRuntimeException { Location location = loc.getLocation(playerID); int[] neededAmounts = new int[types.length]; for (int i = 0; i < neededAmounts.length; i++) { neededAmounts[i] = 0; } Collection<Entity> entities = location.getWorld().getEntities(); loop: for (Entity entity : entities) { if (!(entity instanceof LivingEntity)) { continue; } if (name != null && (entity.getCustomName() == null || !entity.getCustomName().equals(name))) { continue; } if (marked != null) { if (!entity.hasMetadata("betonquest-marked")) { continue; } List<MetadataValue> meta = entity.getMetadata("betonquest-marked"); for (MetadataValue m : meta) { if (!m.asString().equals(marked)) { continue loop; } } } double r = range.getDouble(playerID); if (entity.getLocation().distanceSquared(location) < r * r) { EntityType theType = entity.getType(); for (int i = 0; i < types.length; i++) { if (theType == types[i]) { neededAmounts[i]++; break; } } } } for (int i = 0; i < amounts.length; i++) { if (neededAmounts[i] < amounts[i].getInt(playerID)) { return false; } } return true; }
Example 12
Source File: EntityInteractObjective.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
private boolean onInteract(Player player, Entity entity) { // check if it's the right entity type if (!entity.getType().equals(mobType)) { return false; } // if the entity should have a name and it does not match, return if (name != null && (entity.getCustomName() == null || !entity.getCustomName().equals(name))) { return false; } // check if the entity is correctly marked if (marked != null) { if (!entity.hasMetadata("betonquest-marked")) { return false; } List<MetadataValue> meta = entity.getMetadata("betonquest-marked"); for (MetadataValue m : meta) { if (!m.asString().equals(marked)) { return false; } } } // check if the player has this objective String playerID = PlayerConverter.getID(player); if (containsPlayer(playerID) && checkConditions(playerID)) { // Check location matches if (loc != null) { try { Location location = loc.getLocation(playerID); double r = range.getDouble(playerID); if (!entity.getWorld().equals(location.getWorld()) || entity.getLocation().distance(location) > r) { return false; } } catch (QuestRuntimeException e) { LogUtils.getLogger().log(Level.WARNING, "Error while handling '" + instruction.getID() + "' objective: " + e.getMessage()); LogUtils.logThrowable(e); } } // get data off the player EntityInteractData playerData = (EntityInteractData) dataMap.get(playerID); // check if player already interacted with entity if (playerData.containsEntity(entity)) return false; // right mob is interacted with, handle data update playerData.subtract(); playerData.addEntity(entity); if (playerData.isZero()) { completeObjective(playerID); } else if (notify && playerData.getAmount() % notifyInterval == 0) { // send a notification Config.sendNotify(playerID, "mobs_to_click", new String[]{String.valueOf(playerData.getAmount())}, "mobs_to_click,info"); } return true; } return false; }
Example 13
Source File: ClearEvent.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@Override protected Void execute(String playerID) throws QuestRuntimeException { Location location = loc.getLocation(playerID); Collection<Entity> entities = location.getWorld().getEntities(); loop: for (Entity entity : entities) { if (!(entity instanceof LivingEntity)) { continue; } if (name != null && (entity.getCustomName() == null || !entity.getCustomName().equals(name))) { continue; } if (marked != null) { if (!entity.hasMetadata("betonquest-marked")) { continue; } List<MetadataValue> meta = entity.getMetadata("betonquest-marked"); for (MetadataValue m : meta) { if (!m.asString().equals(marked)) { continue loop; } } } double r = range.getDouble(playerID); if (entity.getLocation().distanceSquared(location) < r * r) { EntityType entityType = entity.getType(); for (EntityType allowedType : types) { if (entityType == allowedType) { if (kill) { LivingEntity living = (LivingEntity) entity; living.damage(living.getHealth() + 10); } else { entity.remove(); } break; } } } } return null; }
Example 14
Source File: LanguageHelper.java From LanguageUtils with MIT License | 2 votes |
/** * Return the display name of the entity. * * @param entity The entity * @param locale The language of the entity(if the entity doesn't have a customized name, the method will return the name of the entity in this language) * @return The name of the entity */ public static String getEntityDisplayName(Entity entity, String locale) { return entity.getCustomName() != null ? entity.getCustomName() : getEntityName(entity, locale); }