Search in sources :

Example 1 with Trident

use of org.bukkit.entity.Trident in project Slimefun4 by Slimefun.

the class TalismanListener method onProjectileDamage.

private void onProjectileDamage(@Nonnull EntityDamageByEntityEvent e) {
    // "Fixes" #1022 - We just ignore Tridents now.
    if (e.getDamager() instanceof Projectile && !(e.getDamager() instanceof Trident)) {
        Projectile projectile = (Projectile) e.getDamager();
        if (Talisman.trigger(e, SlimefunItems.TALISMAN_WHIRLWIND)) {
            Player p = (Player) e.getEntity();
            returnProjectile(p, projectile);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Trident(org.bukkit.entity.Trident) Projectile(org.bukkit.entity.Projectile)

Example 2 with Trident

use of org.bukkit.entity.Trident in project Parties by AlessioDP.

the class BukkitFightListener method onPlayerHit.

@EventHandler(ignoreCancelled = true)
public void onPlayerHit(EntityDamageByEntityEvent event) {
    if (BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = null;
        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;
        try {
            if (event.getDamager() instanceof Trident)
                type = DamageType.TRIDENT;
        } catch (NoClassDefFoundError ignored) {
        }
        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 TRIDENT:
                    shooterSource = ((Trident) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                default:
                    // Nothing to do
                    break;
            }
            if (attacker != null) {
                // Found right attacker
                if (!victim.getUniqueId().equals(attacker.getUniqueId())) {
                    // Friendly fire not allowed here
                    PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                    PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
                    BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
                    if (party != null && ppAttacker.getPartyId().equals(ppVictim.getPartyId()) && party.isFriendlyFireProtected() && !attacker.hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
                        // Calling API event
                        BukkitPartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
                        plugin.getEventManager().callEvent(partiesFriendlyFireEvent);
                        if (!partiesFriendlyFireEvent.isCancelled()) {
                            // Friendly fire confirmed
                            User userAttacker = plugin.getPlayer(attacker.getUniqueId());
                            userAttacker.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_PROTECTION_PROTECTED, ppAttacker, party), true);
                            party.warnFriendlyFire(ppVictim, ppAttacker);
                            event.setCancelled(true);
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, type.name(), attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
                        } else
                            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, type.name(), attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
                    }
                }
            }
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) BukkitPartiesFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFriendlyFireBlockedEvent) Player(org.bukkit.entity.Player) EnderPearl(org.bukkit.entity.EnderPearl) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) Snowball(org.bukkit.entity.Snowball) Trident(org.bukkit.entity.Trident) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Trident

use of org.bukkit.entity.Trident in project EcoEnchants by Auxilor.

the class Lesion method onTridentDamage.

@Override
public void onTridentDamage(@NotNull final LivingEntity attacker, @NotNull final LivingEntity victim, @NotNull final Trident trident, final int level, @NotNull final EntityDamageByEntityEvent event) {
    if (!EnchantmentUtils.passedChance(this, level)) {
        return;
    }
    double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage");
    int bleedCount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level");
    bleedCount *= level;
    final int finalBleedCount = bleedCount;
    AtomicInteger currentBleedCount = new AtomicInteger(0);
    this.getPlugin().getRunnableFactory().create(bukkitRunnable -> {
        currentBleedCount.addAndGet(1);
        victim.damage(bleedDamage);
        if (currentBleedCount.get() >= finalBleedCount) {
            bukkitRunnable.cancel();
        }
    }).runTaskTimer(0, 10);
}
Also used : EnchantmentType(com.willfp.ecoenchants.enchantments.meta.EnchantmentType) EnchantmentUtils(com.willfp.ecoenchants.enchantments.util.EnchantmentUtils) EcoEnchant(com.willfp.ecoenchants.enchantments.EcoEnchant) EcoEnchants(com.willfp.ecoenchants.enchantments.EcoEnchants) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LivingEntity(org.bukkit.entity.LivingEntity) NotNull(org.jetbrains.annotations.NotNull) Trident(org.bukkit.entity.Trident) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

Trident (org.bukkit.entity.Trident)3 Player (org.bukkit.entity.Player)2 User (com.alessiodp.core.common.user.User)1 BukkitPartiesFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFriendlyFireBlockedEvent)1 BukkitEventManager (com.alessiodp.parties.bukkit.events.BukkitEventManager)1 BukkitPartyImpl (com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl)1 BukkitPartyPlayerImpl (com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 EcoEnchant (com.willfp.ecoenchants.enchantments.EcoEnchant)1 EcoEnchants (com.willfp.ecoenchants.enchantments.EcoEnchants)1 EnchantmentType (com.willfp.ecoenchants.enchantments.meta.EnchantmentType)1 EnchantmentUtils (com.willfp.ecoenchants.enchantments.util.EnchantmentUtils)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Arrow (org.bukkit.entity.Arrow)1 EnderPearl (org.bukkit.entity.EnderPearl)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Projectile (org.bukkit.entity.Projectile)1 Snowball (org.bukkit.entity.Snowball)1 EventHandler (org.bukkit.event.EventHandler)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1