use of me.botsko.prism.actionlibs.MatchRule in project Prism-Bukkit by prism.
the class PreprocessArgs method parseParam.
/**
*
* @param plugin
* @param sender
* @param parameters
* @param registeredParams
* @param foundArgsNames
* @param foundArgsList
* @param arg
* @return
*/
private static ParseResult parseParam(Prism plugin, CommandSender sender, QueryParameters parameters, HashMap<String, PrismParameterHandler> registeredParams, Set<String> foundArgsNames, List<MatchedParam> foundArgsList, String arg) {
ParseResult result = ParseResult.NotFound;
// Match command argument to parameter handler
for (final Entry<String, PrismParameterHandler> entry : registeredParams.entrySet()) {
PrismParameterHandler parameterHandler = entry.getValue();
if (!parameterHandler.applicable(arg, sender)) {
continue;
}
if (!parameterHandler.hasPermission(arg, sender)) {
result = ParseResult.NoPermission;
continue;
}
result = ParseResult.Found;
foundArgsList.add(new MatchedParam(parameterHandler, arg));
foundArgsNames.add(parameterHandler.getName().toLowerCase());
break;
}
// Reject argument that doesn't match anything
if (result == ParseResult.NotFound) {
// We support an alternate player syntax so that people
// can use the tab-complete
// feature of minecraft. Using p: prevents it.
final Player autoFillPlayer = plugin.getServer().getPlayer(arg);
if (autoFillPlayer != null) {
MatchRule match = MatchRule.INCLUDE;
if (arg.startsWith("!")) {
match = MatchRule.EXCLUDE;
}
result = ParseResult.Found;
parameters.addPlayerName(arg.replace("!", ""), match);
}
}
switch(result) {
case NotFound:
if (sender != null)
sender.sendMessage(Prism.messenger.playerError("Unrecognized parameter '" + arg + "'. Use /prism ? for help."));
break;
case NoPermission:
if (sender != null)
sender.sendMessage(Prism.messenger.playerError("No permission for parameter '" + arg + "', skipped."));
break;
default:
break;
}
return result;
}
use of me.botsko.prism.actionlibs.MatchRule 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) {
}
}
}
});
}
use of me.botsko.prism.actionlibs.MatchRule in project Prism-Bukkit by prism.
the class ActionParameter method process.
/**
*
*/
@Override
public void process(QueryParameters query, String alias, String input, CommandSender sender) {
// Check match type
MatchRule match = MatchRule.INCLUDE;
if (input.startsWith("!")) {
match = MatchRule.EXCLUDE;
}
final String[] actions = input.split(",");
if (actions.length > 0) {
for (final String action : actions) {
// Find all actions that match the action provided - whether the
// full name or
// short name.
final ArrayList<ActionType> actionTypes = Prism.getActionRegistry().getActionsByShortname(action.replace("!", ""));
if (!actionTypes.isEmpty()) {
List<String> noPermission = new ArrayList<String>();
for (final ActionType actionType : actionTypes) {
// Ensure the action allows this process type
if ((query.getProcessType().equals(PrismProcessType.ROLLBACK) && !actionType.canRollback()) || (query.getProcessType().equals(PrismProcessType.RESTORE) && !actionType.canRestore())) {
// );
continue;
}
if (!sender.hasPermission(getPermission() + "." + actionType.getName())) {
noPermission.add(actionType.getName());
continue;
}
query.addActionType(actionType.getName(), match);
}
if (!noPermission.isEmpty()) {
String message = "Ignoring action '" + action + "' because you don't have permission for ";
if (noPermission.size() != 1) {
message += "any of " + Joiner.on(',').join(noPermission) + ".";
} else if (noPermission.get(0).equals(action)) {
message += "it.";
} else {
message += noPermission.get(0) + ".";
}
sender.sendMessage(Prism.messenger.playerError(message));
}
} else {
if (sender != null) {
sender.sendMessage(Prism.messenger.playerError("Ignoring action '" + action.replace("!", "") + "' because it's unrecognized. Did you mean '" + LevenshteinDistance.getClosestAction(action) + "'? Type '/prism params' for help."));
}
}
}
// If none were valid, we end here.
if (query.getActionTypes().size() == 0) {
throw new IllegalArgumentException("Action parameter value not recognized. Try /pr ? for help");
}
}
}
use of me.botsko.prism.actionlibs.MatchRule in project Prism-Bukkit by prism.
the class ReportCommand method blockSumReports.
/**
*
* @param sender
*/
protected void blockSumReports(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) {
call.getSender().sendMessage(Prism.messenger.playerError("You must specify parameters, at least one player."));
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 BlockReportQueryBuilder reportQuery = new BlockReportQueryBuilder(plugin);
final String sql = reportQuery.getQuery(parameters, false);
final int colTextLen = 20;
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 block change 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.playerHeaderMsg("Total block changes for " + ChatColor.DARK_AQUA + playerName));
call.getSender().sendMessage(Prism.messenger.playerMsg(ChatColor.GRAY + TypeUtils.padStringRight("Block", colTextLen) + TypeUtils.padStringRight("Placed", colIntLen) + TypeUtils.padStringRight("Broken", colIntLen)));
while (rs.next()) {
final String alias = Prism.getItems().getAlias(rs.getInt(1), 0);
final int placed = rs.getInt(2);
final int broken = rs.getInt(3);
final String colAlias = TypeUtils.padStringRight(alias, colTextLen);
final String colPlaced = TypeUtils.padStringRight("" + placed, colIntLen);
final String colBroken = TypeUtils.padStringRight("" + broken, colIntLen);
call.getSender().sendMessage(Prism.messenger.playerMsg(ChatColor.DARK_AQUA + colAlias + ChatColor.GREEN + colPlaced + " " + ChatColor.RED + colBroken));
}
} 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) {
}
}
}
});
}
use of me.botsko.prism.actionlibs.MatchRule in project Prism-Bukkit by prism.
the class SelectQueryBuilder method playerCondition.
/**
*
*/
protected void playerCondition() {
final HashMap<String, MatchRule> playerNames = parameters.getPlayerNames();
if (playerNames.size() > 0) {
// Match the first rule, this needs to change, we can't include and
// exclude at the same time
MatchRule playerMatch = MatchRule.INCLUDE;
for (final MatchRule match : playerNames.values()) {
playerMatch = match;
break;
}
final String matchQuery = (playerMatch.equals(MatchRule.INCLUDE) ? "IN" : "NOT IN");
// we're doing it here. This is going to be rewritten soon anyway.
for (Entry<String, MatchRule> entry : playerNames.entrySet()) {
entry.setValue(MatchRule.INCLUDE);
}
// Add conditions
addCondition(tableNameData + ".player_id " + matchQuery + " ( SELECT p.player_id FROM " + prefix + "players p WHERE " + buildMultipleConditions(playerNames, "p.player", null) + ")");
}
}
Aggregations