use of au.com.mineauz.minigames.stats.StoredStat in project Minigames by AddstarMC.
the class ScoreboardCommand method onCommand.
@Override
public boolean onCommand(final CommandSender sender, Minigame ignore, String label, String[] args) {
if (args == null || args.length < 3) {
return false;
}
// Decode arguments
final Minigame minigame = plugin.mdata.getMinigame(args[0]);
if (minigame == null) {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[0]);
return true;
}
final MinigameStat stat = MinigameStats.getStat(args[1]);
if (stat == null) {
sender.sendMessage(ChatColor.RED + "No statistic found by the name " + args[1]);
return true;
}
final StatSettings settings = minigame.getSettings(stat);
StatValueField field = null;
for (StatValueField f : settings.getFormat().getFields()) {
if (f.name().equalsIgnoreCase(args[2])) {
field = f;
break;
}
}
if (field == null) {
sender.sendMessage(ChatColor.RED + "No field found by the name " + args[2] + " for the statistic " + stat.getDisplayName());
return true;
}
// Prepare defaults for optionals
ScoreboardOrder order;
switch(field) {
case Last:
case Total:
case Max:
order = ScoreboardOrder.DESCENDING;
break;
case Min:
order = ScoreboardOrder.ASCENDING;
break;
default:
throw new AssertionError();
}
int start = 0;
int length = 8;
// Now the optionals
for (int i = 3; i < args.length - 1; i += 2) {
if (args[i].equalsIgnoreCase("-o")) {
// Order
if (args[i + 1].equalsIgnoreCase("asc") || args[i + 1].equalsIgnoreCase("ascending")) {
order = ScoreboardOrder.ASCENDING;
} else if (args[i + 1].equalsIgnoreCase("desc") || args[i + 1].equalsIgnoreCase("descending")) {
order = ScoreboardOrder.DESCENDING;
} else {
sender.sendMessage(ChatColor.RED + "Unknown order " + args[i + 1] + ". Expected asc, ascending, desc, or descending.");
return true;
}
} else if (args[i].equalsIgnoreCase("-l")) {
// Length
if (args[i + 1].matches("[1-9][0-9]*")) {
length = Integer.parseInt(args[i + 1]);
} else {
sender.sendMessage(ChatColor.RED + "Unknown length " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else if (args[i].equalsIgnoreCase("-s")) {
// Start
if (args[i + 1].matches("[1-9][0-9]*")) {
start = Integer.parseInt(args[i + 1]) - 1;
} else {
sender.sendMessage(ChatColor.RED + "Unknown start " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Unknown option " + args[i] + ". Expected -o, -l, or -s");
return true;
}
}
final ScoreboardOrder fOrder = order;
final StatValueField fField = field;
sender.sendMessage(ChatColor.GRAY + "Loading scoreboard...");
// Now load the values
ListenableFuture<List<StoredStat>> future = plugin.getBackend().loadStats(minigame, stat, field, order, start, length);
Futures.addCallback(future, new FutureCallback<List<StoredStat>>() {
@Override
public void onSuccess(List<StoredStat> result) {
sender.sendMessage(ChatColor.GREEN + minigame.getName(true) + " Scoreboard: " + settings.getDisplayName() + " - " + fField.getTitle() + " " + fOrder.toString().toLowerCase());
for (StoredStat playerStat : result) {
sender.sendMessage(ChatColor.AQUA + playerStat.getPlayerDisplayName() + ": " + ChatColor.WHITE + stat.displayValue(playerStat.getValue(), settings));
}
}
@Override
public void onFailure(Throwable t) {
sender.sendMessage(ChatColor.RED + "An internal error occured while loading the statistics");
t.printStackTrace();
}
});
return true;
}
use of au.com.mineauz.minigames.stats.StoredStat in project Minigames by AddstarMC.
the class SQLiteStatLoader method loadStat.
private StoredStat loadStat(ResultSet rs) throws SQLException {
UUID playerId = UUID.fromString(rs.getString("player_id"));
String name = rs.getString("name");
String displayName = rs.getString("displayname");
long value = rs.getLong("value");
return new StoredStat(playerId, name, displayName, value);
}
use of au.com.mineauz.minigames.stats.StoredStat in project Minigames by AddstarMC.
the class MySQLStatLoader method loadStats.
// Loads from the stats table
private List<StoredStat> loadStats(ConnectionHandler handler, int minigameId, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) throws SQLException {
String statName = stat.getName() + field.getSuffix();
try {
StatementKey statement;
switch(order) {
case ASCENDING:
statement = getSingleAsc;
break;
case DESCENDING:
statement = getSingleDesc;
break;
default:
throw new AssertionError();
}
ResultSet rs = handler.executeQuery(statement, minigameId, statName, offset, length);
List<StoredStat> stats = Lists.newArrayList();
try {
while (rs.next()) {
stats.add(loadStat(rs));
}
return stats;
} finally {
rs.close();
}
} finally {
handler.release();
}
}
use of au.com.mineauz.minigames.stats.StoredStat in project Minigames by AddstarMC.
the class MySQLStatLoader method loadStat.
private StoredStat loadStat(ResultSet rs) throws SQLException {
UUID playerId = UUID.fromString(rs.getString("player_id"));
String name = rs.getString("name");
String displayName = rs.getString("displayname");
long value = rs.getLong("value");
return new StoredStat(playerId, name, displayName, value);
}
use of au.com.mineauz.minigames.stats.StoredStat in project Minigames by AddstarMC.
the class SQLiteStatLoader method loadStats.
// Loads from the stats table
private List<StoredStat> loadStats(ConnectionHandler handler, int minigameId, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) throws SQLException {
String statName = stat.getName() + field.getSuffix();
StatementKey statement;
switch(order) {
case ASCENDING:
statement = getSingleAsc;
break;
case DESCENDING:
statement = getSingleDesc;
break;
default:
throw new AssertionError();
}
ResultSet rs = handler.executeQuery(statement, minigameId, statName, offset, length);
List<StoredStat> stats = Lists.newArrayList();
try {
while (rs.next()) {
stats.add(loadStat(rs));
}
return stats;
} finally {
rs.close();
}
}
Aggregations