Add Command.Builder#apply (#409)

This commit is contained in:
Jason 2022-11-25 17:40:42 -07:00
parent a2ee9f043c
commit b19ec931cb

View file

@ -466,6 +466,20 @@ public class Command<C> {
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<C> {
this.commandMeta
);
}
/**
* Essentially a {@link java.util.function.UnaryOperator} for {@link Builder},
* but as a separate interface to avoid conflicts.
*
* @param <C> sender type
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
@FunctionalInterface
public interface Applicable<C> {
/**
* 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<C> applyToCommandBuilder(@NonNull Builder<C> builder);
}
}
}