use of me.botsko.prism.actionlibs.QueryParameters in project Prism-Bukkit by prism.
the class RollbackCommand method handle.
/**
* Handle the command
*/
@Override
public void handle(final CallInfo call) {
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.ROLLBACK, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
parameters.setProcessType(PrismProcessType.ROLLBACK);
parameters.setStringFromRawArgs(call.getArgs(), 1);
// determine if defaults were used
final ArrayList<String> defaultsUsed = parameters.getDefaultsUsed();
String defaultsReminder = "";
if (!defaultsUsed.isEmpty()) {
defaultsReminder += " using defaults:";
for (final String d : defaultsUsed) {
defaultsReminder += " " + d;
}
}
call.getSender().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Preparing results..." + defaultsReminder));
/**
* Run the query 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() {
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getSender());
if (!results.getActionResults().isEmpty()) {
call.getSender().sendMessage(Prism.messenger.playerHeaderMsg("Beginning rollback..."));
// Perform rollback on the main thread
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
final Rollback rb = new Rollback(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
rb.apply();
}
});
} else {
call.getSender().sendMessage(Prism.messenger.playerError("Nothing found to rollback. Try using /prism l (args) first."));
}
}
});
}
use of me.botsko.prism.actionlibs.QueryParameters in project Prism-Bukkit by prism.
the class TeleportCommand method handle.
/**
* Handle the command
*/
@Override
public void handle(CallInfo call) {
// Is there anything even stored to paginate?
String keyName = "console";
if (call.getSender() instanceof Player) {
keyName = call.getSender().getName();
}
if (!plugin.cachedQueries.containsKey(keyName) && !call.getArg(1).contains("id:")) {
call.getSender().sendMessage(Prism.messenger.playerError("There's no saved query to use results from. Maybe they expired? Try your lookup again."));
return;
}
// Parse the incoming ident
String ident = call.getArg(1);
if (ident.contains("id:")) {
ident = ident.replace("id:", "");
}
// Determine result index to tp to - either an id, or the next/previous
// id
int record_id;
if (ident.equals("next") || ident.equals("prev")) {
// Get stored results
final QueryResult results = plugin.cachedQueries.get(keyName);
record_id = results.getLastTeleportIndex();
record_id = (record_id == 0 ? 1 : record_id);
if (record_id > 0) {
if (ident.equals("next")) {
record_id++;
} else {
if (record_id > 1) {
record_id--;
}
}
}
} else {
if (!TypeUtils.isNumeric(ident)) {
call.getPlayer().sendMessage(Prism.messenger.playerError("You must provide a numeric result number or record ID to teleport to."));
return;
}
record_id = Integer.parseInt(ident);
if (record_id <= 0) {
call.getPlayer().sendMessage(Prism.messenger.playerError("Result number or record ID must be greater than zero."));
return;
}
}
// If a record id provided, re-query the database
Handler destinationAction;
if (call.getArg(1).contains("id:")) {
// Build params
final QueryParameters params = new QueryParameters();
params.setWorld(call.getPlayer().getWorld().getName());
params.setId(record_id);
// Query
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(params, call.getPlayer());
if (results.getActionResults().isEmpty()) {
call.getPlayer().sendMessage(Prism.messenger.playerError("No records exists with this ID."));
return;
}
// Get the first result
destinationAction = results.getActionResults().get(0);
} else // Otherwise, look for a cached query
{
// Get stored results
final QueryResult results = plugin.cachedQueries.get(keyName);
if (record_id > results.getActionResults().size()) {
call.getPlayer().sendMessage(Prism.messenger.playerError("No records exists at this index. Did you mean /pr tp id:" + record_id + " instead?"));
return;
}
final int key = (record_id - 1);
// Get the result index specified
destinationAction = results.getActionResults().get(key);
// Refresh the query time and replace
results.setQueryTime();
results.setLastTeleportIndex(record_id);
plugin.cachedQueries.replace(keyName, results);
}
if (destinationAction != null) {
final World world = plugin.getServer().getWorld(destinationAction.getWorldName());
if (world == null) {
call.getPlayer().sendMessage(Prism.messenger.playerError("Action record occurred in world we can't find anymore."));
return;
}
final Location loc = new Location(world, destinationAction.getX(), destinationAction.getY(), destinationAction.getZ());
call.getPlayer().teleport(loc);
call.getPlayer().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Teleporting... " + ChatColor.WHITE + destinationAction.getType().getName() + ChatColor.GRAY + " by " + ChatColor.WHITE + destinationAction.getPlayerName() + ChatColor.GRAY + ", " + ChatColor.WHITE + destinationAction.getTimeSince()));
}
}
use of me.botsko.prism.actionlibs.QueryParameters in project Prism-Bukkit by prism.
the class UndoCommand method handle.
/**
* Handle the command
*/
@Override
public void handle(CallInfo call) {
if (call.getArgs().length > 1) {
final ActionsQuery aq = new ActionsQuery(plugin);
int record_id = 0;
if (TypeUtils.isNumeric(call.getArg(1))) {
record_id = Integer.parseInt(call.getArg(1));
if (record_id <= 0) {
call.getPlayer().sendMessage(Prism.messenger.playerError("Record ID must be greater than zero."));
return;
}
} else {
if (call.getArg(1).equals("last")) {
record_id = aq.getUsersLastPrismProcessId(call.getPlayer().getName());
}
}
// Invalid id
if (record_id == 0) {
call.getPlayer().sendMessage(Prism.messenger.playerError("Either you have no last process or an invalid ID."));
return;
}
final PrismProcessAction process = aq.getPrismProcessRecord(record_id);
if (process == null) {
call.getPlayer().sendMessage(Prism.messenger.playerError("A process does not exists with that value."));
return;
}
// We only support this for drains
if (!process.getProcessChildActionType().equals("prism-drain")) {
call.getPlayer().sendMessage(Prism.messenger.playerError("You can't currently undo anything other than a drain process."));
return;
}
// Pull the actual block change data for this undo event
final QueryParameters parameters = new QueryParameters();
parameters.setWorld(call.getPlayer().getWorld().getName());
parameters.addActionType(process.getProcessChildActionType());
parameters.addPlayerName(call.getPlayer().getName());
parameters.setParentId(record_id);
parameters.setProcessType(PrismProcessType.UNDO);
// make sure the distance isn't too far away
final QueryResult results = aq.lookup(parameters, call.getPlayer());
if (!results.getActionResults().isEmpty()) {
call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Undoing..." + ChatColor.GRAY + " Abandon ship!"));
final Undo rb = new Undo(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
rb.apply();
} else {
call.getPlayer().sendMessage(Prism.messenger.playerError("Nothing found to undo. Must be a problem with Prism."));
}
} else {
// Show the list
// Process and validate all of the arguments
final QueryParameters parameters = new QueryParameters();
parameters.setAllowNoRadius(true);
parameters.addActionType("prism-process");
parameters.addPlayerName(call.getPlayer().getName());
// @todo config this, and move the logic
parameters.setLimit(5);
// to queryparams
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getPlayer());
if (!results.getActionResults().isEmpty()) {
call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Showing " + results.getTotalResults() + " results. Page 1 of " + results.getTotal_pages()));
call.getPlayer().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Use /prism undo [id] to reverse a process"));
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
for (final Handler a : paginated) {
final ActionMessage am = new ActionMessage(a);
if (parameters.allowsNoRadius() || parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
call.getPlayer().sendMessage(Prism.messenger.playerMsg(am.getMessage()));
}
} else {
call.getPlayer().sendMessage(Prism.messenger.playerError("Pagination can't find anything. Do you have the right page number?"));
}
} else {
call.getPlayer().sendMessage(Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
use of me.botsko.prism.actionlibs.QueryParameters in project Prism-Bukkit by prism.
the class OreMonitor method processAlertsFromBlock.
/**
*
* @param player
* @param block
*/
public void processAlertsFromBlock(final Player player, final Block block) {
if (!plugin.getConfig().getBoolean("prism.alerts.ores.enabled")) {
return;
}
if (player == null || player.getGameMode() == null || player.getGameMode().equals(GameMode.CREATIVE)) {
return;
}
if (block != null && isWatched(block) && !plugin.alertedBlocks.containsKey(block.getLocation())) {
threshold = 1;
// identify all ore blocks on same Y axis in x/z direction
final ArrayList<Block> matchingBlocks = new ArrayList<Block>();
final ArrayList<Block> foundores = findNeighborBlocks(block.getType(), block, matchingBlocks);
if (!foundores.isEmpty()) {
// Save the block
final BlockState state = block.getState();
// Set to air to get the light
block.setType(Material.AIR);
int light = block.getLightLevel();
light = (light > 0 ? Math.round(((light) & 0xFF) * 100) / 15 : 0);
// Restore the block
block.setType(state.getType());
final String count = foundores.size() + (foundores.size() >= threshold_max ? "+" : "");
final String msg = getOreColor(block) + player.getName() + " found " + count + " " + getOreNiceName(block) + " " + light + "% light";
/**
* 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() {
// check if block placed
boolean wasplaced = false;
// Build params
final QueryParameters params = new QueryParameters();
params.setWorld(player.getWorld().getName());
params.addSpecificBlockLocation(block.getLocation());
params.addActionType("block-place");
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(params, player);
if (!results.getActionResults().isEmpty()) {
wasplaced = true;
}
if (!wasplaced) {
// Alert staff
plugin.alertPlayers(null, TypeUtils.colorize(msg));
// Log to console
if (plugin.getConfig().getBoolean("prism.alerts.ores.log-to-console")) {
Prism.log(msg);
}
// Log to commands
List<String> commands = plugin.getConfig().getStringList("prism.alerts.ores.log-commands");
MiscUtils.dispatchAlert(msg, commands);
}
}
});
}
}
}
use of me.botsko.prism.actionlibs.QueryParameters in project Prism-Bukkit by prism.
the class InspectorWand method showLocationHistory.
/**
*
* @param player
* @param block
* @param loc
*/
protected void showLocationHistory(final Player player, final Location loc) {
final Block block = loc.getBlock();
/**
* 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() {
// Build params
QueryParameters params;
try {
params = parameters.clone();
} catch (final CloneNotSupportedException ex) {
params = new QueryParameters();
player.sendMessage(Prism.messenger.playerError("Error retrieving parameters. Checking with default parameters."));
}
params.setWorld(player.getWorld().getName());
params.setSpecificBlockLocation(loc);
// Do we need a second location? (For beds, doors, etc)
final Block sibling = me.botsko.elixr.BlockUtils.getSiblingForDoubleLengthBlock(block);
if (sibling != null) {
params.addSpecificBlockLocation(sibling.getLocation());
}
// Ignoring any actions via config?
if (params.getActionTypes().size() == 0) {
@SuppressWarnings("unchecked") final ArrayList<String> ignoreActions = (ArrayList<String>) plugin.getConfig().getList("prism.wands.inspect.ignore-actions");
if (ignoreActions != null && !ignoreActions.isEmpty()) {
for (final String ignore : ignoreActions) {
params.addActionType(ignore, MatchRule.EXCLUDE);
}
}
}
boolean timeDefault = false;
for (final String _default : params.getDefaultsUsed()) {
if (_default.startsWith("t:")) {
timeDefault = true;
}
}
if (timeDefault) {
params.setIgnoreTime(true);
}
// Query
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(params, player);
if (!results.getActionResults().isEmpty()) {
final String blockname = Prism.getItems().getAlias(block.getTypeId(), block.getData());
player.sendMessage(Prism.messenger.playerHeaderMsg(ChatColor.GOLD + "--- Inspecting " + blockname + " at " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ() + " ---"));
if (results.getActionResults().size() > 5) {
player.sendMessage(Prism.messenger.playerHeaderMsg("Showing " + results.getTotalResults() + " results. Page 1 of " + results.getTotal_pages()));
}
for (final me.botsko.prism.actions.Handler a : results.getPaginatedActionResults()) {
final ActionMessage am = new ActionMessage(a);
if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
player.sendMessage(Prism.messenger.playerMsg(am.getMessage()));
}
} else {
final String space_name = (block.getType().equals(Material.AIR) ? "space" : block.getType().toString().replaceAll("_", " ").toLowerCase() + (block.getType().toString().endsWith("BLOCK") ? "" : " block"));
player.sendMessage(Prism.messenger.playerError("No history for this " + space_name + " found."));
}
}
});
}
Aggregations