Search in sources :

Example 11 with PartyEntity

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

the class CommandList method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    int selectedPage = 1;
    if (commandData.getArgs().length == 2) {
        try {
            selectedPage = Integer.parseInt(commandData.getArgs()[1]);
        } catch (NumberFormatException ex) {
            pp.sendMessage(Messages.ADDCMD_LIST_WRONGCMD);
            return;
        }
    }
    /*
		 * Command starts
		 */
    // Get all parties
    List<PartyEntity> parties = new ArrayList<PartyEntity>();
    for (Party party : plugin.getDatabaseManager().getAllParties().join()) {
        if (party != null) {
            PartyEntity partyImpl = new PartyEntity(party, plugin);
            partyImpl.reloadOnlinePlayers();
            if (partyImpl.getNumberOnlinePlayers() >= ConfigParties.LIST_FILTERMIN)
                parties.add(partyImpl);
        }
    }
    // Order parties
    switch(ConfigParties.LIST_ORDEREDBY.toLowerCase()) {
        case "kills":
            if (!ConfigParties.KILLS_ENABLE)
                parties = orderName(parties);
            else
                parties = orderKills(parties);
            break;
        case "players":
            parties = orderPlayers(parties);
            break;
        case "allplayers":
            parties = orderAllPlayers(parties);
            break;
        default:
            parties = orderName(parties);
    }
    // Group up parties
    parties = limitList(parties);
    int maxPages;
    if (parties.size() == 0)
        maxPages = 1;
    else if (parties.size() % ConfigParties.LIST_PERPAGE == 0)
        maxPages = parties.size() / ConfigParties.LIST_PERPAGE;
    else
        maxPages = (parties.size() / ConfigParties.LIST_PERPAGE) + 1;
    if (selectedPage > maxPages)
        selectedPage = maxPages;
    else if (selectedPage < 1)
        selectedPage = 1;
    int currentPage = 0;
    StringBuilder sb = new StringBuilder();
    sb.append(Messages.ADDCMD_LIST_HEADER).append("\n");
    for (PartyEntity party : parties) {
        int currentChoosenPage = (selectedPage - 1) * ConfigParties.LIST_PERPAGE;
        if (currentPage >= currentChoosenPage && currentPage < (currentChoosenPage + ConfigParties.LIST_PERPAGE)) {
            sb.append(PartiesUtils.convertPartyPlaceholders(Messages.ADDCMD_LIST_FORMATPARTY, party)).append("\n");
        }
        currentPage++;
    }
    if (parties.size() == 0)
        sb.append(Messages.ADDCMD_LIST_NOONE).append("\n");
    sb.append(Messages.ADDCMD_LIST_FOOTER);
    pp.sendMessage(sb.toString().replace("%number%", Integer.toString(parties.size())).replace("%page%", Integer.toString(selectedPage)).replace("%maxpages%", Integer.toString(maxPages)));
    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_STOP.replace("{player}", pp.getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Party(com.alessiodp.partiesapi.objects.Party) ArrayList(java.util.ArrayList) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 12 with PartyEntity

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

the class CommandList method orderPlayers.

private List<PartyEntity> orderPlayers(List<PartyEntity> list) {
    int from;
    for (int c = 0; c < list.size() - 1; c++) {
        from = c;
        for (int c2 = c + 1; c2 < list.size(); c2++) {
            if (list.get(c2).getNumberOnlinePlayers() > list.get(from).getNumberOnlinePlayers()) {
                from = c2;
            }
        }
        if (from != c) {
            PartyEntity temp = list.get(c);
            list.set(c, list.get(from));
            list.set(from, temp);
        }
    }
    return list;
}
Also used : PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 13 with PartyEntity

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

the class CommandList method orderAllPlayers.

private List<PartyEntity> orderAllPlayers(List<PartyEntity> list) {
    int from;
    for (int c = 0; c < list.size() - 1; c++) {
        from = c;
        for (int c2 = c + 1; c2 < list.size(); c2++) {
            if (list.get(c2).getMembers().size() > list.get(from).getMembers().size()) {
                from = c2;
            }
        }
        if (from != c) {
            PartyEntity temp = list.get(c);
            list.set(c, list.get(from));
            list.set(from, temp);
        }
    }
    return list;
}
Also used : PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 14 with PartyEntity

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

the class CommandList method orderName.

private List<PartyEntity> orderName(List<PartyEntity> list) {
    int from;
    for (int c = 0; c < list.size() - 1; c++) {
        from = c;
        for (int c2 = c + 1; c2 < list.size(); c2++) {
            if (list.get(c2).getName().trim().compareTo(list.get(from).getName().trim()) < 0) {
                from = c2;
            }
        }
        if (from != c) {
            PartyEntity temp = list.get(c);
            list.set(c, list.get(from));
            list.set(from, temp);
        }
    }
    return list;
}
Also used : PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 15 with PartyEntity

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

the class CommandList method orderKills.

private List<PartyEntity> orderKills(List<PartyEntity> list) {
    int from;
    for (int c = 0; c < list.size() - 1; c++) {
        from = c;
        for (int c2 = c + 1; c2 < list.size(); c2++) {
            if (list.get(c2).getKills() > list.get(from).getKills()) {
                from = c2;
            }
        }
        if (from != c) {
            PartyEntity temp = list.get(c);
            list.set(c, list.get(from));
            list.set(from, temp);
        }
    }
    return list;
}
Also used : PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

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