Java 类org.bukkit.entity.LivingEntity 实例源码

项目:Crescent    文件:KillauraC.java   
@Override
public void call(Event event) {
    if (event instanceof EntityDamageByEntityEvent) {
        final EntityDamageByEntityEvent edbe = (EntityDamageByEntityEvent) event;

        if (edbe.getEntity() instanceof LivingEntity) {
            final LivingEntity le = (LivingEntity) edbe.getEntity();

            final Location eye = profile.getPlayer().getEyeLocation();

            final double yawBetween = Helper.getYawBetween(eye, le.getLocation());
            final double playerYaw = profile.getPlayer().getEyeLocation().getYaw();

            final double angleBetween = Math.abs(180 - Math.abs(Math.abs(yawBetween - playerYaw) - 180));

            callback(angleBetween >= DISALLOWED_ANGLE && previousAngles.size() >= NEEDED_SAMPLES
                    && getAverageAngle() >= DISALLOWED_ANGLE);

            previousAngles.put(angleBetween, System.currentTimeMillis());
        }
    }
}
项目:bskyblock    文件:Schematic.java   
/**
 * 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);
            }
        }
    }
}
项目:ZentrelaRPG    文件:TeleportSpell.java   
public void castSpell(final LivingEntity caster, final MobData md, Player target) {
    final Location loc = target.getLocation();
    if (RMath.flatDistance(caster.getLocation(), loc) < 50) {
        RScheduler.schedule(SakiRPG.plugin, new Runnable() {
            public void run() {
                if (target != null && target.isOnline()) {
                    for (Entity e : RMath.getNearbyEntities(loc, 2))
                        if (e instanceof Player)
                            return;
                    md.entity.teleport(loc);
                    md.invuln = System.currentTimeMillis() + 1000;
                }
            }
        });
    }
}
项目:Warzone    文件:DamageAPI.java   
/**
 * Inflicts the given damage on an entity.
 *
 * This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
 *
 * @param entity Entity to inflict damage upon
 * @param damage Amount of half-hearts of damage to inflict
 * @param info {@link DamageInfo} object that details the type of damage
 * @return the final {@link Damage} object (never null)
 *
 * @throws NullPointerException if entity or info is null
 * throws IllegalArgumentExcpetion if hearts is less than zero
 */
public static @Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
    Preconditions.checkNotNull(entity, "living entity");
    Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
    Preconditions.checkNotNull(info, "damage info");

    DamageAPIHelper helper = DamageAPIHelper.get();

    EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
    helper.setEventDamageInfo(event, info);

    Bukkit.getPluginManager().callEvent(event);

    if(event.isCancelled()) {
        return null;
    }

    entity.damage(event.getDamage());

    helper.setEventDamageInfo(event, null);

    return helper.getOurEvent(event).toDamageObject();
}
项目:AddGun    文件:StandardGun.java   
/**
 * This figures out if the gun's ammo is in the entity's inventory. 
 * 
 * @param entity the entity to check
 * @return the Bullet type found that is valid for this gun, or null.
 */
public Bullet getAmmo(LivingEntity entity) {
    if (entity == null || !enabled)
        return null;

    ItemStack[] inv;
    if (entity instanceof InventoryHolder) {
        // complex inventory
        InventoryHolder holder = (InventoryHolder) entity;
        inv = holder.getInventory().getContents();
    } else {
        // simple inventory
        inv = entity.getEquipment().getArmorContents();
    }

    if (inv != null) {
        for (ItemStack item : inv) {
            Bullet bullet = AddGun.getPlugin().getAmmo().findBullet(item);
            if (bullet != null && this.allBullets.contains(bullet.getName())) {
                return bullet;
            }
        }
    }
    return null;
}
项目:ZentrelaRPG    文件:QuadBeamSpell.java   
private ArrayList<Vector> getVectorsNormal(LivingEntity e) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = e.getEyeLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 4; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 2));
        v2.setZ(Math.sin(radians + k * Math.PI / 2));
        vectors.add(v2.normalize());
    }
    return vectors;
}
项目:AddGun    文件:StandardGun.java   
/**
 * Check if this living entity has a gun of this type already in possession
 * @param entity the entity to check
 * @return true if already in inventory, false otherwise.
 */
