minecraft-extras: Add AudienceProvider.nativeAudience and MinecraftHelp.createNative convenience methods for sender types which are Audiences.
This commit is contained in:
parent
c78c4aba08
commit
5d460e9f3a
4 changed files with 89 additions and 3 deletions
|
|
@ -45,4 +45,16 @@ public interface AudienceProvider<C> extends Function<@NonNull C, @NonNull Audie
|
|||
@Override
|
||||
@NonNull Audience apply(@NonNull C sender);
|
||||
|
||||
/**
|
||||
* Get an audience provider for sender types which are already an {@link Audience}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return native audience provider
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <C extends Audience> AudienceProvider<C> nativeAudience() {
|
||||
return (AudienceProvider<C>) NativeAudienceProvider.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,8 +103,29 @@ public final class MinecraftHelp<C> {
|
|||
private int headerFooterLength = DEFAULT_HEADER_FOOTER_LENGTH;
|
||||
private int maxResultsPerPage = DEFAULT_MAX_RESULTS_PER_PAGE;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Minecraft help instance
|
||||
* Construct a new Minecraft help instance for a sender type which is an {@link Audience}.
|
||||
*
|
||||
* @param commandPrefix Command that was used to trigger the help menu. Used to help insertion generation
|
||||
* @param commandManager command manager
|
||||
* @param <C> sender type extending {@link Audience}
|
||||
* @return new MinecraftHelp instance
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static <C extends Audience> MinecraftHelp<C> createNative(
|
||||
final @NonNull String commandPrefix,
|
||||
final @NonNull CommandManager<C> commandManager
|
||||
) {
|
||||
return new MinecraftHelp<>(
|
||||
commandPrefix,
|
||||
AudienceProvider.nativeAudience(),
|
||||
commandManager
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Minecraft help instance.
|
||||
*
|
||||
* @param commandPrefix Command that was used to trigger the help menu. Used to help insertion generation
|
||||
* @param audienceProvider Provider that maps the command sender type to {@link Audience}
|
||||
|
|
@ -680,8 +701,8 @@ public final class MinecraftHelp<C> {
|
|||
* Creates a component from a command sender, key, and arguments
|
||||
*
|
||||
* @param sender command sender
|
||||
* @param key message key (constants in {@link MinecraftHelp}
|
||||
* @param args args
|
||||
* @param key message key (constants in {@link MinecraftHelp}
|
||||
* @param args args
|
||||
* @return component
|
||||
*/
|
||||
@NonNull Component provide(@NonNull C sender, @NonNull String key, @NonNull String... args);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.minecraft.extras;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
final class NativeAudienceProvider<C extends Audience> implements AudienceProvider<C> {
|
||||
|
||||
static final NativeAudienceProvider<?> INSTANCE = new NativeAudienceProvider<>();
|
||||
|
||||
private NativeAudienceProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Audience apply(@NonNull final C sender) {
|
||||
return sender;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue