Add Command.Builder#apply (#409)
This commit is contained in:
parent
a2ee9f043c
commit
b19ec931cb
1 changed files with 36 additions and 0 deletions
|
|
@ -466,6 +466,20 @@ public class Command<C> {
|
||||||
return this.commandPermission;
|
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
|
* Add command meta to the internal command meta map
|
||||||
*
|
*
|
||||||
|
|
@ -1199,5 +1213,27 @@ public class Command<C> {
|
||||||
this.commandMeta
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue