Search in sources :

Example 46 with LivingEntity

use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.

the class AttackWither method onHit.

@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata) && damagee instanceof LivingEntity) {
        ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 47 with LivingEntity

use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.

the class PowerHandler method powerHandler.

public static void powerHandler(Entity entity) {
    int availableMinorPowers = 0;
    int availableMajorPowers = 0;
    if (entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity.isValid() && ((LivingEntity) entity).getHealth() > 0) {
        if (entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= 5) {
            int EliteMobLevel = entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
            availableMinorPowers = (EliteMobLevel - 5) / 10 + 1;
            availableMajorPowers = EliteMobLevel / 10;
        }
    }
    if (availableMinorPowers >= 1) {
        int currentMinorPowerAmount = 0;
        if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
            return;
        }
        if (minorPowerArray.isEmpty()) {
            minorPowerArrayInitializer();
        }
        if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
            currentMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
            //TODO: this is probably not working as intended
            Iterator<MinorPowers> minorPowerIterator = minorPowerArray.iterator();
            while (minorPowerIterator.hasNext()) {
                MinorPowers minorPower = minorPowerIterator.next();
                if (minorPower.existingPowers(entity)) {
                    minorPowerIterator.remove();
                }
            }
        }
        int missingMinorPowerAmount = availableMinorPowers - currentMinorPowerAmount;
        if (missingMinorPowerAmount > 0 && minorPowerArray.size() > 0) {
            for (int i = 0; i < missingMinorPowerAmount; i++) {
                if (minorPowerArray.size() > 0) {
                    int randomizer = random.nextInt(minorPowerArray.size());
                    MinorPowers selectedMinorPower = minorPowerArray.get(randomizer);
                    minorPowerArray.remove(minorPowerArray.get(randomizer));
                    if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
                        int oldMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
                        int newMinorPowerAmount = oldMinorPowerAmount + 1;
                        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMinorPowerAmount));
                    } else {
                        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
                    }
                    selectedMinorPower.applyPowers(entity);
                }
            }
        }
    }
    if (availableMajorPowers >= 1) {
        int currentMajorPowerAmount = 0;
        if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
            return;
        }
        ArrayList<MajorPowers> majorPowersArrayList = new ArrayList();
        if (majorPowersArrayList.isEmpty()) {
            if (entity instanceof Zombie) {
                //These powers can't be intialized like minor powers because the list depends on the mob type
                //TODO: Add a mob type sensitive power list
                majorPowersArrayList.add(zombieFriends);
                majorPowersArrayList.add(zombieNecronomicon);
                majorPowersArrayList.add(zombieTeamRocket);
                majorPowersArrayList.add(zombieParents);
            }
        }
        if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
            currentMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
            Iterator<MajorPowers> majorPowerIterator = majorPowersArrayList.iterator();
            while (majorPowerIterator.hasNext()) {
                MajorPowers majorPowers = majorPowerIterator.next();
                if (majorPowers.existingPowers(entity)) {
                    majorPowerIterator.remove();
                }
            }
        }
        //TODO: pretty sure this doesn't check for level 10?
        int missingMajorPowerAmount = availableMajorPowers - currentMajorPowerAmount;
        if (missingMajorPowerAmount > 0 && majorPowersArrayList.size() > 0) {
            for (int i = 0; i < missingMajorPowerAmount; i++) {
                if (majorPowersArrayList.size() > 0) {
                    int randomizer = random.nextInt(majorPowersArrayList.size());
                    MajorPowers selectedMajorPower = majorPowersArrayList.get(randomizer);
                    majorPowersArrayList.remove(majorPowersArrayList.get(randomizer));
                    if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
                        int oldMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
                        int newMajorPowerAmount = oldMajorPowerAmount + 1;
                        entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMajorPowerAmount));
                    } else {
                        entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
                    }
                    selectedMajorPower.applyPowers(entity);
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MinorPowers(com.magmaguy.elitemobs.minorpowers.MinorPowers) Zombie(org.bukkit.entity.Zombie) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue)

Example 48 with LivingEntity

use of org.bukkit.entity.LivingEntity in project TotalFreedomMod by TotalFreedom.

the class ItemFun method onPlayerInteractEvent.

