Java Code Examples for org.bukkit.entity.LivingEntity#isValid()
The following examples show how to use
org.bukkit.entity.LivingEntity#isValid() .
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: DisguiseManager.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static synchronized void hideEntityFromAll(LivingEntity livingEntity) { // do nothing if entity is invalid (dead or despawned) if(!(livingEntity instanceof Player) && !livingEntity.isValid()) { return; } try { Object playerInfoPacket = null; boolean isPlayer = livingEntity instanceof Player, disguisedAsPlayer = getDisguise(livingEntity) instanceof PlayerDisguise; if(isPlayer || disguisedAsPlayer) { // construct the packet playerInfoPacket = PacketPlayOutPlayerInfo_new.newInstance(); PacketPlayOutPlayerInfo_action.set(playerInfoPacket, EnumPlayerInfoAction_REMOVE_PLAYER.get(null)); List playerInfoList = (List)PacketPlayOutPlayerInfo_playerInfoList.get(playerInfoPacket); playerInfoList.add(PlayerInfoData_new.newInstance(playerInfoPacket, ProfileHelper.getInstance().getGameProfile(livingEntity.getUniqueId(), "", ""), 35, EnumGamemode_SURVIVAL.get(null), null)); } Object entityTrackerEntry = IntHashMap_get.invoke(EntityTracker_trackedEntities.get(WorldServer_entityTracker.get(Entity_world.get(CraftLivingEntity_getHandle.invoke(livingEntity)))), livingEntity.getEntityId()); for(Player observer : Bukkit.getOnlinePlayers()) { if(livingEntity != observer) { // hide the entity EntityTrackerEntry_clear.invoke(entityTrackerEntry, CraftPlayer_getHandle.invoke(observer)); } // send the player info removal if needed if(isPlayer ? disguiseViewSelf || livingEntity != observer : disguisedAsPlayer && isDisguisedTo(livingEntity, observer)) { ChannelInjector.sendPacketUnaltered(observer, playerInfoPacket); } } } catch(Exception e) { iDisguise.getInstance().getLogger().log(Level.SEVERE, "An unexpected exception occured.", e); } }
Example 2
Source File: DisguiseManager.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static synchronized void hideEntityFromOne(LivingEntity livingEntity, Player observer) { // do nothing if entity is invalid (dead or despawned) if(!(livingEntity instanceof Player) && !livingEntity.isValid()) { return; } try { Object playerInfoPacket = null; boolean isPlayer = livingEntity instanceof Player, disguisedAsPlayer = getDisguise(livingEntity) instanceof PlayerDisguise; if(isPlayer || disguisedAsPlayer) { // construct the packet playerInfoPacket = PacketPlayOutPlayerInfo_new.newInstance(); PacketPlayOutPlayerInfo_action.set(playerInfoPacket, EnumPlayerInfoAction_REMOVE_PLAYER.get(null)); List playerInfoList = (List)PacketPlayOutPlayerInfo_playerInfoList.get(playerInfoPacket); playerInfoList.add(PlayerInfoData_new.newInstance(playerInfoPacket, ProfileHelper.getInstance().getGameProfile(livingEntity.getUniqueId(), "", ""), 35, EnumGamemode_SURVIVAL.get(null), null)); } Object entityTrackerEntry = IntHashMap_get.invoke(EntityTracker_trackedEntities.get(WorldServer_entityTracker.get(Entity_world.get(CraftLivingEntity_getHandle.invoke(livingEntity)))), livingEntity.getEntityId()); if(livingEntity != observer) { // hide the entity EntityTrackerEntry_clear.invoke(entityTrackerEntry, CraftPlayer_getHandle.invoke(observer)); } // send the player info removal if needed if(isPlayer ? disguiseViewSelf || livingEntity != observer : disguisedAsPlayer && isDisguisedTo(livingEntity, observer)) { ChannelInjector.sendPacketUnaltered(observer, playerInfoPacket); } } catch(Exception e) { iDisguise.getInstance().getLogger().log(Level.SEVERE, "An unexpected exception occured.", e); } }
Example 3
Source File: DisguiseManager.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void showEntityToAll(final LivingEntity livingEntity) { // do nothing if entity is invalid (dead or despawned) if(!(livingEntity instanceof Player) && !livingEntity.isValid()) { return; } if(VersionHelper.require1_9()) { showEntityToAll0(livingEntity); } else { // we have to delay the reappearance for 1.8.0 clients Bukkit.getScheduler().runTaskLater(iDisguise.getInstance(), () -> showEntityToAll0(livingEntity), 10L); } }
Example 4
Source File: DisguiseManager.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void showEntityToOne(final LivingEntity livingEntity, final Player observer) { // do nothing if entity is invalid (dead or despawned) if(!(livingEntity instanceof Player) && !livingEntity.isValid()) { return; } if(VersionHelper.require1_9()) { showEntityToOne0(livingEntity, observer); } else { // we have to delay the reappearance for 1.8.0 clients Bukkit.getScheduler().runTaskLater(iDisguise.getInstance(), () -> showEntityToOne0(livingEntity, observer), 10L); } }
Example 5
Source File: EliteMobScanner.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
public static void scanValidAggressiveLivingEntity(LivingEntity livingEntity) { if (!EntityTracker.isNaturalEntity(livingEntity) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_SPAWNER_MOBS)) return; if (EntityTracker.isNaturalEntity(livingEntity) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_NATURAL_MOBS)) return; for (Entity secondEntity : livingEntity.getNearbyEntities(aggressiveRange, aggressiveRange, aggressiveRange)) { if (!secondEntity.getType().equals(livingEntity.getType())) continue; if (!livingEntity.isValid() || !secondEntity.isValid()) continue; if (!EntityTracker.isNaturalEntity(secondEntity) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_SPAWNER_MOBS)) return; if (EntityTracker.isNaturalEntity(secondEntity) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_NATURAL_MOBS)) return; EliteMobEntity eliteMobEntity1 = null; EliteMobEntity eliteMobEntity2 = null; int level1 = 1; int level2 = 1; if (EntityTracker.isEliteMob(livingEntity)) { eliteMobEntity1 = EntityTracker.getEliteMobEntity(livingEntity); if (!eliteMobEntity1.canStack()) continue; level1 = eliteMobEntity1.getLevel(); } if (EntityTracker.isEliteMob(secondEntity)) { eliteMobEntity2 = EntityTracker.getEliteMobEntity(secondEntity); if (!eliteMobEntity2.canStack()) continue; level2 = eliteMobEntity2.getLevel(); } int newLevel = level1 + level2; if (newLevel > ConfigValues.mobCombatSettingsConfig.getInt(MobCombatSettingsConfig.ELITEMOB_STACKING_CAP)) return; double healthPercentage = (livingEntity.getHealth() / livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() + ((LivingEntity) secondEntity).getHealth() / ((LivingEntity) secondEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) / 2; /* This is a bit of a dirty hack It won't register the entity twice, but it will overwrite the existing method */ eliteMobEntity1 = new EliteMobEntity(livingEntity, newLevel, healthPercentage, CreatureSpawnEvent.SpawnReason.CUSTOM); secondEntity.remove(); } }
Example 6
Source File: ChickenHandler.java From EliteMobs with GNU General Public License v3.0 | 2 votes |
public void dropEggs() { ItemStack eggStack = new ItemStack(Material.EGG, 1); ItemMeta eggMeta = eggStack.getItemMeta(); eggMeta.setLore(lore); eggStack.setItemMeta(eggMeta); Iterator<LivingEntity> superChickenIterator = EntityTracker.getSuperMobs().iterator(); while (superChickenIterator.hasNext()) { LivingEntity chicken = superChickenIterator.next(); if (!(chicken instanceof Chicken)) continue; if (chicken == null || !chicken.isValid()) { superChickenIterator.remove(); } else { Item droppedItem = chicken.getWorld().dropItem(chicken.getLocation(), eggStack); droppedItem.setVelocity(ItemDropVelocity.ItemDropVelocity()); new BukkitRunnable() { @Override public void run() { if (droppedItem.isValid()) { droppedItem.remove(); } } }.runTaskLater(MetadataHandler.PLUGIN, 20 * 60); } } }