Search in sources :

Example 11 with ProjectileSource

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

the class GlowArrow method collide.

@Override
public void collide(LivingEntity entity) {
    double damage = getDamage();
    ProjectileSource shooter = getShooter();
    if (isCritical()) {
        damage += 1.0;
    }
    entity.damage(damage, shooter instanceof Entity ? (Entity) shooter : null, EntityDamageEvent.DamageCause.PROJECTILE);
    // Burning arrow ignites target, but doesn't stack if target is already on fire.
    if (getFireTicks() > 0 && entity.getFireTicks() < TARGET_BURN_TICKS) {
        entity.setFireTicks(TARGET_BURN_TICKS);
    }
    // TODO: knockback
    entity.setArrowsStuck(entity.getArrowsStuck() + 1);
    remove();
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 12 with ProjectileSource

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

the class GlowSnowball method collide.

/**
 * Process collide with a living entity.
 *
 * @param entity the eneity that the snowball collides with
 */
@Override
public void collide(LivingEntity entity) {
    ProjectileSource source = getShooter();
    // the entity receives fake damage.
    if (source instanceof Entity) {
        if (entity instanceof GlowBlaze) {
            entity.damage(3, (Entity) source, EntityDamageEvent.DamageCause.PROJECTILE);
        } else {
            entity.damage(0, (Entity) source, EntityDamageEvent.DamageCause.PROJECTILE);
        }
    } else {
        entity.damage(0, EntityDamageEvent.DamageCause.PROJECTILE);
    }
    collide(location.getBlock());
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) GlowBlaze(net.glowstone.entity.monster.GlowBlaze) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 13 with ProjectileSource

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

the class GlowEgg method collide.

/**
 * Process random spawn chicks when collide with a living entity.
 *
 * @param entity the eneity that the egg collides with
 */
@Override
public void collide(LivingEntity entity) {
    ProjectileSource source = getShooter();
    // the entity receives fake damage.
    if (entity 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) GlowEntity(net.glowstone.entity.GlowEntity) LivingEntity(org.bukkit.entity.LivingEntity) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 14 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Prism-Bukkit by prism.

the class DeathUtils method getCauseNiceName.

/**
 * Returns the name of what caused an entity to die.
 *
 * @return String
 */
public static String getCauseNiceName(Entity entity) {
    EntityDamageEvent e = entity.getLastDamageCause();
    if (e == null) {
        return "unknown";
    }
    // Determine the root cause
    DamageCause damageCause = e.getCause();
    Entity killer = null;
    // If was damaged by an entity
    if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
        // Arrow?
        if (entityDamageByEntityEvent.getDamager() instanceof Arrow) {
            Projectile arrow = (Arrow) entityDamageByEntityEvent.getDamager();
            ProjectileSource source = arrow.getShooter();
            if (source instanceof Player) {
                killer = ((Player) source);
            }
        } else {
            killer = entityDamageByEntityEvent.getDamager();
        }
    }
    if (entity instanceof Player) {
        Player player = (Player) entity;
        // yourself with instant damage it doesn't show as suicide.
        if (killer instanceof Player) {
            // Themself
            if (killer.getName().equals(player.getName())) {
                return "suicide";
            }
            // translate bukkit events to nicer names
            if ((damageCause.equals(DamageCause.ENTITY_ATTACK) || damageCause.equals(DamageCause.PROJECTILE))) {
                return "pvp";
            }
        }
    }
    // Causes of death for either entities or players
    if (damageCause.equals(DamageCause.ENTITY_ATTACK)) {
        return "mob";
    } else if (damageCause.equals(DamageCause.PROJECTILE)) {
        return "skeleton";
    } else if (damageCause.equals(DamageCause.ENTITY_EXPLOSION)) {
        return "creeper";
    } else if (damageCause.equals(DamageCause.CONTACT)) {
        return "cactus";
    } else if (damageCause.equals(DamageCause.BLOCK_EXPLOSION)) {
        return "tnt";
    } else if (damageCause.equals(DamageCause.FIRE) || damageCause.equals(DamageCause.FIRE_TICK)) {
        return "fire";
    } else if (damageCause.equals(DamageCause.MAGIC)) {
        return "potion";
    }
    return damageCause.name().toLowerCase();
}
Also used : Arrow(org.bukkit.entity.Arrow) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Projectile(org.bukkit.entity.Projectile)

Example 15 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Prism-Bukkit by prism.

the class PrismEntityEvents method onPotionSplashEvent.

/**
 * PotionSplashEvent.
 * @param event PotionSplashEvent.
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPotionSplashEvent(final PotionSplashEvent event) {
    final ProjectileSource source = event.getPotion().getShooter();
    // Ignore from non-players for the time being
    if (!(source instanceof Player)) {
        return;
    }
    final Player player = (Player) source;
    if (!Prism.getIgnore().event("potion-splash", player)) {
        return;
    }
    // What type?
    // Right now this won't support anything with multiple effects
    final Collection<PotionEffect> potion = event.getPotion().getEffects();
    String name = "";
    for (final PotionEffect eff : potion) {
        name = eff.getType().getName().toLowerCase();
    }
    RecordingQueue.addToQueue(ActionFactory.createPlayer("potion-splash", player, name));
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) ProjectileSource(org.bukkit.projectiles.ProjectileSource) BlockProjectileSource(org.bukkit.projectiles.BlockProjectileSource) EventHandler(org.bukkit.event.EventHandler)

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