public boolean hasGun(LivingEntity entity) {
    if (entity == null || !enabled)
        return false;

    ItemStack[] inv;
    if (entity instanceof InventoryHolder) {
        // complex inventory
        InventoryHolder holder = (InventoryHolder) entity;
        inv = holder.getInventory().getContents();
    } else {
        // simple inventory
        inv = entity.getEquipment().getArmorContents();
    }

    if (inv != null) {
        for (ItemStack item : inv) {
            if (isGun(item)) {
                return true;
            }
        }
    }
    return false;
}
项目:Hub    文件:DoubleJumpListener.java   
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
    if (event.getPlayer().getGameMode() != GameMode.ADVENTURE)
        return;

    if (event.getPlayer().getAllowFlight())
        return;

    if (this.hub.getPlayerManager().isBusy(event.getPlayer()))
        return;

    if (((LivingEntity) event.getPlayer()).isOnGround())
    {
        event.getPlayer().setAllowFlight(true);
        this.allowed.add(event.getPlayer().getUniqueId());
    }
}
项目:RPGInventory    文件:PetListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    PlayerWrapper playerWrapper = InventoryManager.get(player);
    if (playerWrapper.hasPet() && playerWrapper.getPet().getPassenger() != player) {
        LivingEntity petEntity = playerWrapper.getPet();
        PetType pet = PetManager.getPetFromEntity(petEntity, player);
        if (pet != null && pet.getRole() != PetType.Role.COMPANION) {
            EntityUtils.goPetToPlayer(player, petEntity);
        }
    }
}
项目:Warzone    文件:MeleeDamageResolver.java   
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent && damageEvent.getCause() == DamageCause.ENTITY_ATTACK) {
        EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) damageEvent;

        if(entityEvent.getDamager() instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) entityEvent.getDamager();

            Material weaponMaterial;
            ItemStack held = attacker.getEquipment().getItemInMainHand();
            if(held != null) {
                weaponMaterial = held.getType();
            } else {
                weaponMaterial = Material.AIR;
            }

            return new SimpleMeleeDamageInfo(attacker, weaponMaterial);
        }
    }

    return null;
}
项目:Yasui    文件:Main.java   
public void disableAI() {
    for (World world : getServer().getWorlds()) {
        if (config.ignored_world.contains(world.getName())) {
            continue;
        }
        if (world.getLivingEntities().size() >= this.config.world_entity) {
            if (!disableAIWorlds.contains(world.getName())) {
                disableAIWorlds.add(world.getName());
                getLogger().info("disable entity ai in " + world.getName());
            }
            for (Chunk chunk : world.getLoadedChunks()) {
                int entityCount = getLivingEntityCount(chunk);
                if (entityCount >= this.config.chunk_entity) {
                    for (Entity entity : chunk.getEntities()) {
                        if (entity instanceof LivingEntity) {
                            setFromMobSpawner((LivingEntity) entity, true);
                        }
                    }
                }
            }
        }
    }
}
项目:Uranium    文件:CraftWorld.java   
public List<LivingEntity> getLivingEntities() {
    List<LivingEntity> list = new ArrayList<LivingEntity>();

    for (Object o : world.loadedEntityList) {
        if (o instanceof net.minecraft.entity.Entity) {
            net.minecraft.entity.Entity mcEnt = (net.minecraft.entity.Entity) o;
            Entity bukkitEntity = mcEnt.getBukkitEntity();

            // Assuming that bukkitEntity isn't null
            if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) {
                list.add((LivingEntity) bukkitEntity);
            }
        }
    }

    return list;
}
项目:KingdomFactions    文件:Confuse.java   
@Override
public void execute(KingdomFactionsPlayer player) {

    setLocation(player.getPlayer().getTargetBlock((Set<Material>) null, 80).getLocation());

    SpellExecuteEvent event = new SpellExecuteEvent(executeLocation, this, player);
    if (event.isCancelled())
        return;
    playEffect(executeLocation);
    for (Entity e : Utils.getInstance().getNearbyEntities(executeLocation, 3)) {
        if (e instanceof LivingEntity) {
            LivingEntity en = (LivingEntity) e;

            if (e instanceof Player) {
                Player p = (Player) e;
                if (PlayerModule.getInstance().getPlayer(p).isVanished()) continue;
                en.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 5 * 20, 1));
                en.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 5 * 20, 1));
                en.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 5 * 20, 1));
            }
        }
    }

}
项目:ZentrelaRPG    文件:SentinelBossGenerator.java   
private ArrayList<Vector> getVectorsFlameWave(LivingEntity e) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = e.getEyeLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 24; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 12));
        v2.setZ(Math.sin(radians + k * Math.PI / 12));
        vectors.add(v2.normalize());
    }
    return vectors;
}
项目:ZentrelaRPG    文件:FireBoltSpell.java   
public void castSpell(final LivingEntity caster, final MobData md, Player target) {
    final ArrayList<Entity> hit = new ArrayList<Entity>();
    for (int height = 1; height <= 3; height++) {
        final Location start = md.entity.getLocation();
        start.setY(start.getY() + 0.7 * height);
        for (Vector v : getVectorsNormal(md.entity)) {
            ArrayList<Location> locs = RMath.calculateVectorPath(start.clone(), v, range, 2);
            int count = 0;
            for (int k = 0; k < locs.size(); k++) {
                final Location loc = locs.get(k);
                RScheduler.schedule(Spell.plugin, new Runnable() {
                    public void run() {
                        RParticles.showWithOffset(ParticleEffect.FLAME, loc, 0.2, 1);
                        int damage = (int) (md.getDamage() * 1.2);
                        ArrayList<Entity> damaged = Spell.damageNearby(damage, md.entity, loc, 1.0, hit, true, false, true);
                        hit.addAll(damaged);
                    }
                }, 1 * count);
                if (k % 2 == 0)
                    count++;
            }
        }
    }
}
项目:ZentrelaRPG    文件:MelodaIceSpell.java   
public void castSpell(final LivingEntity caster, final MobData md, Player target) {
    final ArrayList<Entity> hit = new ArrayList<Entity>();
    final Location start = md.entity.getLocation();
    start.setY(start.getY() + 1.2);
    for (Vector v : getVectorsNormal(md.entity)) {
        ArrayList<Location> locs = RMath.calculateVectorPath(start.clone(), v, range, 2);
        int count = 0;
        for (int k = 0; k < locs.size(); k++) {
            final Location loc = locs.get(k);
            RScheduler.schedule(Spell.plugin, new Runnable() {
                public void run() {
                    ParticleEffect.REDSTONE.display(null, loc, Color.AQUA, 100, 0.2f, 0.2f, 0.2f, 1, 2);
                    int damage = (int) (md.getDamage() * 1.2);
                    ArrayList<Entity> damaged = Spell.damageNearby(damage, md.entity, loc, 1.0, hit, true, false, true);
                    hit.addAll(damaged);
                }
            }, 1 * count);
            if (k % 2 == 0)
                count++;
        }
    }
}
项目:ZentrelaRPG    文件:MelodaIceSpell.java   
private ArrayList<Vector> getVectorsNormal(LivingEntity e) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = e.getEyeLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 12; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 6));
        v2.setZ(Math.sin(radians + k * Math.PI / 6));
        vectors.add(v2.normalize());
    }
    return vectors;
}
项目:ZentrelaRPG    文件:FreezeSpell.java   
public void castSpell(final LivingEntity caster, final MobData md, Player target) {
    ArrayList<Location> locs = RLocation.findCastableLocs(caster.getLocation(), range, count);
    for (Location loc : locs) {
        FreezeSpellEffect effect = new FreezeSpellEffect(EffectFactory.em(), loc.add(0, 0.15, 0), 3);
        effect.setEntity(caster);
        effect.start();
        RScheduler.schedule(Spell.plugin, () -> {
            Entity activator = null;
            for (Entity e : RMath.getNearbyEntities(loc, 1)) {
                if (e instanceof Player && Spell.canDamage(e, false)) {
                    ((Player) e).addPotionEffect(new PotionEffect(PotionEffectType.JUMP, RTicks.seconds(durationSec), -100), false);
                    ((Player) e).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, RTicks.seconds(durationSec), -100), false);
                    activator = e;
                }
            }
            if (activator != null) {
                FreezeSpellEndEffect end = new FreezeSpellEndEffect(EffectFactory.em(), loc, durationSec);
                end.setEntity(activator);
                end.start();
            }
        }, RTicks.seconds(3));
    }
}
项目:SamaGamesAPI    文件:Camera.java   
Camera(Location initialPosition, boolean fixed)
{
    this.viewers = new ConcurrentHashMap<>();
    this.fixed = fixed;

    World world = ((CraftWorld) initialPosition.getWorld()).getHandle();
    this.entityCamera = new EntityCamera(world);
    this.entityCamera.setPosition(initialPosition.getX(), initialPosition.getY(), initialPosition.getZ());
    world.addEntity(this.entityCamera, CreatureSpawnEvent.SpawnReason.CUSTOM);
    ((LivingEntity) this.entityCamera.getBukkitEntity()).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false, false));
}
项目:Warzone    文件:SimpleLifetimeManager.java   
public @Nonnull
Lifetime newLifetime(@Nonnull LivingEntity entity) {
    Preconditions.checkNotNull(entity, "entity");

    Lifetime lifetime = new SimpleLifetime();
    this.lifetimes.put(entity, lifetime);

    return lifetime;
}
项目:PetBlocks    文件:CustomGroundArmorstand.java   
public void spawn(Location location) {
    final PetBlockSpawnEvent event = new PetBlockSpawnEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCanceled()) {
        NMSRegistry.accessWorldGuardSpawn(location);
        this.rabbit.spawn(location);
        final World mcWorld = ((CraftWorld) location.getWorld()).getHandle();
        this.setPosition(location.getX(), location.getY(), location.getZ());
        mcWorld.addEntity(this, SpawnReason.CUSTOM);
        final NBTTagCompound compound = new NBTTagCompound();
        compound.setBoolean("invulnerable", true);
        compound.setBoolean("Invisible", true);
        compound.setBoolean("PersistenceRequired", true);
        compound.setBoolean("ShowArms", true);
        compound.setBoolean("NoBasePlate", true);
        this.a(compound);
        ((ArmorStand) this.getArmorStand()).setBodyPose(new EulerAngle(0, 0, 2878));
        ((ArmorStand) this.getArmorStand()).setLeftArmPose(new EulerAngle(2878, 0, 0));
        ((ArmorStand) this.getArmorStand()).setMetadata("keep", this.getKeepField());
        NMSRegistry.rollbackWorldGuardSpawn(location);
        ((ArmorStand) this.getArmorStand()).setCustomNameVisible(true);
        ((ArmorStand) this.getArmorStand()).setCustomName(this.petMeta.getPetDisplayName());
        ((ArmorStand) this.getArmorStand()).setRemoveWhenFarAway(false);
        ((LivingEntity) this.getEngineEntity()).setRemoveWhenFarAway(false);
        this.health = ConfigPet.getInstance().getCombat_health();
        if (this.petMeta == null)
            return;
        PetBlockHelper.setItemConsideringAge(this);
    }
}
项目:ProjectAres    文件:OwnedMobTracker.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMobDispense(BlockDispenseEntityEvent event) {
    if(event.getEntity() instanceof LivingEntity) {
        ParticipantState owner = blocks().getOwner(event.getBlock());
        if(owner != null) {
            entities().trackEntity(event.getEntity(), new MobInfo((LivingEntity) event.getEntity(), owner));
        }
    }
}
项目:Scorch    文件:EnchantListener.java   
private ArrayList<ItemStack> getItems(LivingEntity entity) {
    ItemStack[] armor = entity.getEquipment().getArmorContents();
    ItemStack weapon = entity.getEquipment().getItemInHand();
    ArrayList<ItemStack> items = new ArrayList<>(Arrays.asList(armor));
    items.add(weapon);

    return items;
}
项目:PetBlocks    文件:CustomZombie.java   
/**
 * Spawns the entity at the given location
 *
 * @param mLocation location
 */
