Get rid of the command sender interface entirely

This commit is contained in:
Alexander Söderberg 2020-09-17 13:35:16 +02:00
parent 8b0a650b48
commit 4cbbee7db0
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
57 changed files with 192 additions and 301 deletions

View file

@ -39,29 +39,34 @@ import java.util.function.Function;
*
* @param <C> Command sender type
*/
public class BukkitCommandManager<C extends com.intellectualsites.commands.sender.CommandSender>
public class BukkitCommandManager<C>
extends CommandManager<C, BukkitCommandMeta> {
private final Plugin owningPlugin;
private final Function<CommandSender, C> commandSenderMapper;
private final Function<C, CommandSender> backwardsCommandSenderMapper;
/**
* 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
* @param owningPlugin Plugin that is constructing the manager
* @param commandExecutionCoordinator Coordinator provider
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
* @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,
@Nonnull final Function<CommandSender, C> commandSenderMapper)
@Nonnull final Function<CommandSender, C> commandSenderMapper,
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
throws Exception {
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
this.owningPlugin = owningPlugin;
this.commandSenderMapper = commandSenderMapper;
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
/* Register Bukkit parsers */
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>());
@ -93,4 +98,9 @@ public class BukkitCommandManager<C extends com.intellectualsites.commands.sende
return this.commandSenderMapper;
}
@Override
public final boolean hasPermission(@Nonnull final C sender, @Nonnull final String permission) {
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
}
}