Search in sources :

Example 1 with PrismApplierCallback

use of me.botsko.prism.appliers.PrismApplierCallback in project Prism-Bukkit by prism.

the class RollbackWand method rollback.

/**
     * 
     * @param player
     * @param block
     */
protected void rollback(Player player, Location loc) {
    final Block block = loc.getBlock();
    plugin.eventTimer.recordTimedEvent("rollback wand used");
    // Build params
    QueryParameters params;
    try {
        params = parameters.clone();
    } catch (final CloneNotSupportedException ex) {
        params = new QueryParameters();
        player.sendMessage(Prism.messenger.playerError("Error retrieving parameters. Checking with default parameters."));
    }
    params.setWorld(player.getWorld().getName());
    params.setSpecificBlockLocation(block.getLocation());
    params.setLimit(1);
    params.setProcessType(PrismProcessType.ROLLBACK);
    boolean timeDefault = false;
    for (final String _default : params.getDefaultsUsed()) {
        if (_default.startsWith("t:")) {
            timeDefault = true;
        }
    }
    if (timeDefault) {
        params.setIgnoreTime(true);
    }
    final ActionsQuery aq = new ActionsQuery(plugin);
    final QueryResult results = aq.lookup(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"));
        player.sendMessage(Prism.messenger.playerError("Nothing to rollback for this " + space_name + " found."));
    }
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) Block(org.bukkit.block.Block) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Rollback(me.botsko.prism.appliers.Rollback)

Example 2 with PrismApplierCallback

use of me.botsko.prism.appliers.PrismApplierCallback in project Prism-Bukkit by prism.

the class RestoreCommand method handle.

/**
     * Handle the command
     */
@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);
    // determine if defaults were used
    final ArrayList<String> defaultsUsed = parameters.getDefaultsUsed();
    String defaultsReminder = "";
    if (!defaultsUsed.isEmpty()) {
        defaultsReminder += " using defaults:";
        for (final String d : defaultsUsed) {
            defaultsReminder += " " + d;
        }
    }
    call.getSender().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Preparing results..." + defaultsReminder));
    /**
         * Run the query 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() {
            final ActionsQuery aq = new ActionsQuery(plugin);
            final QueryResult results = aq.lookup(parameters, call.getSender());
            if (!results.getActionResults().isEmpty()) {
                call.getSender().sendMessage(Prism.messenger.playerHeaderMsg("Restoring changes..."));
                // Inform nearby players
                if (call.getSender() instanceof Player) {
                    final Player player = (Player) call.getSender();
                    plugin.notifyNearby(player, parameters.getRadius(), player.getDisplayName() + " is re-applying block changes nearby. Just so you know.");
                }
                // Perform restore on the main thread
                plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        final Restore rs = new Restore(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
                        rs.apply();
                    }
                });
            } else {
                call.getSender().sendMessage(Prism.messenger.playerError("Nothing found to restore. Try using /prism l (args) first."));
            }
        }
    });
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) Player(org.bukkit.entity.Player) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Restore(me.botsko.prism.appliers.Restore)

Example 3 with PrismApplierCallback

use of me.botsko.prism.appliers.PrismApplierCallback in project Prism-Bukkit by prism.

the class RollbackCommand method handle.

/**
     * Handle the command
     */
@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);
    // determine if defaults were used
    final ArrayList<String> defaultsUsed = parameters.getDefaultsUsed();
    String defaultsReminder = "";
    if (!defaultsUsed.isEmpty()) {
        defaultsReminder += " using defaults:";
        for (final String d : defaultsUsed) {
            defaultsReminder += " " + d;
        }
    }
    call.getSender().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Preparing results..." + defaultsReminder));
    /**
         * Run the query 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() {
            final ActionsQuery aq = new ActionsQuery(plugin);
            final QueryResult results = aq.lookup(parameters, call.getSender());
            if (!results.getActionResults().isEmpty()) {
                call.getSender().sendMessage(Prism.messenger.playerHeaderMsg("Beginning rollback..."));
                // Perform rollback on the main thread
                plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        final Rollback rb = new Rollback(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
                        rb.apply();
                    }
                });
            } else {
                call.getSender().sendMessage(Prism.messenger.playerError("Nothing found to rollback. Try using /prism l (args) first."));
            }
        }
    });
}
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 4 with PrismApplierCallback

use of me.botsko.prism.appliers.PrismApplierCallback in project Prism-Bukkit by prism.

the class UndoCommand method handle.

/**
     * Handle the command
     */