@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
        return;
    }
    final Player player = event.getPlayer();
    final FPlayer fPlayer = plugin.pl.getPlayer(player);
    switch(event.getMaterial()) {
        case RAW_FISH:
            {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;
                // Clownfish
                if (DepreciationAggregator.getData_MaterialData(event.getItem().getData()) != 2) {
                    break;
                }
                if (!plugin.al.isSeniorAdmin(player)) {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = ("You are a clown.").toCharArray();
                    for (char c : chars) {
                        msg.append(FUtil.randomChatColor()).append(c);
                    }
                    player.sendMessage(msg.toString());
                    player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM);
                    break;
                }
                event.setCancelled(true);
                boolean didHit = false;
                final Location playerLoc = player.getLocation();
                final Vector playerLocVec = playerLoc.toVector();
                final List<Player> players = player.getWorld().getPlayers();
                for (final Player target : players) {
                    if (target == player) {
                        continue;
                    }
                    final Location targetPos = target.getLocation();
                    final Vector targetPosVec = targetPos.toVector();
                    try {
                        if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) {
                            FUtil.setFlying(player, false);
                            target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                            didHit = true;
                        }
                    } catch (IllegalArgumentException ex) {
                    }
                }
                if (didHit) {
                    final Sound[] sounds = Sound.values();
                    for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                            playerLoc.getWorld().playSound(randomOffset(playerLoc, 5.0), sound, 100.0f, randomDoubleRange(0.5, 2.0).floatValue());
                        }
                    }
                }
                break;
            }
        case CARROT_ITEM:
            {
                if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                    break;
                }
                if (!plugin.al.isSeniorAdmin(player)) {
                    break;
                }
                Location location = player.getLocation().clone();
                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();
                double distance = 150.0;
                Block targetBlock = DepreciationAggregator.getTargetBlock(player, null, Math.round((float) distance));
                if (targetBlock != null) {
                    distance = location.distance(targetBlock.getLocation());
                }
                final List<Block> affected = new ArrayList<>();
                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                    Block block = playerPostion.clone().add(playerDirection.clone().multiply(offset)).toLocation(player.getWorld()).getBlock();
                    if (!block.equals(lastBlock)) {
                        if (block.isEmpty()) {
                            affected.add(block);
                            block.setType(Material.TNT);
                        } else {
                            break;
                        }
                    }
                    lastBlock = block;
                }
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        for (Block tntBlock : affected) {
                            TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                            tnt.setFuseTicks(5);
                            tntBlock.setType(Material.AIR);
                        }
                    }
                }.runTaskLater(plugin, 30L);
                event.setCancelled(true);
                break;
            }
        case BONE:
            {
                if (!fPlayer.mobThrowerEnabled()) {
                    break;
                }
                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();
                LivingEntity rezzed_mob = (LivingEntity) player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), fPlayer.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
                fPlayer.enqueueMob(rezzed_mob);
                event.setCancelled(true);
                break;
            }
        case SULPHUR:
            {
                if (!fPlayer.isMP44Armed()) {
                    break;
                }
                event.setCancelled(true);
                if (fPlayer.toggleMP44Firing()) {
                    fPlayer.startArrowShooter(plugin);
                } else {
                    fPlayer.stopArrowShooter();
                }
                break;
            }
        case BLAZE_ROD:
            {
                if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                    break;
                }
                if (!plugin.al.isSeniorAdmin(player)) {
                    break;
                }
                event.setCancelled(true);
                Block targetBlock;
                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                    targetBlock = DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                    targetBlock = event.getClickedBlock();
                }
                if (targetBlock == null) {
                    player.sendMessage("Can't resolve target block.");
                    break;
                }
                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());
                break;
            }
    }
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) Player(org.bukkit.entity.Player) TNTPrimed(org.bukkit.entity.TNTPrimed) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Sound(org.bukkit.Sound) FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) LivingEntity(org.bukkit.entity.LivingEntity) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 49 with LivingEntity

use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.

the class EventListener method onMobSpawn.

@EventHandler(priority = EventPriority.HIGH)
public void onMobSpawn(final CreatureSpawnEvent event) {
    LivingEntity e = event.getEntity();
    if (e.hasMetadata("NPC"))
        return;
    if (e.hasMetadata("shopkeeper"))
        return;
    if (e.getCustomName() != null)
        return;
    if (!ConfigReader.isEnabledWorld(e.getWorld()))
        return;
    if (!ConfigReader.isEnabledMobType(e.getType()))
        return;
    if (e.getLocation().getY() < ConfigReader.getNaturalSpawnMinHeight())
        return;
    if (!ConfigReader.getEnabledSpawnReasons().contains(event.getSpawnReason()))
        return;
    new BukkitRunnable() {

        @Override
        public void run() {
            plugin.mobManager.infernalNaturalSpawn(e);
        }
    }.runTaskLater(plugin, 10L);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 50 with LivingEntity

use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.

the class EventListener method onEntityAttack.

@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
    boolean isDirectAttack = true;
    Entity trueVictim = event.getEntity();
    Entity trueAttacker = event.getDamager();
    if (trueAttacker instanceof Projectile) {
        isDirectAttack = false;
        ProjectileSource src = ((Projectile) trueAttacker).getShooter();
        if (src instanceof Entity) {
            trueAttacker = (Entity) src;
        } else {
            return;
        }
    }
    if (!(trueAttacker instanceof LivingEntity))
        return;
    if (!(trueVictim instanceof LivingEntity))
        return;
    if (plugin.mobManager.mobMap.containsKey(trueVictim.getUniqueId())) {
        // something attacked infernal mob
        if (!(trueAttacker instanceof Player))
            return;
        if (((Player) trueAttacker).getGameMode() == GameMode.CREATIVE)
            return;
        Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
        for (EnumAbilities ab : mob.abilityList) {
            ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
        }
    }
    if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
        // infernal mob attacked something
        if (!(trueVictim instanceof Player))
            return;
        if (((Player) trueVictim).getGameMode() == GameMode.CREATIVE)
            return;
        Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
        for (EnumAbilities ab : mob.abilityList) {
            ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) Player(org.bukkit.entity.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)57 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)23 EventHandler (org.bukkit.event.EventHandler)22 Location (org.bukkit.Location)12 ArrayList (java.util.ArrayList)11 Vector (org.bukkit.util.Vector)10 Projectile (org.bukkit.entity.Projectile)9 PotionEffect (org.bukkit.potion.PotionEffect)9 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)8 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)7 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)7 ItemStack (org.bukkit.inventory.ItemStack)7 List (java.util.List)5 Element (net.aufdemrand.denizencore.objects.Element)5 Island (com.wasteofplastic.acidisland.Island)4 HashMap (java.util.HashMap)4 World (org.bukkit.World)4 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)4 Helper (com.jacob_vejvoda.infernal_mobs.Helper)3