Search in sources :

Example 1 with Snowball

use of org.bukkit.entity.Snowball 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 2 with Snowball

use of org.bukkit.entity.Snowball in project Fusion by GummyPvP.

the class SwitchEvent method onSwitch.

@EventHandler
public void onSwitch(EntityDamageByEntityEvent e) {
    if (!(e.getEntity() instanceof Player))
        return;
    if (!(e.getDamager() instanceof Snowball))
        return;
    if (!(((Snowball) e.getDamager()).getShooter() instanceof Player))
        return;
    Player shooter = (Player) ((Snowball) e.getDamager()).getShooter();
    if (mKitUser.getInstance(shooter).getKit() != KitManager.getInstance().valueOf("Switcher"))
        return;
    if (mKitUser.getInstance(shooter).isInGladiatorArena())
        return;
    if (RegionManager.getInstance().isInProtectedRegion(shooter))
        return;
    if (RegionManager.getInstance().isInProtectedRegion((Player) e.getEntity()))
        return;
    Location shooterLocation, recieverLocation;
    shooterLocation = shooter.getLocation();
    recieverLocation = e.getEntity().getLocation();
    shooter.teleport(recieverLocation);
    e.getEntity().teleport(shooterLocation);
}
Also used : Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Snowball

use of org.bukkit.entity.Snowball in project EliteMobs by MagmaGuy.

the class FrostCone method createSnowball.

private static Snowball createSnowball(EliteEntity eliteEntity, Location location) {
    Projectile snowball = EliteProjectile.create(EntityType.SNOWBALL, eliteEntity.getLivingEntity(), getShotVector(eliteEntity, location), false);
    ProjectileTagger.tagProjectileWithCustomDamage(snowball, 2);
    snowball.getPersistentDataContainer().set(frostConeSnowballKey, PersistentDataType.STRING, "true");
    Bukkit.getScheduler().runTaskLater(MetadataHandler.PLUGIN, snowball::remove, 20L * 3);
    return (Snowball) snowball;
}
Also used : Snowball(org.bukkit.entity.Snowball) Projectile(org.bukkit.entity.Projectile) EliteProjectile(com.magmaguy.elitemobs.combatsystem.EliteProjectile)

Aggregations

Snowball (org.bukkit.entity.Snowball)3 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 PartiesFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent)1 EliteProjectile (com.magmaguy.elitemobs.combatsystem.EliteProjectile)1 Location (org.bukkit.Location)1 Arrow (org.bukkit.entity.Arrow)1 EnderPearl (org.bukkit.entity.EnderPearl)1 Projectile (org.bukkit.entity.Projectile)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1