Package revxrsal.commands.autocomplete
Interface SuggestionProviderFactory
- All Known Implementing Classes:
EntitySelectorResolver.SelectorSuggestionFactory
public interface SuggestionProviderFactory
Creates a
SuggestionProvider
for the given type of parameter. These are
most useful in the following cases:
- Creating a suggestion provider for only a specific type of parameters, for example those with a specific annotation
- Creating suggestion providers for a common interface or class
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface WithinRadius {
double value();
}
public final class WithinRadiusSuggestionFactory implements SuggestionProviderFactory {
@Override public @Nullable SuggestionProvider create(@NotNull CommandParameter parameter) {
if (parameter.getType() != Player.class) return null;
WithinRadius radius = parameter.getAnnotation(WithinRadius.class);
if (radius == null) return null;
return (args, sender, command) -> {
return ((BukkitCommandActor) actor).requirePlayer().getNearbyEntities(
radius.value(), radius.value(), radius.value()
)
.stream().filter(entity -> entity instanceof Player)
.map(Player::getName).collect(Collectors.toList());
};
}
}
Note that SuggestionProviderFactory
ies must be registered
with AutoCompleter.registerSuggestionFactory(SuggestionProviderFactory)
-
Method Summary
Modifier and TypeMethodDescription@Nullable SuggestionProvider
createSuggestionProvider
(@NotNull CommandParameter parameter) Creates aSuggestionProvider
for the given parameter.static SuggestionProviderFactory
forHierarchyType
(Class<?> type, SuggestionProvider provider) Creates aSuggestionProviderFactory
that will return the same provider for all parameters that match or extend a specific typestatic SuggestionProviderFactory
forType
(Class<?> type, SuggestionProvider provider) Creates aSuggestionProviderFactory
that will return the same provider for all parameters that match a specific type
-
Method Details
-
createSuggestionProvider
@Nullable @Nullable SuggestionProvider createSuggestionProvider(@NotNull @NotNull CommandParameter parameter) Creates aSuggestionProvider
for the given parameter. If this parameter is not applicable,null
should be returned.- Parameters:
parameter
- Parameter to create for- Returns:
- The suggestion provider for the parameter, or
null
if not applicable.
-
forType
Creates aSuggestionProviderFactory
that will return the same provider for all parameters that match a specific type- Parameters:
type
- Type to check forprovider
- The provider to use- Returns:
- The provider factory
-
forHierarchyType
Creates aSuggestionProviderFactory
that will return the same provider for all parameters that match or extend a specific type- Parameters:
type
- Type to check forprovider
- The provider to use- Returns:
- The provider factory
-