org.bukkit.entity.Entity#getCustomName ( )源码实例Demo

下面列出了org.bukkit.entity.Entity#getCustomName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Slimefun4   文件: HologramProjector.java
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;
}
 
源代码2 项目: ProjectAres   文件: EntityInfo.java
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);
}
 
源代码3 项目: StackMob-3   文件: LoadEvent.java
@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);
    }
}
 
源代码4 项目: Slimefun4   文件: SimpleHologram.java
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);
}
 
源代码5 项目: Slimefun4   文件: AncientAltarListener.java
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;
}
 
源代码6 项目: askyblock   文件: GridManager.java
/**
 * 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();
                    }
                }
            }
        }
    }
}
 
源代码7 项目: PGM   文件: EntityInfo.java
public EntityInfo(Entity entity, @Nullable ParticipantState owner) {
  this(entity.getType(), entity.getCustomName(), owner);
}
 
源代码8 项目: ProjectAres   文件: MatchEntityState.java
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);
}
 
源代码9 项目: Quests   文件: MobkillingCertainTaskType.java
@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);
                }
            }
        }
    }
}
 
源代码10 项目: UHC   文件: DeathStandsModule.java
protected boolean isProtectedArmourStand(Entity entity) {
    final String customName = entity.getCustomName();

    return customName != null && customName.startsWith(STAND_PREFIX);
}
 
源代码11 项目: BetonQuest   文件: MonstersCondition.java
@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;
}
 
源代码12 项目: BetonQuest   文件: EntityInteractObjective.java
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;
}
 
源代码13 项目: BetonQuest   文件: ClearEvent.java
@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;
}
 
源代码14 项目: LanguageUtils   文件: LanguageHelper.java
/**
 * 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);
}