Search in sources :

Example 21 with Party

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

the class DatabaseManager method getPartySync.

public Party getPartySync(String party) {
    DebugUtils.debugLog("Data call: getParty()");
    long nsTime = System.nanoTime();
    Party futureRet = database.getParty(party);
    DebugUtils.debugDataTiming(nsTime);
    return futureRet;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party)

Example 22 with Party

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

the class FileDispatcher method getParty.

@Override
public Party getParty(String party) {
    Party ret = null;
    String node = "parties." + party;
    if (database.existData(node)) {
        ret = database.loadPartyData(party);
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party)

Example 23 with Party

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

the class YAMLDao method loadPartyData.

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

Example 24 with Party

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

the class SQLDispatcher method getPartyFromResultSet.

private Party getPartyFromResultSet(Connection connection, ResultSet rs) {
    Party ret = null;
    try {
        ret = new Party(rs.getString("name"));
        ret.setDescription(rs.getString("description"));
        ret.setMotd(rs.getString("motd"));
        ret.setPrefix(rs.getString("prefix"));
        ret.setSuffix(rs.getString("suffix"));
        ret.setColor(plugin.getColorManager().searchColorByName(rs.getString("color")));
        ret.setKills(rs.getInt("kills"));
        ret.setPassword(rs.getString("password"));
        ret.setHome(PartiesUtils.formatHome(rs.getString("home")));
        String leader = rs.getString("leader");
        if (leader != null) {
            if (leader.equalsIgnoreCase(Constants.FIXED_VALUE_TEXT)) {
                ret.setLeader(UUID.fromString(Constants.FIXED_VALUE_UUID));
                ret.setFixed(true);
            } else
                ret.setLeader(UUID.fromString(leader));
        }
        ret.setMembers(getMembersParty(connection, rs.getString("name")));
    } catch (Exception ex) {
        LoggerManager.printError(LoggerManager.formatErrorCallTrace(Constants.DEBUG_SQL_ERROR, ex));
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) SQLException(java.sql.SQLException)

Example 25 with Party

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

the class SQLDispatcher method saveEntireData.

@Override
public boolean saveEntireData(DatabaseData data) {
    boolean ret = false;
    try (Connection connection = getConnection()) {
        connection.setAutoCommit(false);
        // Players
        for (Entry<UUID, PartyPlayer> entry : data.getPlayers().entrySet()) updatePlayer(entry.getValue(), connection);
        // Parties
        for (Entry<String, Party> entry : data.getParties().entrySet()) {
            updateParty(entry.getValue(), connection);
        }
        connection.commit();
        ret = true;
    } catch (Exception ex) {
        LoggerManager.printError(LoggerManager.formatErrorCallTrace(Constants.DEBUG_SQL_ERROR, ex));
    }
    return ret;
}
Also used : Party(com.alessiodp.partiesapi.objects.Party) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Connection(java.sql.Connection) UUID(java.util.UUID) SQLException(java.sql.SQLException)

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