@Override
public void spawn(Object mLocation) {
    final Location location = (Location) mLocation;
    final LivingEntity entity = (LivingEntity) this.getEntity();
    final net.minecraft.server.v1_12_R1.World mcWorld = ((CraftWorld) location.getWorld()).getHandle();
    this.setPosition(location.getX(), location.getY(), location.getZ());
    mcWorld.addEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
    entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 9999999, 1));
    entity.setMetadata("keep", this.getKeepField());
    entity.setCustomNameVisible(false);
    entity.setCustomName("PetBlockIdentifier");
}
项目:ProjectAres    文件:HitboxPlayerFacet.java   
public static Cuboid hitbox(Match match, LivingEntity victim) {
    if(victim instanceof Player) {
        final MatchPlayer matchVictim = match.getPlayer(victim);
        if(matchVictim != null) {
            return matchVictim.facet(HitboxPlayerFacet.class).hitbox();
        }
    }
    return victim.getBoundingBox();
}
项目:AddGun    文件:StandardGun.java   
/**
 * This computes if enough XP is present to fire the gun and bullet that's chambered
 * 
 * @param entity the shooter
 * @param bullet the Bullet type that's chambered
 * @return true if enough fuel, false otherwise
 */
boolean hasFuel(LivingEntity entity, Bullet bullet) {
    if (!this.usesXP && !bullet.getUsesXP()) return true; // no xp needs.

    int totalDraw = this.xpDraw + bullet.getXPDraw();

    int xpNeeds = computeTotalXP(entity) - totalDraw; 

    if (xpNeeds < 0 && (xpNeeds + AddGun.getPlugin().getXpPerBottle() * getInvXp(entity) < 0)) {
        return false;
    }

    return true;
}
项目:PetBlocks    文件:CustomGroundArmorstand.java   
public void spawn(Location location) {
    final PetBlockSpawnEvent event = new PetBlockSpawnEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCanceled()) {
        NMSRegistry.accessWorldGuardSpawn(location);
        this.rabbit.spawn(location);
        final net.minecraft.server.v1_9_R1.World mcWorld = ((CraftWorld) location.getWorld()).getHandle();
        this.setPosition(location.getX(), location.getY(), location.getZ());
        mcWorld.addEntity(this, SpawnReason.CUSTOM);
        final NBTTagCompound compound = new NBTTagCompound();
        compound.setBoolean("invulnerable", true);
        compound.setBoolean("Invisible", true);
        compound.setBoolean("PersistenceRequired", true);
        compound.setBoolean("ShowArms", true);
        compound.setBoolean("NoBasePlate", true);
        this.a(compound);
        ((ArmorStand)this.getArmorStand()).setBodyPose(new EulerAngle(0, 0, 2878));
        ((ArmorStand)this.getArmorStand()).setLeftArmPose(new EulerAngle(2878, 0, 0));
        ((ArmorStand)this.getArmorStand()).setMetadata("keep", this.getKeepField());
        NMSRegistry.rollbackWorldGuardSpawn(location);
        ((ArmorStand)this.getArmorStand()).setCustomNameVisible(true);
        ((ArmorStand)this.getArmorStand()).setCustomName(this.petMeta.getPetDisplayName());
        ((ArmorStand)this.getArmorStand()).setRemoveWhenFarAway(false);
        ((LivingEntity) this.getEngineEntity()).setRemoveWhenFarAway(false);
        this.health = ConfigPet.getInstance().getCombat_health();
        if (this.petMeta == null)
            return;
        PetBlockHelper.setItemConsideringAge(this);
    }
}
项目:ProjectAres    文件:CombatLogTracker.java   
private static double getResistanceFactor(LivingEntity entity) {
    int amplifier = 0;
    for(PotionEffect effect : entity.getActivePotionEffects()) {
        if(PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType()) && effect.getAmplifier() > amplifier) {
            amplifier = effect.getAmplifier();
        }
    }
    return 1d - (amplifier / 5d);
}
项目:KingdomFactions    文件:Spark.java   
@Override
public void execute(KingdomFactionsPlayer player) {

    setLocation(player.getPlayer().getTargetBlock((Set<Material>) null, 80).getLocation());

    SpellExecuteEvent event = new SpellExecuteEvent(executeLocation, this, player);
    if (event.isCancelled())
        return;
    playSmoke(executeLocation);
    for (Entity e : Utils.getInstance().getNearbyEntities(executeLocation, 3)) {
        if (e instanceof LivingEntity) {
            LivingEntity en = (LivingEntity) e;

            if (e instanceof Player) {
                Player p = (Player) e;
                if (PlayerModule.getInstance().getPlayer(p).isVanished())
                    return;
                if (en.getHealth() > 5) {
                    en.damage(5D);
                } else {
                    en.damage(en.getHealth());
                }
            }
        }
    }

}
项目:Kineticraft    文件:ActionEntity.java   
/**
 * Toggle the entities AI until it should expire.
 * Does not conflict with other AI toggles.
 * @param done
 */
