Search in sources :

Example 36 with Projectile

use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.

the class GlowArmorStand method damage.

@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
    if (getNoDamageTicks() > 0 || health <= 0 || !canTakeDamage(cause)) {
        return;
    }
    if (source instanceof Projectile && !(source instanceof Arrow)) {
        return;
    }
    EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
    if (event.isCancelled()) {
        return;
    }
    boolean drop = false;
    if (source instanceof GlowPlayer || source instanceof Arrow && ((Projectile) source).getShooter() instanceof GlowPlayer) {
        GlowPlayer damager = (GlowPlayer) (source instanceof GlowPlayer ? source : ((Arrow) source).getShooter());
        if (damager.getGameMode() == GameMode.ADVENTURE) {
            return;
        } else if (damager.getGameMode() == GameMode.CREATIVE) {
            // Instantly kill the entity
            amount = 2;
        } else {
            // Needs two hits
            amount = 1;
            drop = true;
        }
    }
    setLastDamage(amount);
    setHealth(health - amount, drop);
}
Also used : Arrow(org.bukkit.entity.Arrow) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) Projectile(org.bukkit.entity.Projectile) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 37 with Projectile

use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.

the class ProjectileDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowWorld world = block.getWorld();
    Vector position = BlockDispenser.getDispensePosition(block);
    BlockFace face = BlockDispenser.getFacing(block);
    Projectile entity = projectileCreator.apply(new Location(world, position.getX(), position.getY(), position.getZ()), stack);
    entity.setShooter(new GlowDispenser(block));
    entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() < 1) {
        return null;
    }
    return stack;
}
Also used : GlowDispenser(net.glowstone.block.entity.state.GlowDispenser) BlockFace(org.bukkit.block.BlockFace) GlowWorld(net.glowstone.GlowWorld) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location)

Example 38 with Projectile

use of org.bukkit.entity.Projectile in project Denizen-For-Bukkit by DenizenScript.

the class NPCTagBase method onHit.

// <--[action]
// @Actions
// hit
// hit on <entity>
// 
// @Triggers when the NPC hits an enemy.
// 
// @Context
// None
// 
// -->
// <--[action]
// @Actions
// kill
// kill of <entity>
// 
// @Triggers when the NPC kills an enemy.
// 
// @Context
// None
// 
// -->
@EventHandler(priority = EventPriority.MONITOR)
public void onHit(EntityDamageByEntityEvent event) {
    NPC citizen = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
    if (citizen == null) {
        if (event.getDamager() instanceof Projectile) {
            if (((Projectile) event.getDamager()).getShooter() instanceof Entity) {
                citizen = CitizensAPI.getNPCRegistry().getNPC((Entity) ((Projectile) event.getDamager()).getShooter());
            }
        }
    }
    if (citizen == null || !citizen.hasTrait(AssignmentTrait.class)) {
        return;
    }
    NPCTag npc = new NPCTag(citizen);
    PlayerTag player = null;
    if (event.getEntity() instanceof Player) {
        player = PlayerTag.mirrorBukkitPlayer((Player) event.getEntity());
    }
    // TODO: Context containing the entity hit
    npc.action("hit", player);
    npc.action("hit on " + event.getEntityType().name(), player);
    if (event.getEntity() instanceof LivingEntity) {
        if (((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0) {
            npc.action("kill", player);
            npc.action("kill of " + event.getEntityType().name(), player);
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 39 with Projectile

use of org.bukkit.entity.Projectile 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 40 with Projectile

use of org.bukkit.entity.Projectile in project acidisland by tastybento.

the class IslandGuard1_9 method EndCrystalDamage.

/**
 * Handle end crystal damage by visitors
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void EndCrystalDamage(final EntityDamageByEntityEvent e) {
    if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (!(e.getEntity() instanceof EnderCrystal)) {
        return;
    }
    Player p = null;
    if (e.getDamager() instanceof Player) {
        p = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        // Get the shooter
        Projectile projectile = (Projectile) e.getDamager();
        ProjectileSource shooter = projectile.getShooter();
        if (shooter instanceof Player) {
            p = (Player) shooter;
        }
    }
    if (p != null) {
        if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check if on island
        if (plugin.getGrid().playerIsOnIsland(p)) {
            return;
        }
        // Check island
        Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) EnderCrystal(org.bukkit.entity.EnderCrystal) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Island(com.wasteofplastic.acidisland.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Projectile (org.bukkit.entity.Projectile)87 EventHandler (org.bukkit.event.EventHandler)56 Player (org.bukkit.entity.Player)45 Entity (org.bukkit.entity.Entity)37 LivingEntity (org.bukkit.entity.LivingEntity)28 ProjectileSource (org.bukkit.projectiles.ProjectileSource)18 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)13 Location (org.bukkit.Location)9 Animals (org.bukkit.entity.Animals)9 Monster (org.bukkit.entity.Monster)9 Vector (org.bukkit.util.Vector)9 Villager (org.bukkit.entity.Villager)8 ItemStack (org.bukkit.inventory.ItemStack)8 Hanging (org.bukkit.entity.Hanging)7 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)7 PotionEffect (org.bukkit.potion.PotionEffect)7 Block (org.bukkit.block.Block)6 Arrow (org.bukkit.entity.Arrow)6 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4