use of me.botsko.prism.appliers.Previewable in project Prism-Bukkit by prism.
the class PreviewCommand method handleRestore.
private void handleRestore(CallInfo call, QueryParameters parameters, QueryResult results, Audience audience) {
parameters.setProcessType(PrismProcessType.RESTORE);
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("preview-apply-start")));
// Perform preview on the main thread
plugin.getServer().getScheduler().runTask(plugin, () -> {
final Previewable rs = new Restore(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
rs.preview();
});
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-no-actions")));
}
}
use of me.botsko.prism.appliers.Previewable in project Prism-Bukkit by prism.
the class PreviewCommand method handleRollBack.
private void handleRollBack(final CallInfo call, final QueryParameters parameters, final QueryResult results, final Audience audience) {
parameters.setProcessType(PrismProcessType.ROLLBACK);
if (!results.getActionResults().isEmpty()) {
audience.sendMessage(Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("preview-apply-start")));
// Perform preview on the main thread
plugin.getServer().getScheduler().runTask(plugin, () -> {
final Previewable rs = new Rollback(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
rs.preview();
});
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found to preview."));
}
}
use of me.botsko.prism.appliers.Previewable in project Prism-Bukkit by prism.
the class RestoreWand method restore.
protected void restore(Player player, Location loc) {
final Block block = loc.getBlock();
QueryParameters params = checkQueryParams(block, parameters, player);
params.setProcessType(PrismProcessType.RESTORE);
final QueryResult results = getResult(params, player);
if (!results.getActionResults().isEmpty()) {
final Previewable rb = new Restore(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"));
Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing to restore for this " + space_name + " found."));
}
}
use of me.botsko.prism.appliers.Previewable in project Prism-Bukkit by prism.
the class UndoCommand method handle.
@Override
public void handle(CallInfo call) {
final Audience audience = Prism.getAudiences().player(call.getPlayer());
if (call.getArgs().length > 1) {
final ActionsQuery aq = new ActionsQuery(plugin);
long recordId = 0;
if (TypeUtils.isNumeric(call.getArg(1))) {
recordId = Long.parseLong(call.getArg(1));
if (recordId <= 0) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Record ID must be greater than zero."));
return;
}
} else {
if (call.getArg(1).equals("last")) {
recordId = aq.getUsersLastPrismProcessId(call.getPlayer().getName());
}
}
// Invalid id
if (recordId == 0) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Either you have no last process or an invalid ID."));
return;
}
final PrismProcessAction process = aq.getPrismProcessRecord(recordId);
if (process == null) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("A process does not exists with that value."));
return;
}
// We only support this for drains
if (!process.getProcessChildActionType().equals("prism-drain")) {
Prism.messenger.sendMessage(call.getPlayer(), 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(recordId);
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()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("command-undo-complete")));
final Previewable rb = new Undo(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
rb.apply();
} else {
Prism.messenger.sendMessage(call.getPlayer(), 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()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-undo-help")));
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
for (final Handler a : paginated) {
final ActionMessage am = new ActionMessage(a);
if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerMsg(am.getMessage()));
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Pagination can't find anything. Do you have the right page number?"));
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
use of me.botsko.prism.appliers.Previewable in project Prism-Bukkit by prism.
the class RestoreCommand method handle.
@Override
public void handle(final CallInfo call) {
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.RESTORE, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
parameters.setProcessType(PrismProcessType.RESTORE);
parameters.setStringFromRawArgs(call.getArgs(), 1);
StringBuilder defaultsReminder = checkIfDefaultUsed(parameters);
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerSubduedHeaderMsg(ReplaceableTextComponent.builder("restore-prepare").replace("<defaults>", defaultsReminder).build()));
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getSender());
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("restore-start")));
// Inform nearby players
if (call.getSender() instanceof Player) {
final Player player = (Player) call.getSender();
plugin.notifyNearby(player, parameters.getRadius(), ReplaceableTextComponent.builder("block-changes-near").replace("<player>", player.getDisplayName()).build());
}
// Perform restore on the main thread
plugin.getServer().getScheduler().runTask(plugin, () -> {
final Previewable rs = new Restore(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
rs.apply();
});
} else {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError(Il8nHelper.getMessage("restore-error")));
}
});
}
Aggregations