diff --git a/cloud-core/src/main/java/cloud/commandframework/Command.java b/cloud-core/src/main/java/cloud/commandframework/Command.java index fe880a39..6b99550a 100644 --- a/cloud-core/src/main/java/cloud/commandframework/Command.java +++ b/cloud-core/src/main/java/cloud/commandframework/Command.java @@ -466,6 +466,20 @@ public class Command { return this.commandPermission; } + /** + * Applies the provided {@link Applicable} to this {@link Builder}, and returns the result. + * + * @param applicable operation + * @return operation result + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + public @NonNull Builder<@NonNull C> apply( + final @NonNull Applicable<@NonNull C> applicable + ) { + return applicable.applyToCommandBuilder(this); + } + /** * Add command meta to the internal command meta map * @@ -1199,5 +1213,27 @@ public class Command { this.commandMeta ); } + + /** + * Essentially a {@link java.util.function.UnaryOperator} for {@link Builder}, + * but as a separate interface to avoid conflicts. + * + * @param sender type + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + @FunctionalInterface + public interface Applicable { + + /** + * Accepts a {@link Builder} and returns either the same or a modified {@link Builder} instance. + * + * @param builder builder + * @return possibly modified builder + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + @NonNull Builder applyToCommandBuilder(@NonNull Builder builder); + } } }