/** Handle the command */ public void handle(CallInfo call) { if (call.getArgs().length >= 2) { /** Apply previous preview changes */ if (call.getArg(1).equalsIgnoreCase("apply")) { if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) { PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName()); previewSession.getPreviewer().apply_preview(); plugin.playerActivePreviews.remove(call.getPlayer().getName()); } else { call.getPlayer().sendMessage(Prism.messenger.playerError("You have no preview pending.")); } return; } /** Cancel preview */ if (call.getArg(1).equalsIgnoreCase("cancel")) { if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) { PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName()); previewSession.getPreviewer().cancel_preview(); plugin.playerActivePreviews.remove(call.getPlayer().getName()); } else { call.getPlayer().sendMessage(Prism.messenger.playerError("You have no preview pending.")); } return; } // Ensure no current preview is waiting if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) { call.getPlayer() .sendMessage( Prism.messenger.playerError( "You have an existing preview pending. Please apply or cancel before moving on.")); return; } /** Begin a rollback or restore preview */ if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rb") || call.getArg(1).equalsIgnoreCase("rs")) { 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")) { call.getPlayer() .sendMessage( Prism.messenger.playerError( "Prism does not support previews for WorldEdit rollbacks/restores yet.")); return; } // determine if defaults were used ArrayList<String> defaultsUsed = parameters.getDefaultsUsed(); String defaultsReminder = ""; if (!defaultsUsed.isEmpty()) { defaultsReminder += " using defaults:"; for (String d : defaultsUsed) { defaultsReminder += " " + d; } } call.getPlayer() .sendMessage( Prism.messenger.playerSubduedHeaderMsg("Preparing results..." + defaultsReminder)); // Perform preview ActionsQuery aq = new ActionsQuery(plugin); QueryResult results = aq.lookup(parameters, call.getPlayer()); // Rollback if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("rb")) { parameters.setProcessType(PrismProcessType.ROLLBACK); if (!results.getActionResults().isEmpty()) { call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Beginning preview...")); Previewable rs = new Rollback( plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback()); rs.preview(); } else { call.getPlayer().sendMessage(Prism.messenger.playerError("Nothing found to preview.")); } } // Restore if (call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rs")) { parameters.setProcessType(PrismProcessType.RESTORE); if (!results.getActionResults().isEmpty()) { call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Beginning preview...")); Previewable rs = new Restore( plugin, call.getPlayer(), results.getActionResults(), parameters, new PrismApplierCallback()); rs.preview(); } else { call.getPlayer().sendMessage(Prism.messenger.playerError("Nothing found to preview.")); } } return; } call.getPlayer() .sendMessage(Prism.messenger.playerError("Invalid command. Check /prism ? for help.")); } }
/** Handle the command */ @Override public void handle(final CallInfo call) { // Allow for canceling tasks if (call.getArgs().length > 1 && call.getArg(1).equals("cancel")) { if (plugin.getPurgeManager().deleteTask != null) { plugin.getPurgeManager().deleteTask.cancel(); call.getSender() .sendMessage(Prism.messenger.playerMsg("Current purge tasks have been canceled.")); } else { call.getSender() .sendMessage(Prism.messenger.playerError("No purge task is currently running.")); } return; } // Allow for wiping live queue if (call.getArgs().length > 1 && call.getArg(1).equals("queue")) { if (RecordingQueue.getQueue().size() > 0) { Prism.log( "User " + call.getSender().getName() + " wiped the live queue before it could be written to the database. " + RecordingQueue.getQueue().size() + " events lost."); RecordingQueue.getQueue().clear(); call.getSender() .sendMessage(Prism.messenger.playerSuccess("Unwritten data in queue cleared.")); } else { call.getSender() .sendMessage(Prism.messenger.playerError("Event queue is empty, nothing to wipe.")); } return; } // Process and validate all of the arguments final QueryParameters parameters = PreprocessArgs.process( plugin, call.getSender(), call.getArgs(), PrismProcessType.DELETE, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults")); if (parameters == null) { return; } 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; } } if (parameters.getFoundArgs().size() > 0) { // Identify the minimum for chunking final int minId = PurgeChunkingUtil.getMinimumPrimaryKey(); if (minId == 0) { call.getSender() .sendMessage( Prism.messenger.playerError( "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) { call.getSender() .sendMessage( Prism.messenger.playerError( "No maximum primary key could be found for purge chunking")); return; } call.getSender() .sendMessage( Prism.messenger.playerSubduedHeaderMsg("Purging data..." + defaultsReminder)); int purge_tick_delay = plugin.getConfig().getInt("prism.purge.batch-tick-delay"); if (purge_tick_delay < 1) { purge_tick_delay = 20; } call.getSender() .sendMessage( Prism.messenger.playerHeaderMsg( "Starting purge cycle." + ChatColor.GRAY + " No one will ever know...")); // build callback final SenderPurgeCallback callback = new SenderPurgeCallback(); callback.setSender(call.getSender()); // add to an arraylist so we're consistent final CopyOnWriteArrayList<QueryParameters> paramList = new CopyOnWriteArrayList<QueryParameters>(); paramList.add(parameters); Prism.log( "Beginning prism database purge cycle. Will be performed in batches so we don't tie up the db..."); deleteTask = plugin .getServer() .getScheduler() .runTaskAsynchronously( plugin, new PurgeTask(plugin, paramList, purge_tick_delay, minId, maxId, callback)); } else { call.getSender() .sendMessage(Prism.messenger.playerError("You must supply at least one parameter.")); } }
/** Handle the command */ @Override public void handle(final CallInfo call) { if (call.getArgs().length <= 1) { call.getSender() .sendMessage(Prism.messenger.playerError("Invalid command. Use /pr ? for help")); return; } boolean recorderActive = false; if (plugin.recordingTask != null) { final int taskId = plugin.recordingTask.getTaskId(); final BukkitScheduler scheduler = Bukkit.getScheduler(); if (scheduler.isCurrentlyRunning(taskId) || scheduler.isQueued(taskId)) { recorderActive = true; } } // Allow for canceling recorders if (call.getArg(1).equals("cancel")) { if (recorderActive) { plugin.recordingTask.cancel(); plugin.recordingTask = null; call.getSender() .sendMessage(Prism.messenger.playerMsg("Current recording task has been canceled.")); call.getSender() .sendMessage( Prism.messenger.playerError( "WARNING: Actions will collect until queue until recorder restarted manually.")); } else { call.getSender() .sendMessage(Prism.messenger.playerError("No recording task is currently running.")); } return; } // Allow for force-restarting recorders if (call.getArg(1).equals("start")) { if (recorderActive) { call.getSender() .sendMessage( Prism.messenger.playerError( "Recording tasks are currently running. Cannot start.")); } else { // Run db tests... call.getSender() .sendMessage(Prism.messenger.playerMsg("Validating database connections...")); // Attempt to get db Connection conn = null; try { conn = Prism.dbc(); if (conn == null || conn.isClosed()) { call.getSender() .sendMessage( Prism.messenger.playerError( "Valid database connection could not be found. Check the db/console and try again.")); return; } call.getSender() .sendMessage(Prism.messenger.playerSuccess("Valid connection found. Yay!")); call.getSender() .sendMessage(Prism.messenger.playerMsg("Restarting recordering tasks...")); plugin.actionRecorderTask(); } catch (final Exception e) { e.printStackTrace(); } finally { if (conn != null) try { conn.close(); } catch (final Exception ignored) { } ; } } return; } }