use of me.botsko.prism.actionlibs.ActionMessage in project Prism-Bukkit by prism.
the class LookupCommand method handle.
/**
* Handle the command.
*/
@Override
public void handle(final CallInfo call) {
// Process and validate all of the arguments
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
// Run the lookup itself in an async task so the lookup query isn't done on the main thread
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// determine if defaults were used
final List<String> defaultsUsed = parameters.getDefaultsUsed();
StringBuilder defaultsReminder = new StringBuilder();
if (!defaultsUsed.isEmpty()) {
defaultsReminder.append(Il8nHelper.getRawMessage("queryparameter.defaults.prefix"));
for (final String d : defaultsUsed) {
defaultsReminder.append(" ").append(d);
}
}
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getSender());
final StringBuilder sharingWithPlayers = new StringBuilder();
for (final CommandSender shareWith : parameters.getSharedPlayers()) {
sharingWithPlayers.append(shareWith.getName()).append(", ");
}
if (sharingWithPlayers.length() > 0) {
sharingWithPlayers.delete(sharingWithPlayers.lastIndexOf(","), sharingWithPlayers.length());
}
final String playersList = sharingWithPlayers.toString();
// Add current sender
parameters.addSharedPlayer(call.getSender());
for (final CommandSender player : parameters.getSharedPlayers()) {
final boolean isSender = player.getName().equals(call.getSender().getName());
if (!isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("lookup-share-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<sender>"), builder -> Component.text().content(call.getSender().getName()).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1)));
} else if (sharingWithPlayers.length() > 0) {
Component component = Il8nHelper.getMessage("lookup-share-to-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<players>"), builder -> Component.text().content(playersList).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1);
Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(component));
}
if (!results.getActionResults().isEmpty()) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
if ((defaultsReminder.length() > 0) && isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
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, player);
resultCount++;
}
MiscUtils.sendPageButtons(results, player);
} else {
Prism.messenger.sendMessage(player, Prism.messenger.playerError(Il8nHelper.getMessage("no-pagination-found")));
}
if (parameters.hasFlag(Flag.PASTE)) {
StringBuilder paste = new StringBuilder();
for (final Handler a : results.getActionResults()) {
paste.append(new ActionMessage(a).getRawMessage()).append("\r\n");
}
MiscUtils.paste_results(player, paste.toString());
}
} else {
if (defaultsReminder.length() > 0) {
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
}
}
if (isSender) {
Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
}
}
}
// Flush timed data
plugin.eventTimer.printTimeRecord();
});
}
use of me.botsko.prism.actionlibs.ActionMessage in project Prism-Bukkit by prism.
the class InspectorWand method showLocationHistory.
/**
* Show the Location History for a player.
*
* @param player Player
* @param loc Location
*/
private void showLocationHistory(final Player player, final Location loc) {
final Block block = loc.getBlock();
final Block sibling = Utilities.getSiblingForDoubleLengthBlock(block);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// Build params
QueryParameters params;
try {
params = parameters.clone();
} catch (final CloneNotSupportedException ex) {
params = new QueryParameters();
Prism.messenger.sendMessage(player, 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)
if (sibling != null) {
params.addSpecificBlockLocation(sibling.getLocation());
}
// Ignoring any actions via config?
if (params.getActionTypes().size() == 0) {
@SuppressWarnings("unchecked") final Collection<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);
}
}
}
final QueryResult results = getResult(params, player);
if (!results.getActionResults().isEmpty()) {
final String blockname = Prism.getItems().getAlias(block.getType(), block.getBlockData());
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(ReplaceableTextComponent.builder("inspector-wand-header").replace("<blockname>", blockname).replace("<x>", loc.getBlockX()).replace("<y>", loc.getBlockY()).replace("<z>", loc.getBlockY()).build().colorIfAbsent(NamedTextColor.GOLD)));
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
int resultCount = results.getIndexOfFirstResult();
for (final me.botsko.prism.api.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();
}
am.setResultIndex(resultCount);
MiscUtils.sendClickableTpRecord(am, player);
resultCount++;
}
MiscUtils.sendPageButtons(results, player);
} 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("No history for this " + space_name + " found."));
}
});
}
use of me.botsko.prism.actionlibs.ActionMessage 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.ActionMessage 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.ActionMessage 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