use of me.botsko.prism.actionlibs.QueryResult 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.actionlibs.QueryResult 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")));
}
});
}
use of me.botsko.prism.actionlibs.QueryResult 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:")) {
Prism.messenger.sendMessage(call.getSender(), 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
long recordId;
if (ident.equals("next") || ident.equals("prev")) {
// Get stored results
final QueryResult results = plugin.cachedQueries.get(keyName);
recordId = results.getLastTeleportIndex();
recordId = (recordId == 0 ? 1 : recordId);
if (recordId > 0) {
if (ident.equals("next")) {
recordId++;
} else {
if (recordId > 1) {
recordId--;
}
}
}
} else {
if (!TypeUtils.isNumeric(ident)) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("You must provide a numeric result number or record ID to teleport to."));
return;
}
recordId = Integer.parseInt(ident);
if (recordId <= 0) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Result number or record ID must be greater than zero."));
return;
}
}
// If a record id provided, re-query the database
final Handler destinationAction;
if (call.getArg(1).contains("id:")) {
// Build params
final QueryParameters params = new QueryParameters();
params.setWorld(call.getPlayer().getWorld().getName());
params.setId(recordId);
// Query
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(params, call.getPlayer());
if (results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("No records exists with this ID."));
return;
}
// Get the first result
destinationAction = results.getActionResults().get(0);
} else {
// Get stored results
final QueryResult results = plugin.cachedQueries.get(keyName);
if (recordId > results.getActionResults().size()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("No records exists at this index. Did you mean /pr tp id:" + recordId + " instead?"));
return;
}
final int key = (int) (recordId - 1);
// Get the result index specified
destinationAction = results.getActionResults().get(key);
// Refresh the query time and replace
results.setQueryTime();
results.setLastTeleportIndex(recordId);
plugin.cachedQueries.replace(keyName, results);
}
if (destinationAction != null) {
final World world = destinationAction.getLoc().getWorld();
if (world == null) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Action record occurred in world we can't find anymore."));
return;
}
if (PaperLib.isPaper()) {
PaperLib.teleportAsync(call.getPlayer(), destinationAction.getLoc()).thenAccept(success -> sendTeleportCompleteMessage(success, call.getPlayer(), destinationAction));
} else {
sendTeleportCompleteMessage(call.getPlayer().teleport(destinationAction.getLoc()), call.getPlayer(), destinationAction);
}
}
}
use of me.botsko.prism.actionlibs.QueryResult in project Prism-Bukkit by prism.
the class NearCommand method handle.
@Override
public void handle(final CallInfo call) {
// Build params
final QueryParameters parameters = new QueryParameters();
parameters.setPerPage(plugin.getConfig().getInt("prism.queries.default-results-per-page"));
parameters.setWorld(call.getPlayer().getWorld().getName());
// allow a custom near radius
int radius = plugin.getConfig().getInt("prism.near.default-radius");
if (call.getArgs().length == 2) {
if (TypeUtils.isNumeric(call.getArg(1))) {
final int _tmp_radius = Integer.parseInt(call.getArg(1));
if (_tmp_radius > 0) {
radius = _tmp_radius;
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Radius must be greater than zero. Or leave it off to use the default. " + "Use /prism ? for help."));
return;
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Radius must be a number. Or leave it off to use the default." + " Use /prism ? for help."));
return;
}
}
parameters.setRadius(radius);
parameters.setMinMaxVectorsFromPlayerLocation(call.getPlayer().getLocation());
parameters.setLimit(plugin.getConfig().getInt("prism.near.max-results"));
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
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.playerSubduedHeaderMsg(Il8nHelper.formatMessage("near-result-report", parameters.getRadius())));
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated != null) {
int resultCount = results.getIndexOfFirstResult();
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();
}
am.setResultIndex(resultCount);
MiscUtils.sendClickableTpRecord(am, call.getPlayer());
resultCount++;
}
MiscUtils.sendPageButtons(results, call.getPlayer());
// Flush timed data
plugin.eventTimer.printTimeRecord();
} 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("Couldn't find anything."));
}
});
}
use of me.botsko.prism.actionlibs.QueryResult in project Prism-Bukkit by prism.
the class PageCommand method handle.
/**
* {@inheritDoc}
*/
@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)) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("There's no saved query to paginate. Maybe they expired? Try your lookup again."));
return;
}
// Get stored results
final QueryResult results = plugin.cachedQueries.get(keyName);
if (call.getArgs().length != 2) {
Prism.getAudiences().sender(call.getSender()).sendMessage(Identity.nil(), Prism.messenger.playerError("Please specify a page number. Like /prism page 2"));
return;
}
// Determine page number
int page;
if (TypeUtils.isNumeric(call.getArg(1))) {
page = Integer.parseInt(call.getArg(1));
} else {
if (call.getArg(1).equals("next") || call.getArg(1).equals("n")) {
page = results.getPage() + 1;
} else if (call.getArg(1).equals("prev") || call.getArg(1).equals("p")) {
if (results.getPage() <= 1) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("There is no previous page."));
return;
}
page = results.getPage() - 1;
} else {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("Page numbers need to actually be numbers, or next/prev." + " Like /prism page 2"));
return;
}
}
// No negatives
if (page <= 0) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("Page must be greater than zero."));
return;
}
results.setPage(page);
// Refresh the query time and replace
results.setQueryTime();
plugin.cachedQueries.replace(keyName, results);
// Results?
if (results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
return;
}
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), results.getPage(), results.getTotalPages())));
final List<Handler> paginated = results.getPaginatedActionResults();
if (paginated == null || paginated.size() == 0) {
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError("Pagination can't find anything. " + "Do you have the right page number?"));
return;
}
// Show it!
int resultCount = results.getIndexOfFirstResult();
for (final Handler a : paginated) {
final ActionMessage am = new ActionMessage(a);
if (results.getParameters().hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
am.showExtended();
}
am.setResultIndex(resultCount);
MiscUtils.sendClickableTpRecord(am, call.getSender());
resultCount++;
}
MiscUtils.sendPageButtons(results, call.getSender());
}
Aggregations