Search in sources :

Example 41 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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 42 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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 43 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity 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)

Example 44 with PartyEntity

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

the class JoinLeaveListener method globalQuit.

private void globalQuit(Player p) {
    // Make it async
    plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
        boolean removePlFromList = true;
        // Spy listener
        if (pp.isSpy())
            plugin.getSpyManager().removeSpy(pp.getPlayerUUID());
        // Party checking
        if (!pp.getPartyName().isEmpty()) {
            if (pp.getHomeTask() != -1)
                plugin.getPlayerManager().remHomeCount();
            PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
            if (party != null) {
                party.getOnlinePlayers().remove(p);
                if (ConfigMain.PARTIES_JLMESSAGES) {
                    party.sendBroadcast(pp, Messages.OTHER_JOINLEAVE_SERVERLEAVE);
                }
                if (plugin.getDatabaseManager().getDatabaseType().isNone()) {
                    // Start delete timeout
                    if (ConfigMain.STORAGE_SETTINGS_NONE_DISBANDONLEADERLEFT && party.getLeader().equals(p.getUniqueId())) {
                        // Leader left, delete now
                        plugin.getPartyManager().deleteTimedParty(party.getName(), true);
                    } else if (party.getOnlinePlayers().size() == 0) {
                        // All players left, start timer
                        if (ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY > 0) {
                            plugin.getPlayerManager().getListPartyPlayersToDelete().add(p.getUniqueId());
                            PartyDeleteTask task = (PartyDeleteTask) new PartyDeleteTask(party.getName());
                            task.runTaskLaterAsynchronously(plugin, ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY * 20);
                            plugin.getPartyManager().getListPartiesToDelete().put(party.getName().toLowerCase(), task.getTaskId());
                            removePlFromList = false;
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_DELETE_START.replace("{party}", party.getName()).replace("{value}", Integer.toString(ConfigMain.STORAGE_SETTINGS_NONE_DELAYDELETEPARTY * 20)), true);
                        } else
                            plugin.getPartyManager().deleteTimedParty(party.getName(), false);
                    }
                } else {
                    if (party.getNumberOnlinePlayers() == 0) {
                        plugin.getPartyManager().unloadParty(party.getName());
                    }
                }
            }
        }
        if (removePlFromList)
            plugin.getPlayerManager().unloadPlayer(p.getUniqueId());
    });
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartyDeleteTask(com.alessiodp.parties.tasks.PartyDeleteTask)

Example 45 with PartyEntity

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

the class PlayerManager method reload.

public void reload() {
    listPartyPlayers = new HashMap<UUID, PartyPlayerEntity>();
    listPartyPlayersToDelete = new HashSet<UUID>();
    homeCounts = 0;
    chatCooldown = new HashMap<>();
    inviteCooldown = new HashMap<>();
    teleportCooldown = new HashMap<>();
    plugin.getSpyManager().refreshSpyList();
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        PartyPlayerEntity pp = loadPlayer(p.getUniqueId());
        PartyEntity party = plugin.getPartyManager().loadParty(pp.getPartyName());
        if (party != null)
            party.getOnlinePlayers().add(p);
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) UUID(java.util.UUID)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)67 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)56 Player (org.bukkit.entity.Player)31 EventHandler (org.bukkit.event.EventHandler)11 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)6 Status (com.alessiodp.partiesapi.enums.Status)5 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)5 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)5 UUID (java.util.UUID)5 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 Party (com.alessiodp.partiesapi.objects.Party)3 ArrayList (java.util.ArrayList)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 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1