Get rid of the command sender interface entirely
This commit is contained in:
parent
8b0a650b48
commit
4cbbee7db0
57 changed files with 192 additions and 301 deletions
|
|
@ -32,7 +32,7 @@ import org.bukkit.plugin.Plugin;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
final class BukkitCommand<C extends com.intellectualsites.commands.sender.CommandSender>
|
||||
final class BukkitCommand<C>
|
||||
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
||||
|
||||
private final CommandArgument<C, ?> command;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
package com.intellectualsites.commands;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.intellectualsites.commands.sender.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
|
@ -33,12 +32,12 @@ import javax.annotation.Nonnull;
|
|||
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public abstract class BukkitCommandSender implements CommandSender {
|
||||
public abstract class BukkitCommandSender {
|
||||
|
||||
private final org.bukkit.command.CommandSender internalSender;
|
||||
|
||||
/**
|
||||
* Create a new command sender from a Bukkit {@link CommandSender}
|
||||
* Create a new command sender from a Bukkit {@link org.bukkit.command.CommandSender}
|
||||
*
|
||||
* @param internalSender Bukkit command sender
|
||||
*/
|
||||
|
|
@ -68,7 +67,7 @@ public abstract class BukkitCommandSender implements CommandSender {
|
|||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link BukkitCommandSender} from a Bukkit {@link CommandSender}
|
||||
* Construct a new {@link BukkitCommandSender} from a Bukkit {@link org.bukkit.command.CommandSender}
|
||||
*
|
||||
* @param sender Bukkit command sender
|
||||
* @return Constructed command sender
|
||||
|
|
@ -124,11 +123,6 @@ public abstract class BukkitCommandSender implements CommandSender {
|
|||
@Nonnull
|
||||
public abstract Player asPlayer();
|
||||
|
||||
@Override
|
||||
public final boolean hasPermission(@Nonnull final String permission) {
|
||||
return this.internalSender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the command sender
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ package com.intellectualsites.commands;
|
|||
|
||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||
import com.intellectualsites.commands.sender.CommandSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
|
@ -37,7 +36,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class BukkitPluginRegistrationHandler<C extends CommandSender> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
||||
final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
||||
|
||||
private final Map<CommandArgument<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
|||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.sender.CommandSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ import java.util.stream.Collectors;
|
|||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
public class WorldArgument<C extends CommandSender> extends CommandArgument<C, World> {
|
||||
public class WorldArgument<C> extends CommandArgument<C, World> {
|
||||
|
||||
protected WorldArgument(final boolean required,
|
||||
@Nonnull final String name,
|
||||
|
|
@ -57,7 +56,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
|||
* @return Created builder
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C extends CommandSender> CommandArgument.Builder<C, World> newBuilder(@Nonnull final String name) {
|
||||
public static <C> CommandArgument.Builder<C, World> newBuilder(@Nonnull final String name) {
|
||||
return new WorldArgument.Builder<>(name);
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
|||
* @return Created argument
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C extends CommandSender> CommandArgument<C, World> required(@Nonnull final String name) {
|
||||
public static <C> CommandArgument<C, World> required(@Nonnull final String name) {
|
||||
return WorldArgument.<C>newBuilder(name).asRequired().build();
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +80,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
|||
* @return Created argument
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name) {
|
||||
public static <C> CommandArgument<C, World> optional(@Nonnull final String name) {
|
||||
return WorldArgument.<C>newBuilder(name).asOptional().build();
|
||||
}
|
||||
|
||||
|
|
@ -94,13 +93,13 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
|||
* @return Created argument
|
||||
*/
|
||||
@Nonnull
|
||||
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name,
|
||||
public static <C> CommandArgument<C, World> optional(@Nonnull final String name,
|
||||
@Nonnull final String defaultValue) {
|
||||
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, World> {
|
||||
public static final class Builder<C> extends CommandArgument.Builder<C, World> {
|
||||
|
||||
protected Builder(@Nonnull final String name) {
|
||||
super(World.class, name);
|
||||
|
|
@ -114,7 +113,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
|||
}
|
||||
|
||||
|
||||
public static final class WorldParser<C extends CommandSender> implements ArgumentParser<C, World> {
|
||||
public static final class WorldParser<C> implements ArgumentParser<C, World> {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue