Search in sources :

Example 21 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project TotalFreedomMod by TotalFreedom.

the class PotionBlocker method onThrowPotion.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onThrowPotion(PotionSplashEvent event) {
    ProjectileSource source = event.getEntity().getShooter();
    if (!(source instanceof Player)) {
        event.setCancelled(true);
        return;
    }
    Player thrower = (Player) source;
    if (plugin.al.isAdmin(thrower)) {
        return;
    }
    for (Player player : thrower.getWorld().getPlayers()) {
        if (thrower.getLocation().distanceSquared(player.getLocation()) < POTION_BLOCK_RADIUS_SQUARED) {
            thrower.sendMessage(ChatColor.RED + "You cannot use splash potions close to other players.");
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Example 22 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Parties by AlessioDP.

the class FightListener method onPlayerHit.

@EventHandler
public void onPlayerHit(EntityDamageByEntityEvent event) {
    if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = null;
        // 0=Basic, 1=Arrow, 2=EnderPearl, 3=Snowball
        DamageType type = DamageType.UNSUPPORTED;
        if (event.getDamager() instanceof Player)
            type = DamageType.PLAYER;
        else if (event.getDamager() instanceof Arrow)
            type = DamageType.ARROW;
        else if (event.getDamager() instanceof EnderPearl)
            type = DamageType.ENDERPEARL;
        else if (event.getDamager() instanceof Snowball)
            type = DamageType.SNOWBALL;
        if (!type.equals(DamageType.UNSUPPORTED)) {
            ProjectileSource shooterSource;
            switch(type) {
                case PLAYER:
                    attacker = (Player) event.getDamager();
                    break;
                case ARROW:
                    shooterSource = ((Arrow) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case ENDERPEARL:
                    shooterSource = ((EnderPearl) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case SNOWBALL:
                    shooterSource = ((Snowball) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case UNSUPPORTED:
            }
            if (attacker != null) {
                // Found right attacker
                if (!victim.getUniqueId().equals(attacker.getUniqueId()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
                    // Friendly fire not allowed here
                    PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                    PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
                    if (!ppVictim.getPartyName().isEmpty() && ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
                        // Calling API event
                        PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
                        Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                        if (!partiesFriendlyFireEvent.isCancelled()) {
                            // Friendly fire confirmed
                            PartyEntity party = plugin.getPartyManager().getParty(ppVictim.getPartyName());
                            ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
                            party.sendFriendlyFireWarn(ppVictim, ppAttacker);
                            event.setCancelled(true);
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                        } else
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                    }
                }
            }
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) PartiesFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent) Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) EnderPearl(org.bukkit.entity.EnderPearl) ProjectileSource(org.bukkit.projectiles.ProjectileSource) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 23 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.

the class MagicController method getEntityUndo.

@Nullable
public UndoList getEntityUndo(Entity entity) {
    UndoList blockList = null;
    if (entity == null)
        return null;
    Mage mage = getRegisteredMage(entity);
    if (mage == null && entity instanceof Projectile) {
        Projectile projectile = (Projectile) entity;
        ProjectileSource source = projectile.getShooter();
        if (source instanceof LivingEntity) {
            entity = (LivingEntity) source;
            mage = getRegisteredMage(entity);
        }
    }
    if (mage != null) {
        UndoList undoList = mage.getLastUndoList();
        if (undoList != null) {
            long now = System.currentTimeMillis();
            if (undoList.getModifiedTime() > now - undoTimeWindow) {
                blockList = undoList;
            }
        }
    } else {
        blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
    }
    return blockList;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) Nullable(javax.annotation.Nullable)

Example 24 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.

the class Mage method damagedBy.

@Override
public void damagedBy(@Nonnull Entity damager, double damage) {
    if (damagedBy == null)
        return;
    if (damager instanceof Projectile) {
        ProjectileSource source = ((Projectile) damager).getShooter();
        if (!(source instanceof Entity))
            return;
        damager = (Entity) source;
    }
    // Only tracking players for now.
    if (!(damager instanceof Player))
        return;
    Player damagingPlayer = (Player) damager;
    lastDamager = damagedBy.get(damagingPlayer.getUniqueId());
    if (lastDamager == null) {
        lastDamager = new DamagedBy(damagingPlayer, damage);
        damagedBy.put(damagingPlayer.getUniqueId(), lastDamager);
    } else {
        lastDamager.damage += damage;
    }
    if (topDamager != null) {
        if (topDamager.getEntity() == null || topDamager.damage < lastDamager.damage || !withinRange(topDamager.getEntity())) {
            topDamager = lastDamager;
            setTarget(damagingPlayer);
        }
    } else {
        topDamager = lastDamager;
        setTarget(damagingPlayer);
    }
    if (entityData != null) {
        entityData.onDamage(this, damage);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) Player(org.bukkit.entity.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile)

Example 25 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.

the class PlayerController method onProjectileLaunch.

@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    if (launching || event.isCancelled())
        return;
    Projectile projectile = event.getEntity();
    ProjectileSource shooter = projectile.getShooter();
    // Not really handling magic mobs with magic bows...
    if (!(shooter instanceof Player))
        return;
    Player player = (Player) shooter;
    Mage mage = controller.getRegisteredMage(player);
    if (mage == null)
        return;
    Wand wand = mage.getActiveWand();
    if (wand == null)
        return;
    if (wand.getIcon().getMaterial() != Material.BOW)
        return;
    double minPull = wand.getDouble("cast_min_bowpull");
    double pull = Math.min(1.0, projectile.getVelocity().length() / MAX_ARROW_SPEED);
    if (minPull > 0 && pull < minPull) {
        if (wand.isInventoryOpen())
            event.setCancelled(true);
        return;
    }
    Spell spell = wand.getActiveSpell();
    if (spell == null) {
        if (wand.isInventoryOpen())
            event.setCancelled(true);
        return;
    }
    event.setCancelled(true);
    String[] parameters = { "bowpull", Double.toString(pull) };
    // prevent recursion!
    launching = true;
    try {
        wand.cast(parameters);
    } catch (Exception ex) {
        controller.getLogger().log(Level.SEVERE, "Error casting bow spell", ex);
    }
    launching = false;
}
Also used : Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Spell(com.elmakers.mine.bukkit.api.spell.Spell) Projectile(org.bukkit.entity.Projectile) 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