use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteStatLoader method loadStatValues.
public List<StoredStat> loadStatValues(Minigame minigame, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) {
MinigameUtils.debugMessage("SQLite beginning stat load for " + minigame.getName(false) + ", " + stat + ", " + field);
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
// First get the id
int minigameId = backend.getMinigameId(handler, minigame);
return loadStats(handler, minigameId, stat, field, order, offset, length);
} catch (SQLException e) {
return Collections.emptyList();
} finally {
if (handler != null) {
handler.release();
}
MinigameUtils.debugMessage("SQLite completed stat load for " + minigame.getName(false));
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteStatLoader method loadSingleValue.
public long loadSingleValue(Minigame minigame, MinigameStat stat, StatValueField field, UUID playerId) {
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
// First get the id
int minigameId = backend.getMinigameId(handler, minigame);
String statName = stat.getName() + field.getSuffix();
ResultSet rs = handler.executeQuery(getSingle, minigameId, playerId.toString(), statName);
try {
if (rs.next()) {
return rs.getLong("value");
} else {
return 0;
}
} finally {
rs.close();
}
} catch (SQLException e) {
logger.log(Level.SEVERE, "Failed to load stat for " + minigame.getName(false) + " " + playerId, e);
return 0;
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteStatSaver method saveData.
public void saveData(StoredGameStats data) {
MinigameUtils.debugMessage("SQLite beginning save of " + data);
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
try {
handler.beginTransaction();
// Get the minigame id and update both the player and game
int minigameId = backend.getMinigameId(handler, data.getMinigame());
backend.updatePlayer(handler, data.getPlayer());
saveStats(handler, data, data.getPlayer().getUUID(), minigameId);
// Commit the changes
handler.endTransaction();
} catch (SQLException e) {
logger.log(Level.SEVERE, "Failed to save stats for " + data.getPlayer().getName(), e);
handler.endTransactionFail();
} finally {
MinigameUtils.debugMessage("SQLite completed save of " + data);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLStatSaver method saveData.
public void saveData(StoredGameStats data) {
MinigameUtils.debugMessage("MySQL beginning save of " + data);
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
try {
handler.beginTransaction();
// Get the minigame id and update both the player and game
int minigameId = backend.getMinigameId(handler, data.getMinigame());
backend.updatePlayer(handler, data.getPlayer());
saveStats(handler, data, data.getPlayer().getUUID(), minigameId);
// Commit the changes
handler.endTransaction();
} catch (SQLException e) {
logger.log(Level.SEVERE, "Failed to save stats for " + data.getPlayer().getName(), e);
handler.endTransactionFail();
} finally {
MinigameUtils.debugMessage("MySQL completed save of " + data);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteBackend method loadStatSettings.
@Override
public Map<MinigameStat, StatSettings> loadStatSettings(Minigame minigame) {
ConnectionHandler handler = null;
try {
handler = pool.getConnection();
int minigameId = getMinigameId(handler, minigame);
ResultSet rs = handler.executeQuery(loadStatSettings, minigameId);
Map<MinigameStat, StatSettings> settings = Maps.newHashMap();
try {
while (rs.next()) {
String statName = rs.getString("stat");
String rawFormat = rs.getString("format");
String displayName = rs.getString("display_name");
MinigameStat stat = MinigameStats.getStat(statName);
if (stat == null) {
// Just ignore it
continue;
}
// Decode format
StatFormat format = null;
for (StatFormat f : StatFormat.values()) {
if (f.name().equalsIgnoreCase(rawFormat)) {
format = f;
break;
}
}
if (format == null) {
format = stat.getFormat();
}
StatSettings setting = new StatSettings(stat, format, displayName);
settings.put(stat, setting);
}
return settings;
} finally {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
return Collections.emptyMap();
} finally {
if (handler != null) {
handler.release();
}
}
}
Aggregations