Search in sources :

Example 51 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.

the class CrackShotHandler method onWeaponDamageEntity.

@EventHandler
public void onWeaponDamageEntity(WeaponDamageEntityEvent event) {
    if (active && ConfigParties.FRIENDLYFIRE_ENABLE) {
        if (event.getVictim() instanceof Player) {
            PartyPlayerEntity shooterPp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
            Player victim = (Player) event.getVictim();
            if (!victim.getUniqueId().equals(shooterPp.getPlayerUUID()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
                PartyPlayerEntity victimPp = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                if (!shooterPp.getPartyName().isEmpty() && shooterPp.getPartyName().equalsIgnoreCase(victimPp.getPartyName())) {
                    // Calling API event
                    PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(victimPp, shooterPp, null);
                    Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                    if (!partiesFriendlyFireEvent.isCancelled()) {
                        // Friendly fire confirmed
                        PartyEntity party = plugin.getPartyManager().getParty(victimPp.getPartyName());
                        shooterPp.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
                        party.sendFriendlyFireWarn(victimPp, shooterPp);
                        event.setCancelled(true);
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
                    } else
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
                }
            }
        }
    }
}
Also used : PartiesFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent) Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 52 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity 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 53 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.

the class FightListener method onPotionSplash.

@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
    if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getPotion().getShooter() instanceof Player) {
        Player attacker = (Player) event.getPotion().getShooter();
        PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
        if (!ppAttacker.getPartyName().isEmpty() && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(attacker.getWorld().getName()))) {
            boolean cancel = false;
            for (PotionEffect pe : event.getEntity().getEffects()) {
                switch(pe.getType().getName().toLowerCase()) {
                    case "harm":
                    case "blindness":
                    case "confusion":
                    case "poison":
                    case "slow":
                    case "slow_digging":
                    case "weakness":
                    case "unluck":
                        cancel = true;
                }
                if (cancel)
                    break;
            }
            if (cancel) {
                // Friendly fire not allowed here
                PartyEntity party = plugin.getPartyManager().getParty(ppAttacker.getPartyName());
                for (LivingEntity e : event.getAffectedEntities()) {
                    if (e instanceof Player) {
                        Player victim = (Player) e;
                        if (!attacker.equals(victim)) {
                            PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                            if (ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
                                // Calling API event
                                PartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesPotionsFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
                                Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                                if (!partiesFriendlyFireEvent.isCancelled()) {
                                    // Friendly fire confirmed
                                    ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
                                    party.sendFriendlyFireWarn(ppVictim, ppAttacker);
                                    event.setIntensity(e, 0);
                                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                                } else
                                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PartiesPotionsFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesPotionsFriendlyFireBlockedEvent) Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PotionEffect(org.bukkit.potion.PotionEffect) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 54 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.

the class ChatListener method onPlayerCommandPreprocess.

/*
	 * Auto-command
	 */
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    if (!event.isCancelled() && ConfigMain.ADDITIONAL_AUTOCMD_ENABLE) {
        if (event.getMessage().endsWith("\t")) {
            // This is an auto command
            event.setMessage(event.getMessage().replace("\t", ""));
        } else {
            // This is a normal command to replicate
            // Make it async
            plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
                boolean cancel = false;
                for (String str : ConfigMain.ADDITIONAL_AUTOCMD_BLACKLIST) {
                    if (str.equalsIgnoreCase("*") || event.getMessage().toLowerCase().startsWith(str.toLowerCase())) {
                        cancel = true;
                        break;
                    }
                }
                for (String str : ConfigMain.ADDITIONAL_AUTOCMD_WHITELIST) {
                    if (str.equalsIgnoreCase("*") || event.getMessage().toLowerCase().startsWith(str.toLowerCase())) {
                        cancel = false;
                        break;
                    }
                }
                if (!cancel) {
                    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
                    if (!pp.getPartyName().isEmpty()) {
                        if (PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_AUTOCOMMAND)) {
                            PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
                            for (Player pl : party.getOnlinePlayers()) {
                                if (!pl.getUniqueId().equals(event.getPlayer().getUniqueId())) {
                                    // Make it sync
                                    plugin.getPartiesScheduler().runSync(() -> {
                                        pl.chat(event.getMessage() + "\t");
                                        LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_AUTOCMD_PERFORM.replace("{player}", pl.getName()).replace("{command}", event.getMessage()), true);
                                    });
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 55 with PartyPlayerEntity

use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.

the class FollowListener method onChangeWorld.

@EventHandler
public void onChangeWorld(PlayerChangedWorldEvent event) {
    if (ConfigMain.ADDITIONAL_FOLLOW_ENABLE) {
        // Make it async
        plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
            if (ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains("*") || ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains(event.getPlayer().getWorld().getName())) {
                Player player = event.getPlayer();
                PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
                if (!pp.getPartyName().isEmpty()) {
                    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
                    if (party != null) {
                        if (pp.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKNEEDED) {
                            // Init teleport
                            for (Player pl : party.getOnlinePlayers()) {
                                if (!pl.getUniqueId().equals(player.getUniqueId()) && !pl.getWorld().equals(player.getWorld())) {
                                    PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(pl.getUniqueId());
                                    if (ppVictim.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKMINIMUM) {
                                        // Make it sync
                                        plugin.getPartiesScheduler().runSync(() -> {
                                            switch(ConfigMain.ADDITIONAL_FOLLOW_TYPE) {
                                                case 1:
                                                    ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
                                                    ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
                                                    pl.teleport(player.getWorld().getSpawnLocation());
                                                    break;
                                                case 2:
                                                    ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
                                                    ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
                                                    pl.teleport(player);
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PortalTask(com.alessiodp.parties.tasks.PortalTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)92 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)56 Player (org.bukkit.entity.Player)53 EventHandler (org.bukkit.event.EventHandler)13 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)9 UUID (java.util.UUID)8 ArrayList (java.util.ArrayList)6 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)4 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 Status (com.alessiodp.partiesapi.enums.Status)3 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 PartiesPlaceholder (com.alessiodp.parties.addons.internal.PartiesPlaceholder)2 ChatTask (com.alessiodp.parties.tasks.ChatTask)2 PartiesChatEvent (com.alessiodp.partiesapi.events.PartiesChatEvent)2 PartiesFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent)2 PartiesPlayerJoinEvent (com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1