use of me.botsko.prism.appliers.PreviewSession in project Prism-Bukkit by prism.
the class PreviewCommand method handle.
@Override
public void handle(final CallInfo call) {
final Audience audience = Prism.getAudiences().sender(call.getPlayer());
if (call.getArgs().length >= 2) {
if (call.getArg(1).equalsIgnoreCase("apply")) {
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
final PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName());
previewSession.getPreviewer().apply_preview();
plugin.playerActivePreviews.remove(call.getPlayer().getName());
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("You have no preview pending."));
}
return;
}
if (call.getArg(1).equalsIgnoreCase("cancel")) {
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
final PreviewSession previewSession = plugin.playerActivePreviews.get(call.getPlayer().getName());
previewSession.getPreviewer().cancel_preview();
plugin.playerActivePreviews.remove(call.getPlayer().getName());
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-none-pending")));
}
return;
}
// Ensure no current preview is waiting
if (plugin.playerActivePreviews.containsKey(call.getPlayer().getName())) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-pending")));
return;
}
if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rb") || call.getArg(1).equalsIgnoreCase("rs")) {
final 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")) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("preview-worldedit-unsupported")));
return;
}
StringBuilder defaultsReminder = checkIfDefaultUsed(parameters);
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("queryparameter.defaults.prefix", defaultsReminder.toString())));
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// Perform preview
final ActionsQuery aq = new ActionsQuery(plugin);
final QueryResult results = aq.lookup(parameters, call.getPlayer());
// Rollback
if (call.getArg(1).equalsIgnoreCase("rollback") || call.getArg(1).equalsIgnoreCase("rb")) {
handleRollBack(call, parameters, results, audience);
// todo remove debug
assert (parameters.getProcessType() == PrismProcessType.ROLLBACK);
}
// Restore
if (call.getArg(1).equalsIgnoreCase("restore") || call.getArg(1).equalsIgnoreCase("rs")) {
handleRestore(call, parameters, results, audience);
// todo remove debug
assert (parameters.getProcessType() == PrismProcessType.RESTORE);
}
});
return;
}
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("invalid-command")));
}
}
use of me.botsko.prism.appliers.PreviewSession in project Prism-Bukkit by prism.
the class Prism method endExpiredPreviews.
/**
* Clears expired Previews.
*/
@SuppressWarnings("WeakerAccess")
public void endExpiredPreviews() {
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
final java.util.Date date = new java.util.Date();
for (final Entry<String, PreviewSession> query : playerActivePreviews.entrySet()) {
final PreviewSession result = query.getValue();
final long diff = (date.getTime() - result.getQueryTime()) / 1000;
if (diff >= 60) {
// inform player
final Player player = result.getPlayer();
if (player.isOnline()) {
Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("cancel-preview-forgotten")));
}
playerActivePreviews.remove(query.getKey());
}
}
}, 1200L, 1200L);
}
Aggregations