@Override
public void handle(CallInfo call) {
    if (call.getArgs().length > 1) {
        final ActionsQuery aq = new ActionsQuery(plugin);
        int record_id = 0;
        if (TypeUtils.isNumeric(call.getArg(1))) {
            record_id = Integer.parseInt(call.getArg(1));
            if (record_id <= 0) {
                call.getPlayer().sendMessage(Prism.messenger.playerError("Record ID must be greater than zero."));
                return;
            }
        } else {
            if (call.getArg(1).equals("last")) {
                record_id = aq.getUsersLastPrismProcessId(call.getPlayer().getName());
            }
        }
        // Invalid id
        if (record_id == 0) {
            call.getPlayer().sendMessage(Prism.messenger.playerError("Either you have no last process or an invalid ID."));
            return;
        }
        final PrismProcessAction process = aq.getPrismProcessRecord(record_id);
        if (process == null) {
            call.getPlayer().sendMessage(Prism.messenger.playerError("A process does not exists with that value."));
            return;
        }
        // We only support this for drains
        if (!process.getProcessChildActionType().equals("prism-drain")) {
            call.getPlayer().sendMessage(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(record_id);
        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()) {
            call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Undoing..." + ChatColor.GRAY + " Abandon ship!"));
            final Undo rb = new Undo(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
            rb.apply();
        } else {
            call.getPlayer().sendMessage(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()) {
            call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Showing " + results.getTotalResults() + " results. Page 1 of " + results.getTotal_pages()));
            call.getPlayer().sendMessage(Prism.messenger.playerSubduedHeaderMsg("Use /prism undo [id] to reverse a process"));
            final List<Handler> paginated = results.getPaginatedActionResults();
            if (paginated != null) {
                for (final Handler a : paginated) {
                    final ActionMessage am = new ActionMessage(a);
                    if (parameters.allowsNoRadius() || parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
                        am.showExtended();
                    }
                    call.getPlayer().sendMessage(Prism.messenger.playerMsg(am.getMessage()));
                }
            } else {
                call.getPlayer().sendMessage(Prism.messenger.playerError("Pagination can't find anything. Do you have the right page number?"));
            }
        } else {
            call.getPlayer().sendMessage(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) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) Handler(me.botsko.prism.actions.Handler) SubHandler(me.botsko.prism.commandlibs.SubHandler) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Undo(me.botsko.prism.appliers.Undo)

Example 5 with PrismApplierCallback

use of me.botsko.prism.appliers.PrismApplierCallback in project Prism-Bukkit by prism.

the class RestoreWand method restore.

/**
     * 
     * @param player
     * @param block
     */
protected void restore(Player player, Location loc) {
    final Block block = loc.getBlock();
    plugin.eventTimer.recordTimedEvent("rollback wand used");
    // Build params
    QueryParameters params;
    try {
        params = parameters.clone();
    } catch (final CloneNotSupportedException ex) {
        params = new QueryParameters();
        player.sendMessage(Prism.messenger.playerError("Error retrieving parameters. Checking with default parameters."));
    }
    params.setWorld(player.getWorld().getName());
    params.setSpecificBlockLocation(block.getLocation());
    params.setLimit(1);
    params.setProcessType(PrismProcessType.RESTORE);
    boolean timeDefault = false;
    for (final String _default : params.getDefaultsUsed()) {
        if (_default.startsWith("t:")) {
            timeDefault = true;
        }
    }
    if (timeDefault) {
        params.setIgnoreTime(true);
    }
    final ActionsQuery aq = new ActionsQuery(plugin);
    final QueryResult results = aq.lookup(params, player);
    if (!results.getActionResults().isEmpty()) {
        final Restore 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"));
        player.sendMessage(Prism.messenger.playerError("Nothing to restore for this " + space_name + " found."));
    }
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) Block(org.bukkit.block.Block) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Restore(me.botsko.prism.appliers.Restore)

Aggregations

ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)5 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)5 QueryResult (me.botsko.prism.actionlibs.QueryResult)5 PrismApplierCallback (me.botsko.prism.appliers.PrismApplierCallback)5 Restore (me.botsko.prism.appliers.Restore)2 Rollback (me.botsko.prism.appliers.Rollback)2 Block (org.bukkit.block.Block)2 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)1 Handler (me.botsko.prism.actions.Handler)1 PrismProcessAction (me.botsko.prism.actions.PrismProcessAction)1 Undo (me.botsko.prism.appliers.Undo)1 SubHandler (me.botsko.prism.commandlibs.SubHandler)1 Player (org.bukkit.entity.Player)1