public AsyncCommandHelper sendMessageAfterDelay(String message) { FutureProgressListener.addProgressListener(future, sender, format(message)); return this; }
public static <V> MessageFutureCallback<V> createRegionLoadCallback(ExceptionConverter exceptionConverter, Actor sender) { return new Builder(sender) .exceptionConverter(exceptionConverter) .onSuccess("Successfully load the region data.") .build(); }
public AsyncCommandHelper thenRespondWith(String success, String failure) { // Send a response message Futures.addCallback( future, new MessageFutureCallback.Builder(sender) .exceptionConverter(exceptionConverter) .onSuccess(format(success)) .onFailure(format(failure)) .build()); return this; }
public AsyncCommandHelper forRegionDataSave(World world, boolean silent) { checkNotNull(world); formatUsing(world.getName()); registerWithSupervisor("Saving region data for '%s'"); if (silent) { thenTellErrorsOnly("Failed to save regions '%s'"); } else { sendMessageAfterDelay("(Please wait... saving the region data for '%s')"); thenRespondWith( "Saved region data for '%s'", "Failed to load regions '%s'"); } return this; }
/** * Submit data to a pastebin service and inform the sender of * success or failure. * * @param supervisor The supervisor instance * @param sender The sender * @param content The content * @param successMessage The message, formatted with {@link String#format(String, Object...)} on success */ public static void pastebin(Supervisor supervisor, final Actor sender, String content, final String successMessage, final ExceptionConverter exceptionConverter) { ListenableFuture<URL> future = new EngineHubPaste().paste(content); AsyncCommandHelper.wrap(future, supervisor, sender, exceptionConverter) .registerWithSupervisor("Submitting content to a pastebin service...") .sendMessageAfterDelay("(Please wait... sending output to pastebin...)"); Futures.addCallback(future, new FutureCallback<URL>() { @Override public void onSuccess(URL url) { sender.print(String.format(successMessage, url)); } @Override public void onFailure(Throwable throwable) { LOGGER.log(Level.WARNING, "Failed to submit pastebin", throwable); sender.printError("Failed to submit to a pastebin. Please see console for the error."); } }); }
public void fromCommand(CommandContext args) { or(Flags.FRIENDLY , args.hasFlag('f')); // No permission check here. Flags will instead be filtered by the subsequent calls. or(Flags.PETS , args.hasFlag('p'), "worldedit.butcher.pets"); or(Flags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs"); or(Flags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems"); or(Flags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals"); or(Flags.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient"); or(Flags.TAGGED , args.hasFlag('t'), "worldedit.butcher.tagged"); or(Flags.ARMOR_STAND , args.hasFlag('r'), "worldedit.butcher.armorstands"); or(Flags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); }
public static AsyncCommandHelper wrap(ListenableFuture<?> future, Supervisor supervisor, Actor sender, ExceptionConverter exceptionConverter) { return new AsyncCommandHelper(future, supervisor, sender, exceptionConverter); }
@Override public void run() { task.cancel(); }
public <V> MessageFutureCallback<V> build() { checkNotNull(exceptionConverter); return new MessageFutureCallback<>(exceptionConverter, sender, success, failure); } }
public FutureProgressListener(Actor sender, String message) { checkNotNull(sender); checkNotNull(message); task = new MessageTimerTask(sender, message); timer.schedule(task, MESSAGE_DELAY); }
public void fromString(String str) throws CommandException { Type type = Type.findByPattern(str); if (type != null) { this.type = type; } else { throw new CommandException("Acceptable types: projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all"); } }
public static void addProgressListener(ListenableFuture<?> future, Actor sender, String message) { future.addListener(new FutureProgressListener(sender, message), MoreExecutors.directExecutor()); }
public EntityFunction createFunction() { final Type type = this.type; checkNotNull(type, "type can't be null"); return entity -> { EntityProperties registryType = entity.getFacet(EntityProperties.class); if (registryType != null) { if (type.matches(registryType)) { entity.remove(); return true; } } return false; }; }
public AsyncCommandHelper registerWithSupervisor(String description) { supervisor.monitor( FutureForwardingTask.create( future, format(description), sender)); return this; }
public AsyncCommandHelper thenTellErrorsOnly(String failure) { // Send a response message Futures.addCallback( future, new MessageFutureCallback.Builder(sender) .exceptionConverter(exceptionConverter) .onFailure(format(failure)) .build()); return this; }
public AsyncCommandHelper forRegionDataLoad(World world, boolean silent) { checkNotNull(world); formatUsing(world.getName()); registerWithSupervisor("Loading region data for '%s'"); if (silent) { thenTellErrorsOnly("Failed to load regions '%s'"); } else { sendMessageAfterDelay("(Please wait... loading the region data for '%s')"); thenRespondWith( "Loaded region data for '%s'", "Failed to load regions '%s'"); } return this; }
public static <V> MessageFutureCallback<V> createRegionSaveCallback(ExceptionConverter exceptionConverter, Actor sender) { return new Builder(sender) .exceptionConverter(exceptionConverter) .onSuccess("Successfully saved the region data.") .build(); }
public void or(int flag, boolean on, String permission) { or(flag, on); if ((flags & flag) != 0 && !player.hasPermission(permission)) { flags &= ~flag; } }