public void toggleAI(Function<LivingEntity, Boolean> done) {
    LivingEntity le = getLivingEntity();
    BukkitTask[] task = new BukkitTask[1];
    le.setAI(true);
    task[0] = Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
        boolean isDone = done.apply(le);
        le.setAI(!isDone);
        if (isDone)
            task[0].cancel();
    }, 10L, 20L);
}
项目:WC    文件:WorldManager.java   
private void exterminate(){
    world.getEntities().forEach(e -> {
        if (e instanceof Monster || e instanceof Animals){
            LivingEntity le = (LivingEntity)e;
            le.damage(le.getMaxHealth());
        }
        if (e instanceof Item){
            e.remove();
        }
    });
}
项目:Kineticraft    文件:Leashes.java   
@EventHandler(ignoreCancelled = true)
public void onLeash(PlayerInteractEntityEvent evt) {
    if (!LEASHABLE.contains(evt.getRightClicked().getType()) || Utils.inSpawn(evt.getRightClicked().getLocation()))
        return;

    LivingEntity e = (LivingEntity) evt.getRightClicked();
    ItemStack hand = evt.getPlayer().getInventory().getItem(evt.getHand());
    if (hand == null || hand.getType() != Material.LEASH || e.isLeashed())
        return;

    evt.setCancelled(true); // Don't open merchant GUI.
    Utils.useItem(hand);
    Bukkit.getScheduler().runTask(Core.getInstance(), () -> e.setLeashHolder(evt.getPlayer()));
}
项目:Warzone    文件:GravityDamageResolver.java   
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(!(entity instanceof Player)) return null;
    Player victim = (Player) entity;
    Fall fall = this.tracker.getCausingFall(victim, damageEvent.getCause());
    if(fall != null) {
        return new GravityDamageInfo(fall.attacker, fall.cause, fall.from);
    } else {
        return null;
    }
}
项目:PetBlocks    文件:PetBlockHelper.java   
public static void remove(PetBlock petBlock) {
    if (petBlock.getEngineEntity() != null && !((LivingEntity) petBlock.getEngineEntity()).isDead()) {
        ((LivingEntity) petBlock.getEngineEntity()).remove();
    }
    if (!((LivingEntity) petBlock.getArmorStand()).isDead()) {
        ((LivingEntity) petBlock.getArmorStand()).remove();
    }
}
项目:Warzone    文件:GravityDamageInfo.java   
public GravityDamageInfo(@Nullable LivingEntity resolvedDamager, @Nonnull Fall.Cause cause, @Nonnull Fall.From from) {
    super(resolvedDamager);

    Preconditions.checkNotNull(resolvedDamager, "damager");
    Preconditions.checkNotNull(cause, "cause");
    Preconditions.checkNotNull(from, "from");

    this.cause = cause;
    this.from = from;
}
项目:HCFCore    文件:InvincibilityTimer.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPotionSplash(PotionSplashEvent event) {
    ThrownPotion potion = event.getPotion();
    if (potion.getShooter() instanceof Player && BukkitUtils.isDebuff(potion)) {
        for (LivingEntity livingEntity : event.getAffectedEntities()) {
            if (livingEntity instanceof Player) {
                if (getRemaining((Player) livingEntity) > 0L) {
                    event.setIntensity(livingEntity, 0);
                }
            }
        }
    }
}
项目:MT_Core    文件:MobManager.java   
/**
 * Loop over all entities and kill them if they are not a zombie, pig, enderman, cow, squid or sheep.
 * @param loaded the chunk which was loaded
 */
