本文整理了Java中org.bukkit.entity.Entity.isValid()
方法的一些代码示例,展示了Entity.isValid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.isValid()
方法的具体详情如下:
包路径:org.bukkit.entity.Entity
类名称:Entity
方法名:isValid
[英]Returns false if the entity has died or been despawned for some other reason.
[中]
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public final Entity getSource() {
return (source != null && source.isValid()) ? source : null;
}
代码示例来源:origin: bergerkiller/BKCommonLib
@Override
public boolean isValid() {
return base.isValid();
}
代码示例来源:origin: bergerkiller/BKCommonLib
public boolean isValid() {
return entity.isValid();
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: elBukkit/MagicPlugin
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();
}
}
}
代码示例来源:origin: Slikey/EffectLib
public boolean hasValidEntity() {
Entity entity = this.getEntity();
return entity != null && entity.isValid();
}
}
代码示例来源:origin: CitizensDev/CitizensAPI
@Override
public boolean isSpawned() {
return getEntity() != null && getEntity().isValid();
}
代码示例来源:origin: elBukkit/MagicPlugin
@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;
}
代码示例来源:origin: elBukkit/MagicPlugin
@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;
}
代码示例来源:origin: elBukkit/MagicPlugin
@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;
}
代码示例来源:origin: AddstarMC/Minigames
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();
}
}
}
代码示例来源:origin: elBukkit/MagicPlugin
@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();
}
代码示例来源:origin: elBukkit/MagicPlugin
@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;
}
代码示例来源:origin: aadnk/ProtocolLib
public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException {
if (entity == null || !entity.isValid()) {
return;
代码示例来源:origin: aadnk/ProtocolLib
if (entity == null || !entity.isValid()) {
return new ArrayList<>();
代码示例来源:origin: TheBusyBiscuit/Slimefun4
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;
}
}
}
}
代码示例来源:origin: elBukkit/MagicPlugin
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;
}
}
代码示例来源:origin: elBukkit/MagicPlugin
@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;
}
代码示例来源:origin: elBukkit/MagicPlugin
@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);
}
}
}
代码示例来源:origin: NyaaCat/RPGItems-reloaded
@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);
}
内容来源于网络,如有侵权,请联系作者删除!