bukkit/paper/velocity: Add convenience methods for constructing command managers using native platform sender types

This commit is contained in:
jmp 2021-03-18 20:37:04 -07:00 committed by Jason
parent 5d460e9f3a
commit 0722bf6ead
3 changed files with 71 additions and 3 deletions

View file

@ -37,8 +37,8 @@ import cloud.commandframework.bukkit.parsers.OfflinePlayerArgument;
import cloud.commandframework.bukkit.parsers.PlayerArgument;
import cloud.commandframework.bukkit.parsers.WorldArgument;
import cloud.commandframework.bukkit.parsers.location.Location2D;
import cloud.commandframework.bukkit.parsers.location.LocationArgument;
import cloud.commandframework.bukkit.parsers.location.Location2DArgument;
import cloud.commandframework.bukkit.parsers.location.LocationArgument;
import cloud.commandframework.bukkit.parsers.selector.MultipleEntitySelectorArgument;
import cloud.commandframework.bukkit.parsers.selector.MultiplePlayerSelectorArgument;
import cloud.commandframework.bukkit.parsers.selector.SingleEntitySelectorArgument;
@ -62,6 +62,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.EnumSet;
import java.util.Set;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -117,8 +118,8 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
@SuppressWarnings("unchecked")
public BukkitCommandManager(
final @NonNull Plugin owningPlugin,
final @NonNull Function<@NonNull CommandTree<C>,
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull CommandTree<@NonNull C>,
@NonNull CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper
)
@ -195,6 +196,29 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
this.setCaptionRegistry(new BukkitCaptionRegistryFactory<C>().create());
}
/**
* Create a command manager using Bukkit's {@link CommandSender} as the sender type.
*
* @param owningPlugin plugin owning the command manager
* @param commandExecutionCoordinator execution coordinator instance
* @return a new command manager
* @throws Exception If the construction of the manager fails
* @see #BukkitCommandManager(Plugin, Function, Function, Function) for a more thorough explanation
* @since 1.5.0
*/
public static @NonNull BukkitCommandManager<@NonNull CommandSender> createNative(
final @NonNull Plugin owningPlugin,
final @NonNull Function<@NonNull CommandTree<@NonNull CommandSender>,
@NonNull CommandExecutionCoordinator<@NonNull CommandSender>> commandExecutionCoordinator
) throws Exception {
return new BukkitCommandManager<>(
owningPlugin,
commandExecutionCoordinator,
UnaryOperator.identity(),
UnaryOperator.identity()
);
}
/**
* Create a new task recipe. This can be used to create chains of synchronous/asynchronous method calls
*

View file

@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.function.Function;
import java.util.function.UnaryOperator;
/**
* Paper command manager that extends {@link BukkitCommandManager}
@ -88,6 +89,29 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
super(owningPlugin, commandExecutionCoordinator, commandSenderMapper, backwardsCommandSenderMapper);
}
/**
* Create a command manager using Bukkit's {@link CommandSender} as the sender type.
*
* @param owningPlugin plugin owning the command manager
* @param commandExecutionCoordinator execution coordinator instance
* @return a new command manager
* @throws Exception If the construction of the manager fails
* @see #PaperCommandManager(Plugin, Function, Function, Function) for a more thorough explanation
* @since 1.5.0
*/
public static @NonNull PaperCommandManager<@NonNull CommandSender> createNative(
final @NonNull Plugin owningPlugin,
final @NonNull Function<@NonNull CommandTree<@NonNull CommandSender>,
@NonNull CommandExecutionCoordinator<@NonNull CommandSender>> commandExecutionCoordinator
) throws Exception {
return new PaperCommandManager<>(
owningPlugin,
commandExecutionCoordinator,
UnaryOperator.identity(),
UnaryOperator.identity()
);
}
/**
* Register Brigadier mappings using the native paper events
*

View file

@ -33,6 +33,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.lang.reflect.Type;
import java.util.function.Function;
import java.util.function.UnaryOperator;
/**
* Injection module that allows for {@link VelocityCommandManager} to be injectable
@ -67,6 +68,25 @@ public final class CloudInjectionModule<C> extends AbstractModule {
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
}
/**
* Create a new child injection module using Velocity's {@link CommandSource} as the sender type.
*
* @param commandExecutionCoordinator Command execution coordinator
* @return new injection module
* @since 1.5.0
*/
public static @NonNull CloudInjectionModule<@NonNull CommandSource> createNative(
final @NonNull Function<@NonNull CommandTree<@NonNull CommandSource>,
@NonNull CommandExecutionCoordinator<@NonNull CommandSource>> commandExecutionCoordinator
) {
return new CloudInjectionModule<>(
CommandSource.class,
commandExecutionCoordinator,
UnaryOperator.identity(),
UnaryOperator.identity()
);
}
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
protected void configure() {