Search in sources :

Example 1 with PartyDeleteTask

use of com.alessiodp.parties.tasks.PartyDeleteTask 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)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 PartyDeleteTask (com.alessiodp.parties.tasks.PartyDeleteTask)1