Java Code Examples for org.bukkit.entity.Entity#setCustomName()

The following examples show how to use org.bukkit.entity.Entity#setCustomName() . 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: StackTools.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
private static void removeTag(Entity entity){
    entity.setCustomNameVisible(false);
    entity.setCustomName(null);
}
 
Example 2
Source File: TagTask.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
public void run() {
    MythicMobsHook mobsHook = (MythicMobsHook) sm.getHookManager().getHook(PluginCompat.MYTHICMOBS);
    for (Entity e : WorldTools.getLoadedEntities()) {
        if (!sm.getCustomConfig().getStringList("no-stack-worlds").contains(e.getWorld().getName())) {
            if(!(e instanceof Mob)){
                continue;
            }
            if (StackTools.hasValidStackData(e)) {
                String typeString = e.getType().toString();

                int stackSize = StackTools.getSize(e);
                int removeAt = sm.getCustomConfig().getInt("tag.remove-at");
                if (sm.getCustomConfig().isString("custom." + typeString + ".tag.remove-at")) {
                    removeAt = sm.getCustomConfig().getInt("custom." + typeString + ".tag.remove-at");
                }
                if (stackSize > removeAt) {
                    String format = sm.getCustomConfig().getString("tag.format");
                    if (sm.getCustomConfig().isString("custom." + typeString + ".tag.format")) {
                          format = sm.getCustomConfig().getString("custom." + typeString + ".tag.format");
                    }

                    // Change if it is a mythic mob.
                    if (sm.getHookManager().isHookRegistered(PluginCompat.MYTHICMOBS) && mobsHook.isMythicMob(e)) {
                        typeString = mobsHook.getDisplayName(e);
                    } else if (sm.getCustomConfig().getBoolean("tag.use-translations")) {
                        typeString = "" + sm.getTranslationConfig().getString(e.getType().toString());
                    }

                    String formattedType = WordUtils.capitalizeFully(typeString.replaceAll("[^A-Za-z0-9]", " "));
                    String nearlyFinal = StringUtils.replace(StringUtils.replace(StringUtils.replace(format,
                            "%bukkit_type%", e.getType().toString()),
                            "%type%", formattedType),
                            "%size%", String.valueOf(stackSize));
                    String finalString = ChatColor.translateAlternateColorCodes('&', nearlyFinal);
                    if(!finalString.equals(e.getCustomName())){
                         e.setCustomName(finalString);
                    }

                    if(!(sm.getHookManager().isHookRegistered(PluginCompat.PROCOTOLLIB))){
                        boolean alwaysVisible = sm.getCustomConfig().getBoolean("tag.always-visible");
                        if (sm.getCustomConfig().isString("custom." + typeString + ".tag.always-visible")) {
                            alwaysVisible = sm.getCustomConfig().getBoolean("custom." + typeString + ".tag.always-visible");
                        }
                        e.setCustomNameVisible(alwaysVisible);
                    }
                }
            }

        }
    }
}
 
Example 3
Source File: Taunt.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
private void nametagProcessor(Entity entity, List<String> list) {

        int randomizedKey = ThreadLocalRandom.current().nextInt(list.size());
        String tempName = list.get(randomizedKey);

        entity.setCustomName(convert(tempName));

        new BukkitRunnable() {

            @Override
            public void run() {

                if (!entity.isValid())
                    return;

                entity.setCustomName(EntityTracker.getEliteMobEntity(entity).getName());

            }


        }.runTaskLater(MetadataHandler.PLUGIN, 4 * 20);

    }