Search in sources :

Example 1 with Party

use of com.alessiodp.partiesapi.objects.Party in project Parties by AlessioDP.

the class FileDispatcher method loadEntireData.

@Override
public DatabaseData loadEntireData() {
    // Players
    Map<UUID, PartyPlayer> players = new HashMap<UUID, PartyPlayer>();
    for (PartyPlayer pp : getAllPlayers()) players.put(pp.getPlayerUUID(), pp);
    // Parties
    Map<String, Party> parties = new HashMap<String, Party>();
    for (Party p : getAllParties()) parties.put(p.getName(), p);
    return new DatabaseData(players, parties);
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) HashMap(java.util.HashMap) UUID(java.util.UUID) DatabaseData(com.alessiodp.parties.storage.DatabaseData)

Example 2 with Party

use of com.alessiodp.partiesapi.objects.Party in project Parties by AlessioDP.

the class YAMLDao method getAllParties.

@Override
public List<Party> getAllParties() {
    List<Party> ret = new ArrayList<Party>();
    for (String key : data.getConfigurationSection("parties").getKeys(false)) {
        String node = "parties." + key;
        try {
            Party p = new Party(key);
            p.setDescription(data.getString(node + ".desc", ""));
            p.setMotd(data.getString(node + "..motd", ""));
            p.setPrefix(data.getString(node + ".prefix", ""));
            p.setSuffix(data.getString(node + ".suffix", ""));
            p.setColor(plugin.getColorManager().searchColorByName(data.getString(node + ".color", "")));
            p.setKills(data.getInt(node + ".kills", 0));
            p.setHome(PartiesUtils.formatHome(data.getString(node + ".home", "")));
            String lead = data.getString(node + ".leader", "");
            if (!lead.isEmpty()) {
                if (lead.equalsIgnoreCase(Constants.FIXED_VALUE_TEXT)) {
                    p.setLeader(UUID.fromString(Constants.FIXED_VALUE_UUID));
                    p.setFixed(true);
                } else
                    p.setLeader(UUID.fromString(lead));
            }
            List<UUID> mem = new ArrayList<UUID>();
            for (String id : data.getStringList(node + ".members")) {
                try {
                    mem.add(UUID.fromString(id));
                } catch (Exception ex) {
                }
            }
            p.setMembers(mem);
            ret.add(p);
        } catch (Exception ex) {
        }
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IOException(java.io.IOException)

Example 3 with Party

use of com.alessiodp.partiesapi.objects.Party 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 4 with Party

use of com.alessiodp.partiesapi.objects.Party in project Parties by AlessioDP.

the class PartyManager method reload.

public void reload() {
    listParties = new HashMap<String, PartyEntity>();
    listPartiesToDelete = new HashMap<String, Integer>();
    if (ConfigParties.FIXED_ENABLE) {
        List<Party> lst = plugin.getDatabaseManager().getAllFixed().join();
        for (Party party : lst) {
            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_FIXED_LOAD.replace("{party}", party.getName()), true);
            loadParty(party.getName());
        }
    }
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 5 with Party

use of com.alessiodp.partiesapi.objects.Party in project Parties by AlessioDP.

the class PartyManager method getParty.

public PartyEntity getParty(String name) {
    // Just get the party without save it into the party list
    PartyEntity ret = null;
    if (name != null && !name.isEmpty()) {
        ret = getListParties().get(name.toLowerCase());
        if (ret == null) {
            Party p = plugin.getDatabaseManager().getParty(name).join();
            if (p != null) {
                ret = new PartyEntity(p, plugin);
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_GET_DATABASE.replace("{party}", ret.getName()), true);
            }
        } else
            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_GET_LIST.replace("{party}", ret.getName()), true);
    }
    if (ret != null) {
        plugin.getColorManager().loadDynamicColor(ret);
        ret.refreshPlayers();
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Aggregations

Party (com.alessiodp.partiesapi.objects.Party)26 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)6 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)3 DatabaseData (com.alessiodp.parties.storage.DatabaseData)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 Connection (java.sql.Connection)1 Player (org.bukkit.entity.Player)1