Java Code Examples for org.bukkit.entity.LivingEntity#setRemoveWhenFarAway()
The following examples show how to use
org.bukkit.entity.LivingEntity#setRemoveWhenFarAway() .
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: ControllableBaseEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public SpawnResult spawn(Location location) { if (isSpawned()) { return SpawnResult.ALREADY_SPAWNED; } this.handle = GameRegistry.get(IEntitySpawnHandler.class).createEntityHandle(this, location); LivingEntity entity = this.getBukkitEntity(); if (entity != null) { entity.setMetadata(EntityAPI.ENTITY_METADATA_MARKER, new FixedMetadataValue(EntityAPI.getCore(), true)); // Perhaps make this a key somewhere entity.setRemoveWhenFarAway(false); } //return spawned; return isSpawned() ? SpawnResult.SUCCESS : SpawnResult.FAILED; }
Example 2
Source File: EntityListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@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)))); }
Example 3
Source File: DMobType.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@Override public Entity toEntity(Location loc) { World world = loc.getWorld(); GameWorld gameWorld = plugin.getGameWorld(world); if (gameWorld == null) { return null; } LivingEntity entity = (LivingEntity) world.spawnEntity(loc, type); /* Set the Items */ entity.getEquipment().setItemInHand(itemHand); entity.getEquipment().setHelmet(itemHelmet); entity.getEquipment().setChestplate(itemChestplate); entity.getEquipment().setLeggings(itemLeggings); entity.getEquipment().setBoots(itemBoots); /* Check mob specified stuff */ if (type == EntityType.SKELETON) { if (witherSkeleton) { ((Skeleton) entity).setSkeletonType(SkeletonType.WITHER); } else { ((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL); } } if (type == EntityType.OCELOT) { Ocelot ocelot = (Ocelot) entity; if (EnumUtil.isValidEnum(Ocelot.Type.class, ocelotType.toUpperCase())) { ocelot.setCatType(Ocelot.Type.valueOf(ocelotType.toUpperCase())); } } /* Set Health */ if (maxHealth > 0) { entity.setMaxHealth(maxHealth); entity.setHealth(maxHealth); } /* Disable Despawning */ entity.setRemoveWhenFarAway(false); /* Spawn Mob */ new DMob(entity, gameWorld, this); return entity; }