Search in sources :

Example 1 with Restore

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

the class PreviewCommand method handleRestore.

private void handleRestore(CallInfo call, QueryParameters parameters, QueryResult results, Audience audience) {
    parameters.setProcessType(PrismProcessType.RESTORE);
    if (!results.getActionResults().isEmpty()) {
        Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("preview-apply-start")));
        // Perform preview on the main thread
        plugin.getServer().getScheduler().runTask(plugin, () -> {
            final Previewable rs = new Restore(plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback());
            rs.preview();
        });
    } else {
        Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-no-actions")));
    }
}
Also used : PrismApplierCallback(me.botsko.prism.appliers.PrismApplierCallback) Previewable(me.botsko.prism.appliers.Previewable) Restore(me.botsko.prism.appliers.Restore)

Example 2 with Restore

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

the class RestoreWand method restore.

protected void restore(Player player, Location loc) {
    final Block block = loc.getBlock();
    QueryParameters params = checkQueryParams(block, parameters, player);
    params.setProcessType(PrismProcessType.RESTORE);
    final QueryResult results = getResult(params, player);
    if (!results.getActionResults().isEmpty()) {
        final Previewable 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"));
        Prism.messenger.sendMessage(player, 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) Block(org.bukkit.block.Block) Previewable(me.botsko.prism.appliers.Previewable) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Restore(me.botsko.prism.appliers.Restore)

Example 3 with Restore

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

the class RestoreCommand method handle.

@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);
    StringBuilder defaultsReminder = checkIfDefaultUsed(parameters);
    Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerSubduedHeaderMsg(ReplaceableTextComponent.builder("restore-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("restore-start")));
            // Inform nearby players
            if (call.getSender() instanceof Player) {
                final Player player = (Player) call.getSender();
                plugin.notifyNearby(player, parameters.getRadius(), ReplaceableTextComponent.builder("block-changes-near").replace("<player>", player.getDisplayName()).build());
            }
            // Perform restore on the main thread
            plugin.getServer().getScheduler().runTask(plugin, () -> {
                final Previewable rs = new Restore(plugin, call.getSender(), results.getActionResults(), parameters, new PrismApplierCallback());
                rs.apply();
            });
        } else {
            Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerError(Il8nHelper.getMessage("restore-error")));
        }
    });
}
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) Previewable(me.botsko.prism.appliers.Previewable) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Restore(me.botsko.prism.appliers.Restore)

Aggregations

Previewable (me.botsko.prism.appliers.Previewable)3 PrismApplierCallback (me.botsko.prism.appliers.PrismApplierCallback)3 Restore (me.botsko.prism.appliers.Restore)3 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)2 QueryResult (me.botsko.prism.actionlibs.QueryResult)2 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1