use of me.botsko.prism.actionlibs.QueryResult in project Prism-Bukkit by prism.
the class RollbackWand method rollback.
protected void rollback(Player player, Location loc) {
final Block block = loc.getBlock();
QueryParameters params = checkQueryParams(block, parameters, player);
params.setProcessType(PrismProcessType.ROLLBACK);
final QueryResult results = getResult(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"));
Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing to rollback for this " + space_name + " found."));
}
}
use of me.botsko.prism.actionlibs.QueryResult 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.QueryResult in project Prism-Bukkit by prism.
the class PreviewCommand method handle.
@Override
public void handle(final CallInfo call) {
final Audience audience = Prism.getAudiences().sender(call.getPlayer());
if (call.getArgs().length >= 2) {
if (call.getArg(1).equalsIgnoreCase("apply")) {
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
final PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName());
previewSession.getPreviewer().apply_preview();
plugin.playerActivePreviews.remove(call.getPlayer().getName());
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("You have no preview pending."));
}
return;
}
if (call.getArg(1).equalsIgnoreCase("cancel")) {
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
final PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName());
previewSession.getPreviewer().cancel_preview();
plugin.playerActivePreviews.remove(call.getPlayer().getName());
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-none-pending")));
}
return;
}
// Ensure no current preview is waiting
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-pending")));
return;
}
if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rb") || call.getArg(1).equalsIgnoreCase("rs")) {
final QueryParameters parameters = PreprocessArgs.process(plugin, call.getPlayer(), call.getArgs(), PrismProcessType.ROLLBACK, 2, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
if (parameters == null) {
return;
}
parameters.setStringFromRawArgs(call.getArgs(), 1);
if (parameters.getActionTypes().containsKey("world-edit")) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-worldedit-unsupported")));
return;
}
StringBuilder defaultsReminder = checkIfDefaultUsed(parameters);
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("queryparameter.defaults.prefix", defaultsReminder.toString())));
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// Perform preview
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getPlayer());
// Rollback
if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("rb")) {
handleRollBack(call, parameters, results, audience);
// todo remove debug
assert (parameters.getProcessType() == PrismProcessType.ROLLBACK);
}
// Restore
if (call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rs")) {
handleRestore(call, parameters, results, audience);
// todo remove debug
assert (parameters.getProcessType() == PrismProcessType.RESTORE);
}
});
return;
}
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("invalid-command")));
}
}
use of me.botsko.prism.actionlibs.QueryResult in project Prism-Bukkit by prism.
the class OreMonitor method processAlertsFromBlock.
/**
* Process alerts.
*
* @param player Player
* @param block Block
* @param alertPerm Players with this permission will receive the alert
*/
public void processAlertsFromBlock(final Player player, final Block block, final String alertPerm) {
if (!plugin.getConfig().getBoolean("prism.alerts.ores.enabled")) {
return;
}
if (player == 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<>();
final ArrayList<Block> foundores = findNeighborBlocks(block.getType(), block, matchingBlocks);
if (!foundores.isEmpty()) {
// Create alert message
final String count = foundores.size() + (foundores.size() >= thresholdMax ? "+" : "");
final String msg = player.getName() + " found " + count + " " + getOreNiceName(block) + " " + getLightLevel(block) + "% light";
final TextComponent component = Component.text().content(msg).color(getOreColor(block)).hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ShowItem.of(Key.key(block.getType().getKey().toString()), 1))).build();
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// Check if block placed
// 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()) {
// Block was not placed - Alert staff
plugin.alertPlayers(null, component, alertPerm);
// Log to console
if (plugin.getConfig().getBoolean("prism.alerts.ores.log-to-console")) {
Prism.log(PlainComponentSerializer.plain().serialize(component));
}
// Log to commands
List<String> commands = plugin.getConfig().getStringList("prism.alerts.ores.log-commands");
MiscUtils.dispatchAlert(msg, commands);
}
});
}
}
}
use of me.botsko.prism.actionlibs.QueryResult 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);
}
}
});
}
}
}
Aggregations