use of me.botsko.prism.appliers.Rollback in project Prism-Bukkit by prism.
the class RollbackWand method rollback.
/**
*
* @param player
* @param block
*/
protected void rollback(Player player, Location loc) {
final Block block = loc.getBlock();
plugin.eventTimer.recordTimedEvent("rollback wand used");
// 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(block.getLocation());
params.setLimit(1);
params.setProcessType(PrismProcessType.ROLLBACK);
boolean timeDefault = false;
for (final String _default : params.getDefaultsUsed()) {
if (_default.startsWith("t:")) {
timeDefault = true;
}
}
if (timeDefault) {
params.setIgnoreTime(true);
}
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(params, player);
if (!results.getActionResults().isEmpty()) {
final Rollback rb = new Rollback(plugin, player, results.getActionResults(), params, new PrismApplierCallback());
rb.apply();
} 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("Nothing to rollback for this " + space_name + " found."));
}
}
use of me.botsko.prism.appliers.Rollback 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."));
}
}
});
}
Aggregations