Search in sources :

Example 86 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Ublisk by Derkades.

the class Zombie method getMobCode.

@Override
public MobCode getMobCode() {
    return new MobCode() {

        @Override
        public void mobCode(LivingEntity entity) {
            // We can safely cast, because this code will only run on zombies
            org.bukkit.entity.Zombie zombie = (org.bukkit.entity.Zombie) entity;
            // Clear equipment
            EntityEquipment equipment = zombie.getEquipment();
            ItemStack air = new ItemStack(Material.AIR);
            equipment.setBoots(air);
            equipment.setLeggings(air);
            equipment.setChestplate(air);
            equipment.setHelmet(air);
            equipment.setItemInMainHand(air);
            equipment.setItemInOffHand(air);
            zombie.setBaby(isBaby());
        }
    };
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MobCode(xyz.derkades.ublisk.mob.MobCode) EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack)

Example 87 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Ublisk by Derkades.

the class MobSpawn method startMobSpawning.

public static void startMobSpawning() {
    if (MOB_SPAWNING_ACTIVE) {
        throw new UnsupportedOperationException("Mob spawning is already active");
    } else {
        MOB_SPAWNING_ACTIVE = true;
    }
    for (final Mob mob : Mobs.MOB_LIST) {
        double rate = mob.getSpawnRate() * 20;
        new BukkitRunnable() {

            public void run() {
                if (Bukkit.getOnlinePlayers().size() == 0 || mob.hasReachedSpawnLimit()) {
                    return;
                }
                Radius area = mob.getArea();
                boolean positiveX = Random.getRandomBoolean();
                boolean positiveZ = Random.getRandomBoolean();
                int radius = area.getRadius();
                int x = area.getX();
                int z = area.getZ();
                int randomX = Random.getRandomInteger(0, radius);
                int randomZ = Random.getRandomInteger(0, radius);
                if (positiveX) {
                    x = x + randomX;
                } else {
                    x = x - randomX;
                }
                if (positiveZ) {
                    z = z + randomZ;
                } else {
                    z = z - randomZ;
                }
                Location loc = new Location(Var.WORLD, x + 0.5, area.getY(), z + 0.5);
                if (!loc.getChunk().isLoaded()) {
                    return;
                }
                boolean noPlayerNearby = true;
                for (Player player : Var.WORLD.getEntitiesByClass(Player.class)) {
                    if (player.getLocation().distanceSquared(loc) < Math.pow(MAXIMUM_DISTANCE + area.getY(), 2)) {
                        noPlayerNearby = false;
                        break;
                    }
                }
                if (noPlayerNearby) {
                    return;
                }
                while (MOB_SPAWNING_AIR_BLOCKS.contains(loc.getBlock().getType())) {
                    loc.setY(loc.getY() - 1);
                }
                // Don't let mobs spawn on top of some blocks
                if (MOB_SPAWNING_CANCEL.contains(loc.getBlock().getType())) {
                    return;
                }
                loc.setY(loc.getY() + 1);
                if (!MOB_SPAWNING_AIR_BLOCKS.contains(loc.getBlock().getType()))
                    return;
                String name = DARK_AQUA + mob.getName() + DARK_GRAY + " [" + DARK_GREEN + mob.getLevel() + DARK_GRAY + "]";
                LivingEntity entity = (LivingEntity) Var.WORLD.spawnEntity(loc, mob.getEntityType());
                // Apply custom data
                entity.setCustomName(name);
                entity.setCustomNameVisible(true);
                double health = mob.getHealth();
                entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(health);
                entity.setHealth(health);
                entity.setRemoveWhenFarAway(true);
                // Look in a random direction
                Location tp = entity.getLocation();
                tp.setYaw(Random.getRandomInteger(0, 360));
                entity.teleport(tp);
                Ublisk.spawnParticle(Particle.EXPLOSION_NORMAL, tp, 20, 0, 0, 0, 0.1);
                // Execute mob code, if any
                MobCode code = mob.getMobCode();
                if (code != null)
                    code.mobCode(entity);
                Mobs.SPAWNED_MOBS.put(entity.getUniqueId(), mob);
            }
        }.runTaskTimer(Main.getInstance(), 2 * 20, (long) rate);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Example 88 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Ublisk by Derkades.

the class HomingArrowsListener method eventArrowFired.

@EventHandler
public void eventArrowFired(EntityShootBowEvent e) {
    if (((e.getEntity() instanceof LivingEntity)) && ((e.getProjectile() instanceof Arrow))) {
        LivingEntity player = e.getEntity();
        double minAngle = 6.283185307179586D;
        Entity minEntity = null;
        for (Entity entity : player.getNearbyEntities(64.0D, 64.0D, 64.0D)) {
            if ((player.hasLineOfSight(entity)) && ((entity instanceof LivingEntity)) && (!entity.isDead())) {
                Vector toTarget = entity.getLocation().toVector().clone().subtract(player.getLocation().toVector());
                double angle = e.getProjectile().getVelocity().angle(toTarget);
                if (angle < minAngle) {
                    minAngle = angle;
                    minEntity = entity;
                }
            }
        }
        if (minEntity != null)
            new HomingTask((Arrow) e.getProjectile(), (LivingEntity) minEntity);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Arrow(org.bukkit.entity.Arrow) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 89 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Ublisk by Derkades.

the class InvalidEntityCommand method onCommand.

@Override
protected void onCommand(UPlayer player, String[] args) {
    player.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Entity : X : Y : Z : Name");
    for (LivingEntity entity : Var.WORLD.getLivingEntities()) {
        if (!Mobs.SPAWNED_MOBS.containsKey(entity.getUniqueId())) {
            String color = "";
            if (Mobs.NON_MOB_ENTITIES.contains(entity.getType()))
                color = ChatColor.GREEN.toString();
            else
                color = ChatColor.RED.toString();
            int x = (int) entity.getLocation().getX();
            int y = (int) entity.getLocation().getY();
            int z = (int) entity.getLocation().getZ();
            player.sendMessage(color + entity.getType() + " : " + x + " : " + y + " : " + z + " : " + entity.getName());
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity)

Example 90 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Ublisk by Derkades.

the class Ublisk method createFakeExplosion.

/**
 * Creates a fake explosion with sounds and particles.
 * @param location The location to spawn the explosion at.
 * @param damage Damage to be dealt. This is divided by the number of blocks the entity is away from the explosion. E.g. with damage = 10, a zombie standing 3 blocks away will get 10/3 = 3.33 damage.
 * @param damageRadius See damage.
 * @param sound If an explosion sound should be played.
 * @param explosions Particles to summon. See Explosion enum.
 */
public static void createFakeExplosion(Location location, UPlayer source, int damage, double damageRadius, boolean sound, Explosion... explosions) {
    // Spawn particles
    for (Explosion explosion : explosions) {
        if (explosion == Explosion.BLAST_SMALL) {
            Ublisk.spawnParticle(Particle.EXPLOSION_LARGE, location, 1, 0, 0, 0, 0);
        } else if (explosion == Explosion.BLAST_LARGE) {
            Ublisk.spawnParticle(Particle.EXPLOSION_HUGE, location, 1, 0, 0, 0, 0);
        } else if (explosion == Explosion.FIRE) {
            Ublisk.spawnParticle(Particle.LAVA, location, 100, 1, 0, 1, 0.5);
        } else if (explosion == Explosion.FLAMES) {
            Ublisk.spawnParticle(Particle.FLAME, location, 48, 1, 1, 1, 0.1);
        } else if (explosion == Explosion.SMOKE) {
            Ublisk.spawnParticle(Particle.SMOKE_LARGE, location, 15, 0, 0, 0, 0.1);
        }
    }
    // Play sounds
    if (sound) {
        Ublisk.playSound(location, Sound.ENTITY_GENERIC_EXPLODE);
    }
    // Do damage
    List<Entity> near = location.getWorld().getEntities();
    for (Entity entity : near) {
        if (entity instanceof LivingEntity) {
            LivingEntity living = (LivingEntity) entity;
            double distance = entity.getLocation().distance(location);
            if (distance <= damageRadius)
                living.damage(damage / distance, source.getEntity());
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)322 Entity (org.bukkit.entity.Entity)169 Player (org.bukkit.entity.Player)121 Location (org.bukkit.Location)71 EventHandler (org.bukkit.event.EventHandler)63 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14