Search in sources :

Example 6 with ActionsQuery

use of me.botsko.prism.actionlibs.ActionsQuery 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);
                    }
                }
            });
        }
    }
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) BlockState(org.bukkit.block.BlockState) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) QueryParameters(me.botsko.prism.actionlibs.QueryParameters)

Example 7 with ActionsQuery

use of me.botsko.prism.actionlibs.ActionsQuery in project Prism-Bukkit by prism.

the class Prism method performLookup.

@Override
public Future<Result> performLookup(PrismParameters parameters, CommandSender sender) {
    CompletableFuture<Result> resultCompletableFuture = new CompletableFuture<>();
    Bukkit.getScheduler().runTaskAsynchronously(instance, () -> {
        Result result = new ActionsQuery(Prism.getInstance()).lookup(parameters, sender);
        resultCompletableFuture.complete(result);
    });
    return resultCompletableFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) Result(me.botsko.prism.api.Result) QueryResult(me.botsko.prism.actionlibs.QueryResult)

Example 8 with ActionsQuery

use of me.botsko.prism.actionlibs.ActionsQuery in project Prism-Bukkit by prism.

the class QueryWandBase method getResult.

QueryResult getResult(QueryParameters params, Player player) {
    boolean timeDefault = false;
    for (final String _default : params.getDefaultsUsed()) {
        if (_default.startsWith("t:")) {
            timeDefault = true;
            break;
        }
    }
    if (timeDefault) {
        params.setIgnoreTime(true);
    }
    // Query
    final ActionsQuery aq = new ActionsQuery(plugin);
    return aq.lookup(params, player);
}
Also used : ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery)

Example 9 with ActionsQuery

use of me.botsko.prism.actionlibs.ActionsQuery in project Prism-Bukkit by prism.

the class RollbackCommand method handle.

@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);
    StringBuilder defaultsReminder = checkIfDefaultUsed(parameters);
    Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerSubduedHeaderMsg(ReplaceableTextComponent.builder("rollback-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("rollback-start")));
            // Perform rollback on the main thread
            plugin.getServer().getScheduler().runTask(plugin, () -> {
                final Rollback rb = new Rollback(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
                rb.apply();
            });
        } else {
            Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError(Il8nHelper.getMessage("rollback-error")));
        }
    });
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Rollback(me.botsko.prism.appliers.Rollback)

Example 10 with ActionsQuery

use of me.botsko.prism.actionlibs.ActionsQuery 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."));
        }
    }
}
Also used : PrismProcessAction(me.botsko.prism.actions.PrismProcessAction) QueryResult(me.botsko.prism.actionlibs.QueryResult) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) Audience(net.kyori.adventure.audience.Audience) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) Handler(me.botsko.prism.api.actions.Handler) SubHandler(me.botsko.prism.commandlibs.SubHandler) Previewable(me.botsko.prism.appliers.Previewable) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Undo(me.botsko.prism.appliers.Undo)

Aggregations

ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)13 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)11 QueryResult (me.botsko.prism.actionlibs.QueryResult)10 Handler (me.botsko.prism.api.actions.Handler)4 SubHandler (me.botsko.prism.commandlibs.SubHandler)4 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)3 PrismApplierCallback (me.botsko.prism.appliers.PrismApplierCallback)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Previewable (me.botsko.prism.appliers.Previewable)2 Audience (net.kyori.adventure.audience.Audience)2 Block (org.bukkit.block.Block)2 Player (org.bukkit.entity.Player)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Pattern (java.util.regex.Pattern)1 Il8nHelper (me.botsko.prism.Il8nHelper)1 Prism (me.botsko.prism.Prism)1 PrismProcessAction (me.botsko.prism.actions.PrismProcessAction)1 Result (me.botsko.prism.api.Result)1