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

The following examples show how to use org.bukkit.entity.LivingEntity#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: SuperMobConstructor.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
public static LivingEntity constructSuperMob(LivingEntity livingEntity) {

        if (!SuperMobProperties.isValidSuperMobType(livingEntity)) {
            Bukkit.getLogger().warning("[EliteMobs] Attempted to construct an invalid supermob. Report this to the dev!");
            return null;
        }

        String name = ChatColorConverter.convert(SuperMobProperties.getDataInstance(livingEntity).getName());
        double newMaxHealth = SuperMobProperties.getDataInstance(livingEntity).getDefaultMaxHealth() * ConfigValues.defaultConfig.getInt(DefaultConfig.SUPERMOB_STACK_AMOUNT);

        livingEntity.setCustomName(name);
        livingEntity.setCustomNameVisible(true);
        livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(newMaxHealth);
        livingEntity.setHealth(newMaxHealth);

        EntityTracker.registerSuperMob(livingEntity);

        return livingEntity;

    }
 
Example 2
Source File: Region.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
public void setVillagerNametag() {
  Iterator<Entity> entityIterator = this.world.getEntities().iterator();
  while (entityIterator.hasNext()) {
    Entity e = entityIterator.next();

    if (!this.isInRegion(e.getLocation())) {
      continue;
    }

    if (e.getType() == EntityType.VILLAGER) {
      LivingEntity le = (LivingEntity) e;
      le.setCustomNameVisible(false);
      le.setCustomName(
          BedwarsRel
              ._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "ingame.shop.name"));
    }
  }
}
 
Example 3
Source File: Schematic.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Spawns a random companion for the player with a random name at the location given
 * @param player
 * @param location
 */
protected void spawnCompanion(Player player, Location location) {
    // Older versions of the server require custom names to only apply to Living Entities
    //Bukkit.getLogger().info("DEBUG: spawning compantion at " + location);
    if (!islandCompanion.isEmpty() && location != null) {
        Random rand = new Random();
        int randomNum = rand.nextInt(islandCompanion.size());
        EntityType type = islandCompanion.get(randomNum);
        if (type != null) {
            LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type);
            if (!companionNames.isEmpty()) {
                randomNum = rand.nextInt(companionNames.size());
                String name = companionNames.get(randomNum).replace("[player]", player.getName());
                //plugin.getLogger().info("DEBUG: name is " + name);
                companion.setCustomName(name);
                companion.setCustomNameVisible(true);
            } 
        }
    }
}
 
Example 4
Source File: SpawnMobEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Location location = loc.getLocation(playerID);
    int a = amount.getInt(playerID);
    for (int i = 0; i < a; i++) {
        Entity entity = location.getWorld().spawnEntity(location, type);
        if (entity instanceof LivingEntity) {
            LivingEntity living = (LivingEntity) entity;
            EntityEquipment eq = living.getEquipment();
            eq.setHelmet(helmet == null ? null : helmet.generate(1));
            eq.setHelmetDropChance(0);
            eq.setChestplate(chestplate == null ? null : chestplate.generate(1));
            eq.setChestplateDropChance(0);
            eq.setLeggings(leggings == null ? null : leggings.generate(1));
            eq.setLeggingsDropChance(0);
            eq.setBoots(boots == null ? null : boots.generate(1));
            eq.setBootsDropChance(0);
            eq.setItemInMainHand(mainHand == null ? null : mainHand.generate(1));
            eq.setItemInMainHandDropChance(0);
            eq.setItemInOffHand(offHand == null ? null : offHand.generate(1));
            eq.setItemInOffHandDropChance(0);
        }
        int j = 0;
        for (Item item : drops) {
            entity.setMetadata("betonquest-drops-" + j,
                    new FixedMetadataValue(BetonQuest.getInstance(), item.getID().getFullID() + ":"
                            + item.getAmount().getInt(playerID)));
            j++;
        }
        if (name != null && entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            livingEntity.setCustomName(name);
        }
        if (marked != null) {
            entity.setMetadata("betonquest-marked", new FixedMetadataValue(BetonQuest.getInstance(), marked));
        }
    }
    return null;
}
 
Example 5
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onInteractEntity(PlayerInteractAtEntityEvent event) {
  if (event.getRightClicked() == null) {
    return;
  }

  Entity entity = event.getRightClicked();
  Player player = event.getPlayer();
  if (!player.hasMetadata("bw-addteamjoin")) {
    if (!(entity instanceof LivingEntity)) {
      return;
    }

    LivingEntity livEntity = (LivingEntity) entity;
    Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
    if (game == null) {
      return;
    }

    if (game.getState() != GameState.WAITING) {
      return;
    }

    Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    event.setCancelled(true);
    return;
  }

  List<MetadataValue> values = player.getMetadata("bw-addteamjoin");
  if (values == null || values.size() == 0) {
    return;
  }

  event.setCancelled(true);
  TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0);
  if (!((boolean) value.value())) {
    return;
  }

  if (!(entity instanceof LivingEntity)) {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
            ._l(player, "errors.entitynotcompatible")));
    return;
  }

  LivingEntity living = (LivingEntity) entity;
  living.setRemoveWhenFarAway(false);
  living.setCanPickupItems(false);
  living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName());
  living.setCustomNameVisible(
      BedwarsRel.getInstance().getBooleanConfig("jointeam-entity.show-name", true));

  if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) {
    Utils.equipArmorStand(living, value.getTeam());
  }

  player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
  player.sendMessage(ChatWriter
      .pluginMessage(
          ChatColor.GREEN + BedwarsRel._l(player, "success.teamjoinadded", ImmutableMap.of("team",
              value.getTeam().getChatColor() + value.getTeam().getDisplayName()
                  + ChatColor.GREEN))));
}