Search in sources :

Example 26 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Sentinel by mcmonkey4eva.

the class SentinelTrait method whenAttacksAreHappening.

@EventHandler(priority = EventPriority.LOWEST)
public void whenAttacksAreHappening(EntityDamageByEntityEvent event) {
    if (!npc.isSpawned()) {
        return;
    }
    if (event.isCancelled()) {
        return;
    }
    if (event.getEntity().getUniqueId().equals(getLivingEntity().getUniqueId())) {
        if (!event.isApplicable(EntityDamageEvent.DamageModifier.ARMOR)) {
            event.setDamage(EntityDamageEvent.DamageModifier.BASE, (1.0 - getArmor(getLivingEntity())) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
        } else {
            event.setDamage(EntityDamageEvent.DamageModifier.ARMOR, -getArmor(getLivingEntity()) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
        }
        return;
    }
    if (event.getDamager().getUniqueId().equals(getLivingEntity().getUniqueId())) {
        if (SentinelPlugin.instance.getConfig().getBoolean("random.enforce damage", false)) {
            if (canEnforce) {
                canEnforce = false;
                whenAttacksHappened(event);
                if (!event.isCancelled()) {
                    ((LivingEntity) event.getEntity()).damage(event.getFinalDamage());
                }
                if (SentinelPlugin.debugMe) {
                    SentinelPlugin.instance.getLogger().info("Sentinel: enforce damage value to " + event.getFinalDamage());
                }
            } else {
                if (SentinelPlugin.debugMe) {
                    SentinelPlugin.instance.getLogger().info("Sentinel: refuse damage enforcement");
                }
            }
            event.setDamage(0);
            event.setCancelled(true);
            return;
        }
        event.setDamage(EntityDamageEvent.DamageModifier.BASE, getDamage());
    }
    if (event.getDamager() instanceof Projectile) {
        ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
        if (source instanceof LivingEntity && ((LivingEntity) source).getUniqueId().equals(getLivingEntity().getUniqueId())) {
            if (SentinelPlugin.instance.getConfig().getBoolean("random.enforce damage", false)) {
                if (canEnforce) {
                    canEnforce = false;
                    whenAttacksHappened(event);
                    if (!event.isCancelled()) {
                        ((LivingEntity) event.getEntity()).damage(getDamage());
                    }
                    if (SentinelPlugin.debugMe) {
                        SentinelPlugin.instance.getLogger().info("Sentinel: enforce damage value to " + getDamage());
                    }
                } else {
                    if (SentinelPlugin.debugMe) {
                        SentinelPlugin.instance.getLogger().info("Sentinel: refuse damage enforcement");
                    }
                }
                event.setDamage(0);
                event.setCancelled(true);
                return;
            }
            double dam = getDamage();
            double modder = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
            double rel = modder == 0.0 ? 1.0 : dam / modder;
            event.setDamage(EntityDamageEvent.DamageModifier.BASE, dam);
            for (EntityDamageEvent.DamageModifier mod : EntityDamageEvent.DamageModifier.values()) {
                if (mod != EntityDamageEvent.DamageModifier.BASE && event.isApplicable(mod)) {
                    event.setDamage(mod, event.getDamage(mod) * rel);
                    if (SentinelPlugin.debugMe) {
                        SentinelPlugin.instance.getLogger().info("Sentinel: Set damage for " + mod + " to " + event.getDamage(mod));
                    }
                }
            }
        }
    }
}
Also used : ProjectileSource(org.bukkit.projectiles.ProjectileSource) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 27 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project MyPet by xXKeyleXx.

the class MyPetEntityListener method onMyPetDamageMonitor.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMyPetDamageMonitor(final EntityDamageByEntityEvent event) {
    if (event.getEntity() == null) {
        // catch invalid events (i.e. EnchantmentAPI)
        return;
    }
    Entity target = event.getEntity();
    if (WorldGroup.getGroupByWorld(target.getWorld()).isDisabled()) {
        return;
    }
    if (target instanceof LivingEntity) {
        Entity source = event.getDamager();
        if (Configuration.LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION && !(target instanceof Player) && !(target instanceof MyPetBukkitEntity)) {
            LivingEntity livingSource = null;
            if (source instanceof Projectile) {
                Projectile projectile = (Projectile) source;
                if (projectile.getShooter() instanceof LivingEntity) {
                    livingSource = (LivingEntity) projectile.getShooter();
                }
            } else if (source instanceof LivingEntity) {
                livingSource = (LivingEntity) source;
            }
            if (livingSource != null) {
                MyPetExperience.addDamageToEntity(livingSource, (LivingEntity) target, event.getDamage());
            }
        }
        if (source instanceof Projectile) {
            ProjectileSource projectileSource = ((Projectile) source).getShooter();
            if (projectileSource instanceof Entity) {
                source = (Entity) projectileSource;
            }
        }
        if (source instanceof MyPetBukkitEntity) {
            MyPet myPet = ((MyPetBukkitEntity) source).getMyPet();
            if (myPet.getStatus() != PetState.Here) {
                return;
            }
            // fix influence of other plugins for this event and throw damage event
            MyPetDamageEvent petDamageEvent = new MyPetDamageEvent(myPet, target, event.getOriginalDamage(EntityDamageEvent.DamageModifier.BASE));
            Bukkit.getPluginManager().callEvent(petDamageEvent);
            if (petDamageEvent.isCancelled()) {
                event.setCancelled(true);
                return;
            } else {
                event.setDamage(petDamageEvent.getDamage());
            }
            if (!isSkillActive) {
                for (Skill skill : myPet.getSkills().all()) {
                    if (skill instanceof OnHitSkill) {
                        OnHitSkill onHitSkill = (OnHitSkill) skill;
                        if (onHitSkill.trigger()) {
                            MyPetOnHitSkillEvent skillEvent = new MyPetOnHitSkillEvent(myPet, onHitSkill, (LivingEntity) target);
                            Bukkit.getPluginManager().callEvent(skillEvent);
                            if (!skillEvent.isCancelled()) {
                                isSkillActive = true;
                                onHitSkill.apply((LivingEntity) target);
                                isSkillActive = false;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) OnDamageByEntitySkill(de.Keyle.MyPet.api.skill.OnDamageByEntitySkill) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) OnHitSkill(de.Keyle.MyPet.api.skill.OnHitSkill) MyPetOnHitSkillEvent(de.Keyle.MyPet.api.event.MyPetOnHitSkillEvent) MyPetDamageEvent(de.Keyle.MyPet.api.event.MyPetDamageEvent) OnHitSkill(de.Keyle.MyPet.api.skill.OnHitSkill) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EntityMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile) CraftMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile) EventHandler(org.bukkit.event.EventHandler)

Example 28 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project InfernalMobs by NyaaCat.

the class EventListener method onEntityAttack.

@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
    // todo unexpected fireball damage
    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;
        Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
        mob.lastDamageCause = event;
        GameMode gameMode = ((Player) trueAttacker).getGameMode();
        if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
            for (EnumAbilities ab : mob.abilityList) {
                ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
            }
        }
        if (ConfigReader.isEnhanceEnabled()) {
            double resistedDamage = ConfigReader.getLevelConfig().calcResistedDamage(event.getDamage(), mob.getMobLevel());
            event.setDamage(resistedDamage);
        }
    }
    if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
        // infernal mob attacked something
        EntityDamageEvent.DamageCause cause = event.getCause();
        double originDamage = event.getDamage();
        Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
        if (isValidDamageCause(cause, mob)) {
            if ((trueVictim instanceof Player)) {
                GameMode gameMode = ((Player) trueVictim).getGameMode();
                if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
                    return;
                for (EnumAbilities ab : mob.abilityList) {
                    ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
                }
            }
            double extraDamage = event.getDamage() - originDamage;
            if (ConfigReader.isEnhanceEnabled()) {
                LevelConfig levelConfig = ConfigReader.getLevelConfig();
                double damage = levelConfig.getDamage(originDamage, mob.getMobLevel());
                damage += extraDamage;
                event.setDamage(damage);
            }
        }
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig) GameMode(org.bukkit.GameMode) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities) EventHandler(org.bukkit.event.EventHandler)

Example 29 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowFishingHook method reelIn.

/**
 * Removes this fishing hook. Drops loot and xp if a player is fishing.
 */
public void reelIn() {
    if (location.getBlock().getType() == Material.WATER) {
        ProjectileSource shooter = getShooter();
        if (shooter instanceof Player) {
            PlayerFishEvent fishEvent = new PlayerFishEvent((Player) shooter, this, null, CAUGHT_FISH);
            fishEvent.setExpToDrop(ThreadLocalRandom.current().nextInt(1, 7));
            fishEvent = EventFactory.getInstance().callEvent(fishEvent);
            if (!fishEvent.isCancelled()) {
                // TODO: Item should "fly" towards player
                world.dropItemNaturally(((Player) getShooter()).getLocation(), getRewardItem());
                ((Player) getShooter()).giveExp(fishEvent.getExpToDrop());
            }
        }
    }
    remove();
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 30 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowEnderPearl method collide.

/**
 * Process teleportation when collide with an entity.
 *
 * @param entity the eneity that the ender pearl collides with
 */
@Override
public void collide(LivingEntity entity) {
    ProjectileSource source = getShooter();
    // the entity receives fake damage.
    if (source instanceof Entity) {
        entity.damage(0, (Entity) source, EntityDamageEvent.DamageCause.PROJECTILE);
    } else {
        entity.damage(0, EntityDamageEvent.DamageCause.PROJECTILE);
    }
    collide(entity.getLocation().getBlock());
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Aggregations

ProjectileSource (org.bukkit.projectiles.ProjectileSource)44 EventHandler (org.bukkit.event.EventHandler)24 LivingEntity (org.bukkit.entity.LivingEntity)21 Projectile (org.bukkit.entity.Projectile)21 Entity (org.bukkit.entity.Entity)20 Player (org.bukkit.entity.Player)17 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)5 UUID (java.util.UUID)4 Entity (org.spongepowered.api.entity.Entity)4 Player (org.spongepowered.api.entity.player.Player)4 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)3 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 EnumAbilities (com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)2 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)2 List (java.util.List)2 Random (java.util.Random)2 GlowPlayer (net.glowstone.entity.GlowPlayer)2 Location (org.bukkit.Location)2