Search in sources :

Example 16 with QueryParameters

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

the class QueryWandBase method setParameters.

/**
     * Set the field {@link #parameters} with the parameters here. This will be
     * using the stuff in <code>/prism params</code>
     * 
     * @param sender
     *            The sender of the command.
     * @param args
     *            The arguments from <code>/prism params</code>.
     * @param argStart
     *            What argument to start on.
     */
public boolean setParameters(Player sender, String[] args, int argStart) {
    final PrismProcessType processType = this instanceof RollbackWand ? PrismProcessType.ROLLBACK : this instanceof RestoreWand ? PrismProcessType.RESTORE : this instanceof InspectorWand ? PrismProcessType.LOOKUP : PrismProcessType.LOOKUP;
    final QueryParameters params = PreprocessArgs.process(plugin, sender, args, processType, argStart, false, true);
    if (params == null) {
        return false;
    } else {
        params.resetMinMaxVectors();
        this.parameters = params;
        return true;
    }
}
Also used : PrismProcessType(me.botsko.prism.appliers.PrismProcessType) QueryParameters(me.botsko.prism.actionlibs.QueryParameters)

Example 17 with QueryParameters

use of me.botsko.prism.actionlibs.QueryParameters 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)

Example 18 with QueryParameters

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

the class PurgeManager method run.

/**
	 * 
	 */
@Override
public void run() {
    Prism.log("Scheduled purge executor beginning new run...");
    if (!purgeRules.isEmpty()) {
        final CopyOnWriteArrayList<QueryParameters> paramList = new CopyOnWriteArrayList<QueryParameters>();
        for (final String purgeArgs : purgeRules) {
            // Process and validate all of the arguments
            final QueryParameters parameters = PreprocessArgs.process(plugin, null, purgeArgs.split(" "), PrismProcessType.DELETE, 0, false);
            if (parameters == null) {
                Prism.log("Invalid parameters for database purge: " + purgeArgs);
                continue;
            }
            if (parameters.getFoundArgs().size() > 0) {
                parameters.setStringFromRawArgs(purgeArgs.split(" "), 0);
                paramList.add(parameters);
            }
        }
        if (paramList.size() > 0) {
            // Identify the minimum for chunking
            final int minId = PurgeChunkingUtil.getMinimumPrimaryKey();
            if (minId == 0) {
                Prism.log("No minimum primary key could be found for purge chunking.");
                return;
            }
            // Identify the max id for chunking
            final int maxId = PurgeChunkingUtil.getMaximumPrimaryKey();
            if (maxId == 0) {
                Prism.log("No maximum primary key could be found for purge chunking.");
                return;
            }
            int purge_tick_delay = plugin.getConfig().getInt("prism.purge.batch-tick-delay");
            if (purge_tick_delay < 1) {
                purge_tick_delay = 20;
            }
            /**
                 * We're going to cycle through the param rules, one rule at a
                 * time in a single async task. This task will reschedule itself
                 * when each purge cycle has completed and records remain
                 */
            Prism.log("Beginning prism database purge cycle. Will be performed in batches so we don't tie up the db...");
            deleteTask = Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new PurgeTask(plugin, paramList, purge_tick_delay, minId, maxId, new LogPurgeCallback()), purge_tick_delay);
        }
    } else {
        Prism.log("Purge rules are empty, not purging anything.");
    }
}
Also used : QueryParameters(me.botsko.prism.actionlibs.QueryParameters) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

QueryParameters (me.botsko.prism.actionlibs.QueryParameters)18 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)12 QueryResult (me.botsko.prism.actionlibs.QueryResult)11 PrismApplierCallback (me.botsko.prism.appliers.PrismApplierCallback)5 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)4 Handler (me.botsko.prism.actions.Handler)4 SubHandler (me.botsko.prism.commandlibs.SubHandler)4 Block (org.bukkit.block.Block)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Player (org.bukkit.entity.Player)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 MatchRule (me.botsko.prism.actionlibs.MatchRule)2 Restore (me.botsko.prism.appliers.Restore)2 Rollback (me.botsko.prism.appliers.Rollback)2 PrismProcessAction (me.botsko.prism.actions.PrismProcessAction)1