Search in sources :

Example 1 with BukkitEventManager

use of com.alessiodp.parties.bukkit.events.BukkitEventManager in project Parties by AlessioDP.

the class BukkitPartiesPlugin method postHandle.

@Override
protected void postHandle() {
    addonManager = new BukkitPartiesAddonManager(this);
    economyManager = new BukkitEconomyManager(this);
    expManager = new BukkitExpManager(this);
    eventManager = new BukkitEventManager(this);
    super.postHandle();
    new BukkitMetricsHandler(this);
    if (isBungeeCordEnabled() && BukkitConfigMain.PARTIES_BUNGEECORD_PACKETS_CONFIG_SYNC) {
        ((BukkitPartiesConfigurationManager) getConfigurationManager()).makeConfigsRequest();
        getLoggerManager().log(PartiesConstants.DEBUG_PLUGIN_BUNGEECORD_MODE, true);
    }
}
Also used : BukkitExpManager(com.alessiodp.parties.bukkit.parties.BukkitExpManager) BukkitPartiesConfigurationManager(com.alessiodp.parties.bukkit.configuration.BukkitPartiesConfigurationManager) BukkitMetricsHandler(com.alessiodp.parties.bukkit.addons.external.BukkitMetricsHandler) BukkitEconomyManager(com.alessiodp.parties.bukkit.utils.BukkitEconomyManager) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) BukkitPartiesAddonManager(com.alessiodp.parties.bukkit.addons.BukkitPartiesAddonManager)

Example 2 with BukkitEventManager

use of com.alessiodp.parties.bukkit.events.BukkitEventManager in project Parties by AlessioDP.

the class BukkitFightListener method onPlayerFish.

@EventHandler(ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
    if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY && event.getCaught() != null && event.getCaught() instanceof Player && BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_PREVENT_FISH_HOOK) {
        // Friendly fire not allowed here
        PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(event.getCaught().getUniqueId());
        PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
        if (party != null && ppAttacker.getPartyId().equals(ppVictim.getPartyId()) && party.isFriendlyFireProtected() && !event.getPlayer().hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
            // Calling API event
            BukkitPartiesFishHookFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesFishHookFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
            plugin.getEventManager().callEvent(partiesFriendlyFireEvent);
            if (!partiesFriendlyFireEvent.isCancelled()) {
                // Friendly fire confirmed
                User userAttacker = plugin.getPlayer(event.getPlayer().getUniqueId());
                userAttacker.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_PROTECTION_PROTECTED, ppAttacker, party), true);
                party.warnFriendlyFire(ppVictim, ppAttacker);
                try {
                    event.getHook().remove();
                    event.setCancelled(true);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, "fish hook", ppAttacker.getPlayerUUID().toString(), ppVictim.getPlayerUUID().toString()), true);
                } catch (NoSuchMethodError ignored) {
                    // Hook remove not supported in this version
                    plugin.getLoggerManager().printError(PartiesConstants.DEBUG_FRIENDLYFIRE_FISH_NOT_SUPPORTED);
                }
            } else
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "fish hook", ppAttacker.getPlayerUUID().toString(), ppVictim.getPlayerUUID().toString()), true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) BukkitPartiesFishHookFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFishHookFriendlyFireBlockedEvent) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) EventHandler(org.bukkit.event.EventHandler)

Example 3 with BukkitEventManager

use of com.alessiodp.parties.bukkit.events.BukkitEventManager in project Parties by AlessioDP.

the class BukkitFightListener method onPotionSplash.

@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    if (BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getPotion().getShooter() instanceof Player) {
        Player attacker = (Player) event.getPotion().getShooter();
        PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
        BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
        if (party != null && party.isFriendlyFireProtected() && !attacker.hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
            boolean cancel = false;
            for (PotionEffect pe : event.getEntity().getEffects()) {
                switch(CommonUtils.toLowerCase(pe.getType().getName())) {
                    case "harm":
                    case "blindness":
                    case "confusion":
                    case "poison":
                    case "slow":
                    case "slow_digging":
                    case "weakness":
                    case "unluck":
                        cancel = true;
                        break;
                    default:
                        // Do not cancel
                        break;
                }
                if (cancel)
                    break;
            }
            if (cancel) {
                // Friendly fire not allowed here
                for (LivingEntity e : event.getAffectedEntities()) {
                    if (e instanceof Player) {
                        Player victim = (Player) e;
                        if (!attacker.equals(victim)) {
                            PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                            if (ppAttacker.getPartyId().equals(ppVictim.getPartyId())) {
                                // Calling API event
                                BukkitPartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesPotionsFriendlyFireBlockedEvent(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.setIntensity(e, 0);
                                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, "potion splash", attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
                                } else
                                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "potion splash", attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) PotionEffect(org.bukkit.potion.PotionEffect) BukkitPartiesPotionsFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesPotionsFriendlyFireBlockedEvent) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) EventHandler(org.bukkit.event.EventHandler)

Example 4 with BukkitEventManager

use of com.alessiodp.parties.bukkit.events.BukkitEventManager in project Parties by AlessioDP.

the class BukkitFightListener method onEntityCombustByEntity.

@EventHandler(ignoreCancelled = true)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
    if (BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getCombuster() instanceof Projectile && ((Projectile) event.getCombuster()).getShooter() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = (Player) ((Projectile) event.getCombuster()).getShooter();
        // Found right attacker
        if (attacker != null && !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
                BukkitPartiesCombustFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).prepareCombustFriendlyFireBlockedEvent(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, "entity combust", attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
                } else
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "entity combust", attacker.getUniqueId().toString(), victim.getUniqueId().toString()), true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) BukkitPartiesCombustFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesCombustFriendlyFireBlockedEvent) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 5 with BukkitEventManager

use of com.alessiodp.parties.bukkit.events.BukkitEventManager 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)

Aggregations

BukkitEventManager (com.alessiodp.parties.bukkit.events.BukkitEventManager)6 User (com.alessiodp.core.common.user.User)5 Player (org.bukkit.entity.Player)5 BukkitPartyImpl (com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl)4 BukkitPartyPlayerImpl (com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl)4 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)4 EventHandler (org.bukkit.event.EventHandler)4 BukkitPartiesCombustFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesCombustFriendlyFireBlockedEvent)1 BukkitPartiesFishHookFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFishHookFriendlyFireBlockedEvent)1 BukkitPartiesFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFriendlyFireBlockedEvent)1 BukkitPartiesPotionsFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesPotionsFriendlyFireBlockedEvent)1 BukkitPartiesPreExperienceDropEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesPreExperienceDropEvent)1 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)1 BukkitPartiesAddonManager (com.alessiodp.parties.bukkit.addons.BukkitPartiesAddonManager)1 BukkitMetricsHandler (com.alessiodp.parties.bukkit.addons.external.BukkitMetricsHandler)1 BukkitPartiesConfigurationManager (com.alessiodp.parties.bukkit.configuration.BukkitPartiesConfigurationManager)1 BukkitExpManager (com.alessiodp.parties.bukkit.parties.BukkitExpManager)1 BukkitEconomyManager (com.alessiodp.parties.bukkit.utils.BukkitEconomyManager)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 Arrow (org.bukkit.entity.Arrow)1