Clean up generics (and get rid of the type parameter for command meta data)
This commit is contained in:
parent
1a85251fc6
commit
ccd0e8ae0e
50 changed files with 577 additions and 596 deletions
|
|
@ -81,7 +81,7 @@ public final class CloudBrigadierManager<C, S> {
|
|||
? extends ArgumentType<?>>> mappers;
|
||||
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
||||
private final Supplier<CommandContext<C>> dummyContextProvider;
|
||||
private final CommandManager<C, ?> commandManager;
|
||||
private final CommandManager<C> commandManager;
|
||||
|
||||
/**
|
||||
* Create a new cloud brigadier manager
|
||||
|
|
@ -89,7 +89,7 @@ public final class CloudBrigadierManager<C, S> {
|
|||
* @param commandManager Command manager
|
||||
* @param dummyContextProvider Provider of dummy context for completions
|
||||
*/
|
||||
public CloudBrigadierManager(@Nonnull final CommandManager<C, ?> commandManager,
|
||||
public CloudBrigadierManager(@Nonnull final CommandManager<C> commandManager,
|
||||
@Nonnull final Supplier<CommandContext<C>>
|
||||
dummyContextProvider) {
|
||||
this.mappers = Maps.newHashMap();
|
||||
|
|
@ -184,14 +184,14 @@ public final class CloudBrigadierManager<C, S> {
|
|||
* Register a cloud-Brigadier mapping
|
||||
*
|
||||
* @param argumentType cloud argument type
|
||||
* @param mapper mapper function
|
||||
* @param <T> cloud argument value type
|
||||
* @param <K> cloud argument type
|
||||
* @param <O> Brigadier argument type value
|
||||
* @param mapper mapper function
|
||||
* @param <T> cloud argument value type
|
||||
* @param <K> cloud argument type
|
||||
* @param <O> Brigadier argument type value
|
||||
*/
|
||||
public <T, K extends CommandArgument<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType,
|
||||
@Nonnull final Function<? extends K,
|
||||
? extends ArgumentType<O>> mapper) {
|
||||
? extends ArgumentType<O>> mapper) {
|
||||
this.mappers.put(argumentType.getRawType(), mapper);
|
||||
}
|
||||
|
||||
|
|
@ -211,8 +211,8 @@ public final class CloudBrigadierManager<C, S> {
|
|||
*
|
||||
* @param argumentType cloud argument type
|
||||
* @param argument cloud argument
|
||||
* @param <T> cloud argument value type (generic)
|
||||
* @param <K> cloud argument type (generic)
|
||||
* @param <T> cloud argument value type (generic)
|
||||
* @param <K> cloud argument type (generic)
|
||||
* @return Brigadier argument type
|
||||
*/
|
||||
@Nullable
|
||||
|
|
@ -268,9 +268,9 @@ public final class CloudBrigadierManager<C, S> {
|
|||
}
|
||||
|
||||
private ArgumentBuilder<S, ?> constructCommandNode(@Nonnull final CommandTree.Node<CommandArgument<C, ?>> root,
|
||||
@Nonnull final BiPredicate<S, String> permissionChecker,
|
||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
||||
@Nonnull final SuggestionProvider<S> suggestionProvider) {
|
||||
@Nonnull final BiPredicate<S, String> permissionChecker,
|
||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
||||
@Nonnull final SuggestionProvider<S> suggestionProvider) {
|
||||
|
||||
ArgumentBuilder<S, ?> argumentBuilder;
|
||||
if (root.getValue() instanceof StaticArgument) {
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
|||
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandMetaBuilder;
|
||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import com.intellectualsites.commands.paper.PaperCommandManager;
|
||||
import com.intellectualsites.commands.bukkit.parsers.WorldArgument;
|
||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import com.intellectualsites.commands.paper.PaperCommandManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
|
|
@ -54,7 +54,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
|
@ -68,46 +67,43 @@ public final class BukkitTest extends JavaPlugin {
|
|||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
final PaperCommandManager<CommandSender> mgr = new PaperCommandManager<>(
|
||||
final CommandManager<CommandSender> mgr = new PaperCommandManager<>(
|
||||
this,
|
||||
CommandExecutionCoordinator
|
||||
.simpleCoordinator(),
|
||||
CommandExecutionCoordinator
|
||||
.simpleCoordinator(),
|
||||
Function.identity(),
|
||||
Function.identity()
|
||||
);
|
||||
final AnnotationParser<CommandSender, BukkitCommandMeta> annotationParser
|
||||
final AnnotationParser<CommandSender> annotationParser
|
||||
= new AnnotationParser<>(mgr, CommandSender.class, p ->
|
||||
BukkitCommandMetaBuilder.builder().withDescription(p.get(StandardParameters.DESCRIPTION,
|
||||
"No description")).build());
|
||||
annotationParser.parse(this);
|
||||
mgr.registerBrigadier();
|
||||
mgr.command(mgr.commandBuilder("gamemode",
|
||||
Collections.singleton("gajmöde"),
|
||||
BukkitCommandMetaBuilder.builder()
|
||||
.withDescription("Your ugli")
|
||||
.build())
|
||||
//noinspection all
|
||||
((PaperCommandManager<CommandSender>) mgr).registerBrigadier();
|
||||
mgr.command(mgr.commandBuilder("gamemode", this.metaWithDescription("Your ugli"), "gajmöde")
|
||||
.argument(EnumArgument.required(GameMode.class, "gamemode"))
|
||||
.argument(StringArgument.<CommandSender>newBuilder("player")
|
||||
.withSuggestionsProvider((v1, v2) -> {
|
||||
final List<String> suggestions =
|
||||
new ArrayList<>(
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList()));
|
||||
suggestions.add("dog");
|
||||
suggestions.add("cat");
|
||||
return suggestions;
|
||||
}).build())
|
||||
.withSuggestionsProvider((v1, v2) -> {
|
||||
final List<String> suggestions =
|
||||
new ArrayList<>(
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList()));
|
||||
suggestions.add("dog");
|
||||
suggestions.add("cat");
|
||||
return suggestions;
|
||||
}).build())
|
||||
.handler(c -> ((Player) c.getSender())
|
||||
.setGameMode(c.<GameMode>get("gamemode")
|
||||
.orElse(GameMode.SURVIVAL)))
|
||||
.setGameMode(c.<GameMode>get("gamemode")
|
||||
.orElse(GameMode.SURVIVAL)))
|
||||
.build())
|
||||
.command(mgr.commandBuilder("kenny")
|
||||
.literal("sux")
|
||||
.argument(IntegerArgument
|
||||
.<CommandSender>newBuilder("perc")
|
||||
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
||||
.<CommandSender>newBuilder("perc")
|
||||
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
||||
.handler(context -> {
|
||||
((Player) context.getSender()).sendMessage(String.format(
|
||||
"Kenny sux %d%%",
|
||||
|
|
@ -182,4 +178,9 @@ public final class BukkitTest extends JavaPlugin {
|
|||
player.sendMessage(ChatColor.GOLD + "Your input was: " + ChatColor.AQUA + input + ChatColor.GREEN + " (" + number + ")");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private SimpleCommandMeta metaWithDescription(@Nonnull final String description) {
|
||||
return BukkitCommandMetaBuilder.builder().withDescription(description).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
|||
|
||||
private final CommandArgument<C, ?> command;
|
||||
private final BukkitCommandManager<C> bukkitCommandManager;
|
||||
private final Command<C, BukkitCommandMeta> cloudCommand;
|
||||
private final Command<C> cloudCommand;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
BukkitCommand(@Nonnull final Command<C, BukkitCommandMeta> cloudCommand,
|
||||
BukkitCommand(@Nonnull final Command<C> cloudCommand,
|
||||
@Nonnull final CommandArgument<C, ?> command,
|
||||
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
|
||||
super(command.getName(),
|
||||
|
|
@ -76,9 +76,9 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
|||
if (throwable != null) {
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid Command Syntax. "
|
||||
+ "Correct command syntax is: "
|
||||
+ ChatColor.GRAY + "/"
|
||||
+ ((InvalidSyntaxException) throwable).getCorrectSyntax());
|
||||
+ "Correct command syntax is: "
|
||||
+ ChatColor.GRAY + "/"
|
||||
+ ((InvalidSyntaxException) throwable).getCorrectSyntax());
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
commandSender.sendMessage(ChatColor.RED + throwable.getMessage());
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
|
|
@ -87,7 +87,8 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
|||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND);
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid Command Argument: "
|
||||
+ ChatColor.GRAY + throwable.getCause().getMessage());
|
||||
+ ChatColor.GRAY + throwable.getCause()
|
||||
.getMessage());
|
||||
} else {
|
||||
commandSender.sendMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ import java.util.function.Function;
|
|||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
public class BukkitCommandManager<C>
|
||||
extends CommandManager<C, BukkitCommandMeta> {
|
||||
public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||
|
||||
private final Plugin owningPlugin;
|
||||
|
||||
|
|
@ -61,8 +60,8 @@ public class BukkitCommandManager<C>
|
|||
* @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<CommandTree<C>,
|
||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
|
||||
throws Exception {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ public final class BukkitCommandMetaBuilder {
|
|||
*
|
||||
* @return Builder instance
|
||||
*/
|
||||
@Nonnull public static BuilderStage1 builder() {
|
||||
@Nonnull
|
||||
public static BuilderStage1 builder() {
|
||||
return new BuilderStage1();
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +54,8 @@ public final class BukkitCommandMetaBuilder {
|
|||
* @param description Command description
|
||||
* @return Builder instance
|
||||
*/
|
||||
@Nonnull public BuilderStage2 withDescription(@Nonnull final String description) {
|
||||
@Nonnull
|
||||
public BuilderStage2 withDescription(@Nonnull final String description) {
|
||||
return new BuilderStage2(description);
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +75,8 @@ public final class BukkitCommandMetaBuilder {
|
|||
*
|
||||
* @return Meta instance
|
||||
*/
|
||||
@Nonnull public BukkitCommandMeta build() {
|
||||
@Nonnull
|
||||
public BukkitCommandMeta build() {
|
||||
return new BukkitCommandMeta(CommandMeta.simple().with("description", this.description).build());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
||||
final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHandler {
|
||||
|
||||
private final Map<CommandArgument<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHan
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(@Nonnull final Command<?, BukkitCommandMeta> command) {
|
||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
||||
/* We only care about the root command argument */
|
||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||
|
|
@ -75,7 +75,7 @@ final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHan
|
|||
label = commandArgument.getName();
|
||||
}
|
||||
@SuppressWarnings("unchecked") final BukkitCommand<C> bukkitCommand = new BukkitCommand<>(
|
||||
(Command<C, BukkitCommandMeta>) command,
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.bukkitCommandManager);
|
||||
this.registeredCommands.put(commandArgument, bukkitCommand);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
|||
*
|
||||
* @param name Argument name
|
||||
* @param material Default value
|
||||
* @param <C> Command sender type
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
@Nonnull
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
|||
*/
|
||||
@Nonnull
|
||||
public static <C> CommandArgument<C, World> optional(@Nonnull final String name,
|
||||
@Nonnull final String defaultValue) {
|
||||
@Nonnull final String defaultValue) {
|
||||
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import com.intellectualsites.commands.exceptions.InvalidCommandSenderException;
|
|||
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
|
||||
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
||||
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
|
@ -42,16 +41,16 @@ import javax.annotation.Nonnull;
|
|||
public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||
|
||||
private static final String MESSAGE_NO_PERMS =
|
||||
"I'm sorry, but you do not have permission to perform this command. "
|
||||
+ "Please contact the server administrators if you believe that this is in error.";
|
||||
"I'm sorry, but you do not have permission to perform this command. "
|
||||
+ "Please contact the server administrators if you believe that this is in error.";
|
||||
private static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Type \"/help\" for help.";
|
||||
|
||||
private final BungeeCommandManager<C> bungeeCommandManager;
|
||||
private final CommandArgument<C, ?> command;
|
||||
private final com.intellectualsites.commands.Command<C, SimpleCommandMeta> cloudCommand;
|
||||
private final com.intellectualsites.commands.Command<C> cloudCommand;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
BungeeCommand(@Nonnull final com.intellectualsites.commands.Command<C, SimpleCommandMeta> cloudCommand,
|
||||
BungeeCommand(@Nonnull final com.intellectualsites.commands.Command<C> cloudCommand,
|
||||
@Nonnull final CommandArgument<C, ?> command,
|
||||
@Nonnull final BungeeCommandManager<C> bungeeCommandManager) {
|
||||
super(command.getName(),
|
||||
|
|
@ -71,41 +70,41 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
|||
}
|
||||
this.bungeeCommandManager.executeCommand(this.bungeeCommandManager.getCommandSenderMapper().apply(commandSender),
|
||||
builder.toString())
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
commandSender.sendMessage(
|
||||
new ComponentBuilder("Invalid Command Syntax. Correct command syntax is: ")
|
||||
.color(ChatColor.RED)
|
||||
.append("/")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(((InvalidSyntaxException) throwable).getCorrectSyntax())
|
||||
.color(ChatColor.GRAY)
|
||||
.create()
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage())
|
||||
.color(ChatColor.RED)
|
||||
.create());
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(MESSAGE_NO_PERMS)
|
||||
.color(ChatColor.WHITE)
|
||||
.create());
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(MESSAGE_UNKNOWN_COMMAND)
|
||||
.color(ChatColor.WHITE)
|
||||
.create());
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
commandSender.sendMessage(new ComponentBuilder("Invalid Command Argument: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(throwable.getCause().getMessage())
|
||||
.create());
|
||||
} else {
|
||||
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage()).create());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}));
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
commandSender.sendMessage(
|
||||
new ComponentBuilder("Invalid Command Syntax. Correct command syntax is: ")
|
||||
.color(ChatColor.RED)
|
||||
.append("/")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(((InvalidSyntaxException) throwable).getCorrectSyntax())
|
||||
.color(ChatColor.GRAY)
|
||||
.create()
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage())
|
||||
.color(ChatColor.RED)
|
||||
.create());
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(MESSAGE_NO_PERMS)
|
||||
.color(ChatColor.WHITE)
|
||||
.create());
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
commandSender.sendMessage(new ComponentBuilder(MESSAGE_UNKNOWN_COMMAND)
|
||||
.color(ChatColor.WHITE)
|
||||
.create());
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
commandSender.sendMessage(new ComponentBuilder("Invalid Command Argument: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(throwable.getCause().getMessage())
|
||||
.create());
|
||||
} else {
|
||||
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage()).create());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BungeeCommandManager<C> extends CommandManager<C, SimpleCommandMeta> {
|
||||
public class BungeeCommandManager<C> extends CommandManager<C> {
|
||||
|
||||
private final Plugin owningPlugin;
|
||||
private final Function<CommandSender, C> commandSenderMapper;
|
||||
|
|
@ -49,8 +49,8 @@ public class BungeeCommandManager<C> extends CommandManager<C, SimpleCommandMeta
|
|||
* @throws Exception If the construction of the manager fails
|
||||
*/
|
||||
public BungeeCommandManager(@Nonnull final Plugin owningPlugin,
|
||||
@Nonnull final Function<CommandTree<C, SimpleCommandMeta>,
|
||||
CommandExecutionCoordinator<C, SimpleCommandMeta>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandTree<C>,
|
||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
|
||||
throws Exception {
|
||||
|
|
@ -63,7 +63,7 @@ public class BungeeCommandManager<C> extends CommandManager<C, SimpleCommandMeta
|
|||
|
||||
@Override
|
||||
public final boolean hasPermission(@Nonnull final C sender,
|
||||
@Nonnull final String permission) {
|
||||
@Nonnull final String permission) {
|
||||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,14 +26,12 @@ package com.intellectualsites.commands.bungee;
|
|||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class BungeePluginRegistrationHandler<C> implements
|
||||
CommandRegistrationHandler<SimpleCommandMeta> {
|
||||
final class BungeePluginRegistrationHandler<C> implements CommandRegistrationHandler {
|
||||
|
||||
private final Map<CommandArgument<?, ?>, net.md_5.bungee.api.plugin.Command> registeredCommands = new HashMap<>();
|
||||
|
||||
|
|
@ -47,19 +45,19 @@ final class BungeePluginRegistrationHandler<C> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(@Nonnull final Command<?, SimpleCommandMeta> command) {
|
||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
||||
/* We only care about the root command argument */
|
||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked") final BungeeCommand<C> bungeeCommand = new BungeeCommand<>(
|
||||
(Command<C, SimpleCommandMeta>) command,
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.bungeeCommandManager);
|
||||
this.registeredCommands.put(commandArgument, bungeeCommand);
|
||||
this.bungeeCommandManager.getOwningPlugin().getProxy().getPluginManager()
|
||||
.registerCommand(this.bungeeCommandManager.getOwningPlugin(), bungeeCommand);
|
||||
.registerCommand(this.bungeeCommandManager.getOwningPlugin(), bungeeCommand);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@ package com.intellectualsites.commands.paper;
|
|||
|
||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
|
||||
import com.intellectualsites.commands.CommandTree;
|
||||
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
|
||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -52,8 +51,9 @@ class PaperBrigadierListener<C> implements Listener {
|
|||
PaperBrigadierListener(@Nonnull final PaperCommandManager<C> paperCommandManager) throws Exception {
|
||||
this.paperCommandManager = paperCommandManager;
|
||||
this.brigadierManager = new CloudBrigadierManager<>(this.paperCommandManager,
|
||||
() -> new CommandContext<>(this.paperCommandManager.getCommandSenderMapper()
|
||||
.apply(Bukkit.getConsoleSender())));
|
||||
() -> new CommandContext<>(
|
||||
this.paperCommandManager.getCommandSenderMapper()
|
||||
.apply(Bukkit.getConsoleSender())));
|
||||
/* Register default mappings */
|
||||
final String version = Bukkit.getServer().getClass().getPackage().getName();
|
||||
this.nmsVersion = version.substring(version.lastIndexOf(".") + 1);
|
||||
|
|
@ -112,7 +112,7 @@ class PaperBrigadierListener<C> implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||
final CommandTree<C, BukkitCommandMeta> commandTree = this.paperCommandManager.getCommandTree();
|
||||
final CommandTree<C> commandTree = this.paperCommandManager.getCommandTree();
|
||||
final CommandTree.Node<CommandArgument<C, ?>> node = commandTree.getNamedNode(event.getCommandLabel());
|
||||
if (node == null) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@
|
|||
//
|
||||
package com.intellectualsites.commands.paper;
|
||||
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandManager;
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
|
||||
import com.intellectualsites.commands.CommandTree;
|
||||
import com.intellectualsites.commands.bukkit.BukkitCommandManager;
|
||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -46,15 +45,15 @@ public class PaperCommandManager<C>
|
|||
/**
|
||||
* Construct a new Paper 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 PaperCommandManager(@Nonnull final Plugin owningPlugin,
|
||||
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
||||
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandTree<C>,
|
||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper) throws
|
||||
Exception {
|
||||
|
|
@ -65,7 +64,7 @@ public class PaperCommandManager<C>
|
|||
* Attempt to register the Brigadier mapper, and return it.
|
||||
*
|
||||
* @return {@link PaperBrigadierListener} instance, if it could be created. If it cannot
|
||||
* be created {@code null} is returned
|
||||
* be created {@code null} is returned
|
||||
*/
|
||||
@Nullable
|
||||
public PaperBrigadierListener<C> registerBrigadier() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue