use of me.botsko.prism.database.mysql.ActionReportQueryBuilder in project Prism-Bukkit by prism.
the class ReportCommand method actionTypeCountReport.
/**
*
* @param sender
*/
protected void actionTypeCountReport(final CallInfo call) {
// Process and validate all of the arguments
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 3, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
// No actions
if (!parameters.getActionTypes().isEmpty()) {
call.getSender().sendMessage(Prism.messenger.playerError("You may not specify any action types for this report."));
return;
}
// Verify single player name for now
final HashMap<String, MatchRule> players = parameters.getPlayerNames();
if (players.size() != 1) {
call.getSender().sendMessage(Prism.messenger.playerError("You must provide only a single player name."));
return;
}
// Get single playername
String tempName = "";
for (final String player : players.keySet()) {
tempName = player;
break;
}
final String playerName = tempName;
final ActionReportQueryBuilder reportQuery = new ActionReportQueryBuilder(plugin);
final String sql = reportQuery.getQuery(parameters, false);
final int colTextLen = 16;
final int colIntLen = 12;
/**
* Run the lookup itself in an async task so the lookup query isn't done
* on the main thread
*/
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
call.getSender().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Crafting action type report for " + ChatColor.DARK_AQUA + playerName + "..."));
Connection conn = null;
PreparedStatement s = null;
ResultSet rs = null;
try {
conn = Prism.dbc();
s = conn.prepareStatement(sql);
s.executeQuery();
rs = s.getResultSet();
call.getSender().sendMessage(Prism.messenger.playerMsg(ChatColor.GRAY + TypeUtils.padStringRight("Action", colTextLen) + TypeUtils.padStringRight("Count", colIntLen)));
while (rs.next()) {
final String action = rs.getString(2);
final int count = rs.getInt(1);
final String colAlias = TypeUtils.padStringRight(action, colTextLen);
final String colPlaced = TypeUtils.padStringRight("" + count, colIntLen);
call.getSender().sendMessage(Prism.messenger.playerMsg(ChatColor.DARK_AQUA + colAlias + ChatColor.GREEN + colPlaced));
}
} catch (final SQLException e) {
e.printStackTrace();
} finally {
if (rs != null)
try {
rs.close();
} catch (final SQLException ignored) {
}
if (s != null)
try {
s.close();
} catch (final SQLException ignored) {
}
if (conn != null)
try {
conn.close();
} catch (final SQLException ignored) {
}
}
}
});
}
Aggregations