public void clearUnwantedMobs(Chunk loaded){
       Arrays.stream(loaded.getEntities()).filter(e -> e instanceof LivingEntity).filter(entity ->
               (entity.getType().isAlive() && entity.getType() != EntityType.PLAYER
               && entity.getType() != EntityType.ZOMBIE && entity.getType() != EntityType.ENDERMAN
               && entity.getType() != EntityType.PIG && entity.getType() != EntityType.COW
               && entity.getType() != EntityType.SHEEP && entity.getType() != EntityType.SQUID)
               ).forEach(entity -> ((LivingEntity)entity).damage(((LivingEntity) entity).getHealth() + 1));
}
项目:Kineticraft    文件:CustomAttack.java   
/**
 * Execute this attack as a given entity.
 * @param attacker
 */
public void handleAttack(Entity attacker) {
    this.source = attacker;
    List<LivingEntity> targets = attacker.getNearbyEntities(getRadius(), getRadius(), getRadius()).stream()
            .filter(e -> e instanceof LivingEntity).map(e -> (LivingEntity) e).filter(this::canAttack).collect(Collectors.toList());
    showDisplay(targets);
    targets.forEach(this::attack);
}
项目:mczone    文件:PetInstance.java   
public void spawn() {
    setSpawned(true);
    Player owner = Bukkit.getPlayerExact(this.owner);
    if (owner == null)
        return;

    Location spawnTo = owner.getLocation();
       entity = (LivingEntity) spawnTo.getWorld().spawnEntity(spawnTo, getType());
       update();
}
项目:Uranium    文件:CraftProjectile.java   
@Deprecated
public void _INVALID_setShooter(LivingEntity shooter) {
    if (shooter == null) {
        return;
    }
    getHandle().thrower = ((CraftLivingEntity) shooter).getHandle();
    if (shooter instanceof CraftHumanEntity) {
        getHandle().throwerName = ((CraftHumanEntity) shooter).getName();
    }
}