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
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue