@Override public final Entity getSource() { return (source != null && source.isValid()) ? source : null; }
@Override public boolean isValid() { return base.isValid(); }
public boolean isValid() { return entity.isValid(); }
new BukkitRunnable() { public void run() { for(Iterator<Entity> it = CheckAliveEntities.keySet().iterator(); it.hasNext();) { Entity e = it.next(); if ( !e.isValid() && !(e instanceof Player) ) { System.out.println("DA"); x.removeHologram(e); // needs refactoring it.remove(); y.setEntityRespawn(e); // needs refactoring break; } } } } }.runTaskTimer(this, 5, 5);
public void checkEntities() { if (spawned == null) return; Iterator<WeakReference<Entity>> iterator = spawned.iterator(); while (iterator.hasNext()) { WeakReference<Entity> mobReference = iterator.next(); Entity mob = mobReference.get(); if (mob == null || !mob.isValid()) { iterator.remove(); } } }
public boolean hasValidEntity() { Entity entity = this.getEntity(); return entity != null && entity.isValid(); } }
@Override public boolean isSpawned() { return getEntity() != null && getEntity().isValid(); }
@Override public @Nullable Entity getTopDamager() { if (topDamager == null) return null; Entity topEntity = topDamager.getEntity(); if (topEntity == null && damagedBy != null) { double topDamage = 0; for (Iterator<Map.Entry<UUID, DamagedBy>> it = damagedBy.entrySet().iterator(); it.hasNext();) { Map.Entry<UUID, DamagedBy> entry = it.next(); DamagedBy damaged = entry.getValue(); Entity entity = damaged.getEntity(); if (entity != null && entity.isValid() && !entity.isDead()) { boolean withinRange = withinRange(entity); if (withinRange && damaged.damage > topDamage) { topEntity = entity; topDamage = damaged.damage; topDamager = damaged; } } else { it.remove(); } } } return topEntity; }
@Nullable @Override public EntityData modify(Entity entity) { EntityData entityData = null; if (entity == null || entity.hasMetadata("notarget")) return entityData; if (worldName != null && !entity.getWorld().getName().equals(worldName)) return entityData; if (worldName == null) worldName = entity.getWorld().getName(); // Check to see if this is something we spawned, and has now been destroyed if (entities != null && entities.contains(entity) && !entity.isValid()) { entities.remove(entity); } else if (entity.isValid()) { if (modifiedEntities == null) modifiedEntities = new HashMap<>(); UUID entityId = entity.getUniqueId(); entityData = modifiedEntities.get(entityId); if (entityData == null) { entityData = new EntityData(entity); modifiedEntities.put(entityId, entityData); watch(entity); } } modifiedTime = System.currentTimeMillis(); return entityData; }
@Override public SpellResult perform(CastContext context) { Entity entity = context.getTargetEntity(); if (ignoreInvalid && !entity.isValid()) { return SpellResult.NO_TARGET; } context.registerModified(entity); entity.remove(); return SpellResult.CAST; }
public void restoreEntities(MinigamePlayer player) { Iterator<EntityData> it = entdata.values().iterator(); while (it.hasNext()) { EntityData entdata = it.next(); if (player == null || player.equals(entdata.getModifier())) { if (entdata.wasCreated()) { Entity ent = entdata.getEntity(); // Entity needs to be removed if (ent.isValid()) { ent.remove(); } } else { // Entity needs to be spawned Location location = entdata.getEntityLocation(); location.getWorld().spawnEntity(location, entdata.getEntityType()); } it.remove(); } } }
@Override public boolean isValid() { if (forget) return false; if (!hasEntity) return true; Entity entity = getEntity(); if (entity == null) return false; if (!isNPC && entity instanceof Player) { Player player = (Player)entity; return player.isOnline(); } if (entity instanceof LivingEntity) { LivingEntity living = (LivingEntity)entity; return !living.isDead(); } // Automata theoretically handle themselves by sticking around for a while // And forcing themselves to be forgotten // but maybe some extra safety here would be good? return entity.isValid(); }
@Nullable @Override public Entity undo() { Entity entity = this.getEntity(); // Re-spawn if dead or missing if (respawn && !isTemporary && uuid != null && (entity == null || !entity.isValid() || entity.isDead()) && !(entity instanceof Player)) { // Avoid re-re-spawning an entity WeakReference<Entity> respawnedEntity = respawned.get(uuid); if (respawnedEntity != null) { entity = respawnedEntity.get(); } else { entity = trySpawn(null, null); if (entity != null) { respawned.put(uuid, new WeakReference<>(entity)); // Undo'ing an entity won't drop loot entity.setMetadata("nodrops", new FixedMetadataValue(MagicPlugin.getAPI().getPlugin(), true)); } } setEntity(entity); } else if (entity != null) { modify(entity); } return entity; }
public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException { if (entity == null || !entity.isValid()) { return;
if (entity == null || !entity.isValid()) { return new ArrayList<>();
protected void tick(Block b) throws Exception { Iterator<Entity> iterator = me.mrCookieSlime.Slimefun.holograms.XPCollector.getArmorStand(b).getNearbyEntities(4D, 4D, 4D).iterator(); while (iterator.hasNext()) { Entity n = iterator.next(); if (n instanceof ExperienceOrb) { if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; if (n.isValid()) { int xp = getEXP(b) + ((ExperienceOrb) n).getExperience(); ChargableBlock.addCharge(b, -getEnergyConsumption()); n.remove(); int withdrawn = 0; for (int level = 0; level < getEXP(b); level = level + 10) { if (fits(b, new CustomItem(Material.EXPERIENCE_BOTTLE, "&aFlask of Knowledge", 0))) { withdrawn = withdrawn + 10; pushItems(b, new CustomItem(Material.EXPERIENCE_BOTTLE, "&aFlask of Knowledge", 0)); } } BlockStorage.addBlockInfo(b, "stored-exp", String.valueOf(xp - withdrawn)); return; } } } }
public void deactivate() { isActive = false; if (spawned != null) { for (WeakReference<Entity> mobReference : spawned) { Entity mob = mobReference.get(); if (mob != null && mob.isValid()) { mob.remove(); } } } if (effectContext != null) { effectContext.cancelEffects(); effectContext = null; } if (mage != null) { mage.deactivate(); mage.undoScheduled(); if (template != null && template.isUndoAll()) { UndoList undone = mage.undo(); while (undone != null) { undone = mage.undo(); } } controller.forgetMage(mage); mage = null; } }
@Override public SpellResult step(CastContext context) { ActionHandler actions = getHandler("actions"); if (entity == null) { SpellResult result = spawn(context); if (!result.isSuccess() || actions == null || actions.size() == 0) { return result; } } if (actions == null || actions.size() == 0) { // This shouldn't really ever happen, but just in case we don't want to get stuck here. return SpellResult.NO_ACTION; } Entity spawned = entity.get(); if (spawned == null || spawned.isDead() || !spawned.isValid()) { if (setTarget && spawned != null) { createActionContext(context, spawned, spawned.getLocation(), spawned, spawned.getLocation()); } return startActions(); } return SpellResult.PENDING; }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); if (entity instanceof Projectile || entity instanceof TNTPrimed) return; if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) return; Entity damager = event.getDamager(); UndoList undoList = controller.getEntityUndo(damager); if (undoList != null) { // Prevent dropping items from frames, if (undoList.isScheduled()) { undoList.damage(entity); if (!entity.isValid()) { event.setCancelled(true); } } else { undoList.modify(entity); } } }
@Override public PowerResult<Boolean> swapToMainhand(Player player, ItemStack stack, PlayerSwapHandItemsEvent event) { checkCooldown(this, player, cooldown, false, true); UUID translocatorUUID = playerTranslocatorMap.getIfPresent(player.getUniqueId()); if (translocatorUUID == null) { return PowerResult.fail(); } playerTranslocatorMap.invalidate(player.getUniqueId()); translocatorPlayerMap.invalidate(translocatorUUID); Entity translocator = Bukkit.getServer().getEntity(translocatorUUID); if (translocator == null) { return PowerResult.fail(); } if (translocator.isDead() || !translocator.isValid()) { translocator.remove(); return PowerResult.fail(); } translocator.remove(); if (!getItem().consumeDurability(stack, tpCost)) return PowerResult.cost(); Location newLoc = translocator.getLocation(); Vector direction = player.getLocation().getDirection(); newLoc.setDirection(direction); World world = newLoc.getWorld(); player.teleport(newLoc); world.playEffect(newLoc, Effect.ENDER_SIGNAL, 0); world.playSound(newLoc, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 0.3f); return PowerResult.ok(true); }