Don't require BukkitCommandManager to use BukkitCommandSender
This commit is contained in:
parent
d144c3ea8c
commit
d78d64329b
6 changed files with 84 additions and 37 deletions
|
|
@ -27,6 +27,7 @@ import com.google.common.reflect.TypeToken;
|
|||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import com.intellectualsites.commands.parsers.WorldComponent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
|
@ -35,25 +36,32 @@ import java.util.function.Function;
|
|||
/**
|
||||
* Command manager for the Bukkit platform, using {@link BukkitCommandSender} as the
|
||||
* command sender type
|
||||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
public class BukkitCommandManager<C extends BukkitCommandSender> extends CommandManager<C, BukkitCommandMeta> {
|
||||
public class BukkitCommandManager<C extends com.intellectualsites.commands.sender.CommandSender>
|
||||
extends CommandManager<C, BukkitCommandMeta> {
|
||||
|
||||
private final Plugin owningPlugin;
|
||||
private final Function<CommandSender, C> commandSenderMapper;
|
||||
|
||||
/**
|
||||
* Construct a new Bukkit command manager
|
||||
*
|
||||
* @param owningPlugin Plugin that is constructing the manager
|
||||
* @param commandExecutionCoordinator Coordinator provider
|
||||
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
||||
* @throws Exception If the construction of the manager fails
|
||||
*/
|
||||
public BukkitCommandManager(@Nonnull final Plugin owningPlugin,
|
||||
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
||||
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator)
|
||||
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandSender, C> commandSenderMapper)
|
||||
throws Exception {
|
||||
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler());
|
||||
((BukkitPluginRegistrationHandler) this.getCommandRegistrationHandler()).initialize(this);
|
||||
this.owningPlugin = owningPlugin;
|
||||
this.commandSenderMapper = commandSenderMapper;
|
||||
|
||||
/* Register Bukkit parsers */
|
||||
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldComponent.WorldParser<>());
|
||||
|
|
@ -80,4 +88,9 @@ public class BukkitCommandManager<C extends BukkitCommandSender> extends Command
|
|||
return BukkitCommandMetaBuilder.builder().withDescription("").build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
final Function<CommandSender, C> getCommandSenderMapper() {
|
||||
return this.commandSenderMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue