✨ Cleanup annotations and remove Cloud Brigs Pair (#32)
This commit is contained in:
parent
c3469706ab
commit
f1d4529276
10 changed files with 93 additions and 117 deletions
|
|
@ -58,14 +58,14 @@ public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onMessageReceived(final @NonNull MessageReceivedEvent event) {
|
public final void onMessageReceived(final @NonNull MessageReceivedEvent event) {
|
||||||
Message message = event.getMessage();
|
final Message message = event.getMessage();
|
||||||
C sender = commandManager.getCommandSenderMapper().apply(event);
|
final C sender = this.commandManager.getCommandSenderMapper().apply(event);
|
||||||
|
|
||||||
if (commandManager.getBotId() == event.getAuthor().getIdLong()) {
|
if (this.commandManager.getBotId() == event.getAuthor().getIdLong()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = commandManager.getPrefixMapper().apply(sender);
|
final String prefix = this.commandManager.getPrefixMapper().apply(sender);
|
||||||
String content = message.getContentRaw();
|
String content = message.getContentRaw();
|
||||||
|
|
||||||
if (!content.startsWith(prefix)) {
|
if (!content.startsWith(prefix)) {
|
||||||
|
|
@ -81,40 +81,40 @@ public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throwable instanceof InvalidSyntaxException) {
|
if (throwable instanceof InvalidSyntaxException) {
|
||||||
commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
InvalidSyntaxException.class,
|
InvalidSyntaxException.class,
|
||||||
(InvalidSyntaxException) throwable, (c, e) -> {
|
(InvalidSyntaxException) throwable, (c, e) -> {
|
||||||
sendMessage(event,
|
this.sendMessage(event,
|
||||||
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
|
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
|
||||||
.getCorrectSyntax());
|
.getCorrectSyntax());
|
||||||
});
|
});
|
||||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||||
commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
InvalidCommandSenderException.class,
|
InvalidCommandSenderException.class,
|
||||||
(InvalidCommandSenderException) throwable, (c, e) ->
|
(InvalidCommandSenderException) throwable, (c, e) ->
|
||||||
sendMessage(event, throwable.getMessage())
|
this.sendMessage(event, throwable.getMessage())
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof NoPermissionException) {
|
} else if (throwable instanceof NoPermissionException) {
|
||||||
commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
NoPermissionException.class,
|
NoPermissionException.class,
|
||||||
(NoPermissionException) throwable, (c, e) ->
|
(NoPermissionException) throwable, (c, e) ->
|
||||||
sendMessage(event, MESSAGE_NO_PERMS)
|
this.sendMessage(event, MESSAGE_NO_PERMS)
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof NoSuchCommandException) {
|
} else if (throwable instanceof NoSuchCommandException) {
|
||||||
commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
NoSuchCommandException.class,
|
NoSuchCommandException.class,
|
||||||
(NoSuchCommandException) throwable, (c, e) ->
|
(NoSuchCommandException) throwable, (c, e) ->
|
||||||
sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
|
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof ArgumentParseException) {
|
} else if (throwable instanceof ArgumentParseException) {
|
||||||
commandManager.handleException(sender, ArgumentParseException.class,
|
this.commandManager.handleException(sender, ArgumentParseException.class,
|
||||||
(ArgumentParseException) throwable, (c, e) -> {
|
(ArgumentParseException) throwable, (c, e) -> {
|
||||||
sendMessage(event,
|
this.sendMessage(event,
|
||||||
"Invalid Command Argument: " + throwable.getCause()
|
"Invalid Command Argument: " + throwable.getCause()
|
||||||
.getMessage());
|
.getMessage());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sendMessage(event, throwable.getMessage());
|
this.sendMessage(event, throwable.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ public class JDACommandManager<C> extends CommandManager<C> {
|
||||||
private final Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper;
|
private final Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* final
|
|
||||||
* Construct a new JDA Command Manager
|
* Construct a new JDA Command Manager
|
||||||
*
|
*
|
||||||
* @param jda JDA instance to register against
|
* @param jda JDA instance to register against
|
||||||
|
|
@ -86,7 +85,7 @@ public class JDACommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Prefix mapper
|
* @return Prefix mapper
|
||||||
*/
|
*/
|
||||||
public final @NonNull Function<C, String> getPrefixMapper() {
|
public final @NonNull Function<@NonNull C, @NonNull String> getPrefixMapper() {
|
||||||
return this.prefixMapper;
|
return this.prefixMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,13 +87,6 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
return UserArgument.<C>newBuilder(name, jda).asOptional().build();
|
return UserArgument.<C>newBuilder(name, jda).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum ParserMode {
|
|
||||||
MENTION,
|
|
||||||
ID,
|
|
||||||
NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the modes enabled on the parser
|
* Get the modes enabled on the parser
|
||||||
*
|
*
|
||||||
|
|
@ -103,6 +96,14 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
return modes;
|
return modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum ParserMode {
|
||||||
|
MENTION,
|
||||||
|
ID,
|
||||||
|
NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, User> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, User> {
|
||||||
private final JDA jda;
|
private final JDA jda;
|
||||||
private List<ParserMode> modes = new ArrayList<>();
|
private List<ParserMode> modes = new ArrayList<>();
|
||||||
|
|
@ -158,7 +159,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
if (modes.contains(ParserMode.MENTION)) {
|
if (modes.contains(ParserMode.MENTION)) {
|
||||||
if (input.endsWith(">")) {
|
if (input.endsWith(">")) {
|
||||||
String id;
|
final String id;
|
||||||
if (input.startsWith("<@!")) {
|
if (input.startsWith("<@!")) {
|
||||||
id = input.substring(3, input.length() - 1);
|
id = input.substring(3, input.length() - 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -166,10 +167,10 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ArgumentParseResult<User> result = userFromId(input, id);
|
final ArgumentParseResult<User> result = this.userFromId(input, id);
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
return result;
|
return result;
|
||||||
} catch (UserNotFoundParseException | NumberFormatException e) {
|
} catch (final UserNotFoundParseException | NumberFormatException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -177,16 +178,16 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
if (modes.contains(ParserMode.ID)) {
|
if (modes.contains(ParserMode.ID)) {
|
||||||
try {
|
try {
|
||||||
final ArgumentParseResult<User> result = userFromId(input, input);
|
final ArgumentParseResult<User> result = this.userFromId(input, input);
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
return result;
|
return result;
|
||||||
} catch (UserNotFoundParseException | NumberFormatException e) {
|
} catch (final UserNotFoundParseException | NumberFormatException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modes.contains(ParserMode.NAME)) {
|
if (modes.contains(ParserMode.NAME)) {
|
||||||
List<User> users = jda.getUsersByName(input, true);
|
final List<User> users = jda.getUsersByName(input, true);
|
||||||
|
|
||||||
if (users.size() == 0) {
|
if (users.size() == 0) {
|
||||||
exception = new UserNotFoundParseException(input);
|
exception = new UserNotFoundParseException(input);
|
||||||
|
|
@ -209,7 +210,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
private @NonNull ArgumentParseResult<User> userFromId(final @NonNull String input, final @NonNull String id)
|
private @NonNull ArgumentParseResult<User> userFromId(final @NonNull String input, final @NonNull String id)
|
||||||
throws UserNotFoundParseException, NumberFormatException {
|
throws UserNotFoundParseException, NumberFormatException {
|
||||||
User user = jda.getUserById(id);
|
final User user = jda.getUserById(id);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new UserNotFoundParseException(input);
|
throw new UserNotFoundParseException(input);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import cloud.commandframework.permission.CommandPermission;
|
import cloud.commandframework.permission.CommandPermission;
|
||||||
import cloud.commandframework.permission.Permission;
|
import cloud.commandframework.permission.Permission;
|
||||||
|
import cloud.commandframework.types.tuples.Pair;
|
||||||
import com.mojang.brigadier.LiteralMessage;
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
|
@ -83,8 +84,7 @@ import java.util.function.Supplier;
|
||||||
*/
|
*/
|
||||||
public final class CloudBrigadierManager<C, S> {
|
public final class CloudBrigadierManager<C, S> {
|
||||||
|
|
||||||
private final Map<Class<?>, cloud.commandframework.types.tuples.Pair<Function<? extends ArgumentParser<C, ?>,
|
private final Map<Class<?>, Pair<Function<? extends ArgumentParser<C, ?>, ? extends ArgumentType<?>>, Boolean>> mappers;
|
||||||
? extends ArgumentType<?>>, Boolean>> mappers;
|
|
||||||
private final Map<@NonNull Class<?>, @NonNull Supplier<@Nullable ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
private final Map<@NonNull Class<?>, @NonNull Supplier<@Nullable ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
||||||
private final Supplier<CommandContext<C>> dummyContextProvider;
|
private final Supplier<CommandContext<C>> dummyContextProvider;
|
||||||
private final CommandManager<C> commandManager;
|
private final CommandManager<C> commandManager;
|
||||||
|
|
@ -203,8 +203,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final boolean nativeSuggestions,
|
final boolean nativeSuggestions,
|
||||||
final @NonNull Function<@NonNull ? extends K,
|
final @NonNull Function<@NonNull ? extends K,
|
||||||
@NonNull ? extends ArgumentType<O>> mapper) {
|
@NonNull ? extends ArgumentType<O>> mapper) {
|
||||||
this.mappers.put(GenericTypeReflector.erase(argumentType.getType()),
|
this.mappers.put(GenericTypeReflector.erase(argumentType.getType()), Pair.of(mapper, nativeSuggestions));
|
||||||
cloud.commandframework.types.tuples.Pair.of(mapper, nativeSuggestions));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,12 +223,11 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final @NonNull TypeToken<T> argumentType,
|
final @NonNull TypeToken<T> argumentType,
|
||||||
final @NonNull K argument) {
|
final @NonNull K argument) {
|
||||||
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
||||||
final cloud.commandframework.types.tuples.Pair pair
|
final Pair pair = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
||||||
= this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
|
||||||
if (pair == null || pair.getFirst() == null) {
|
if (pair == null || pair.getFirst() == null) {
|
||||||
return this.createDefaultMapper(valueType, commandArgument);
|
return this.createDefaultMapper(valueType, commandArgument);
|
||||||
}
|
}
|
||||||
return new Pair<>((ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
|
return Pair.of((ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
|
||||||
(boolean) pair.getSecond());
|
(boolean) pair.getSecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,9 +243,9 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
defaultType = null;
|
defaultType = null;
|
||||||
}
|
}
|
||||||
if (defaultType != null) {
|
if (defaultType != null) {
|
||||||
return new Pair<>(argumentTypeSupplier.get(), true);
|
return Pair.of(argumentTypeSupplier.get(), true);
|
||||||
}
|
}
|
||||||
return new Pair<>(StringArgumentType.string(), false);
|
return Pair.of(StringArgumentType.string(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -339,10 +337,10 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(TypeToken.get((Class<?>) types[i]),
|
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(TypeToken.get((Class<?>) types[i]),
|
||||||
TypeToken.get(parser.getClass()),
|
TypeToken.get(parser.getClass()),
|
||||||
parser);
|
parser);
|
||||||
final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider;
|
final SuggestionProvider<S> provider = pair.getSecond() ? null : suggestionProvider;
|
||||||
|
|
||||||
final ArgumentBuilder<S, ?> fragmentBuilder = RequiredArgumentBuilder
|
final ArgumentBuilder<S, ?> fragmentBuilder = RequiredArgumentBuilder
|
||||||
.<S, Object>argument((String) names[i], (ArgumentType<Object>) pair.getLeft())
|
.<S, Object>argument((String) names[i], (ArgumentType<Object>) pair.getFirst())
|
||||||
.suggests(provider)
|
.suggests(provider)
|
||||||
.requires(sender -> permissionChecker.test(sender,
|
.requires(sender -> permissionChecker.test(sender,
|
||||||
(CommandPermission) root.getNodeMeta()
|
(CommandPermission) root.getNodeMeta()
|
||||||
|
|
@ -378,12 +376,12 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(root.getValue().getValueType(),
|
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(root.getValue().getValueType(),
|
||||||
TypeToken.get(root.getValue().getParser().getClass()),
|
TypeToken.get(root.getValue().getParser().getClass()),
|
||||||
root.getValue().getParser());
|
root.getValue().getParser());
|
||||||
final SuggestionProvider<S> provider = pair.getRight()
|
final SuggestionProvider<S> provider = pair.getSecond()
|
||||||
? null
|
? null
|
||||||
: (context, builder) -> this.buildSuggestions(root.getValue(),
|
: (context, builder) -> this.buildSuggestions(root.getValue(),
|
||||||
context, builder);
|
context, builder);
|
||||||
argumentBuilder = RequiredArgumentBuilder
|
argumentBuilder = RequiredArgumentBuilder
|
||||||
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getLeft())
|
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getFirst())
|
||||||
.suggests(provider)
|
.suggests(provider)
|
||||||
.requires(sender -> permissionChecker.test(sender,
|
.requires(sender -> permissionChecker.test(sender,
|
||||||
(CommandPermission) root.getNodeMeta()
|
(CommandPermission) root.getNodeMeta()
|
||||||
|
|
@ -440,26 +438,4 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
return builder.buildFuture();
|
return builder.buildFuture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class Pair<L, R> {
|
|
||||||
|
|
||||||
private final L left;
|
|
||||||
private final R right;
|
|
||||||
|
|
||||||
private Pair(final @NonNull L left,
|
|
||||||
final @NonNull R right) {
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
private @NonNull L getLeft() {
|
|
||||||
return this.left;
|
|
||||||
}
|
|
||||||
|
|
||||||
private @NonNull R getRight() {
|
|
||||||
return this.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,9 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final CommandSender commandSender, final String s, final String[] strings) {
|
public boolean execute(final @NonNull CommandSender commandSender,
|
||||||
|
final @NonNull String s,
|
||||||
|
final @NonNull String @NonNull [] strings) {
|
||||||
/* Join input */
|
/* Join input */
|
||||||
final StringBuilder builder = new StringBuilder(this.command.getName());
|
final StringBuilder builder = new StringBuilder(this.command.getName());
|
||||||
for (final String string : strings) {
|
for (final String string : strings) {
|
||||||
|
|
@ -135,8 +137,10 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) throws
|
public List<String> tabComplete(final @NonNull CommandSender sender,
|
||||||
IllegalArgumentException {
|
final @NonNull String alias,
|
||||||
|
final @NonNull String @NonNull [] args)
|
||||||
|
throws IllegalArgumentException {
|
||||||
final StringBuilder builder = new StringBuilder(this.command.getName());
|
final StringBuilder builder = new StringBuilder(this.command.getName());
|
||||||
for (final String string : args) {
|
for (final String string : args) {
|
||||||
builder.append(" ").append(string);
|
builder.append(" ").append(string);
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -39,17 +39,17 @@ class AsyncCommandSuggestionsListener<C> implements Listener {
|
||||||
|
|
||||||
private final PaperCommandManager<C> paperCommandManager;
|
private final PaperCommandManager<C> paperCommandManager;
|
||||||
|
|
||||||
AsyncCommandSuggestionsListener(@Nonnull final PaperCommandManager<C> paperCommandManager) {
|
AsyncCommandSuggestionsListener(final @NonNull PaperCommandManager<C> paperCommandManager) {
|
||||||
this.paperCommandManager = paperCommandManager;
|
this.paperCommandManager = paperCommandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onTabCompletion(@Nonnull final AsyncTabCompleteEvent event) throws Exception {
|
void onTabCompletion(final @NonNull AsyncTabCompleteEvent event) throws Exception {
|
||||||
if (event.getBuffer().isEmpty() || !event.getBuffer().startsWith("/")) {
|
if (event.getBuffer().isEmpty() || !event.getBuffer().startsWith("/")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String[] arguments = event.getBuffer().substring(1).split(" ");
|
final String[] arguments = event.getBuffer().substring(1).split(" ");
|
||||||
if (paperCommandManager.getCommandTree().getNamedNode(arguments[0]) == null) {
|
if (this.paperCommandManager.getCommandTree().getNamedNode(arguments[0]) == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -60,7 +60,7 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
private final PaperCommandManager<C> paperCommandManager;
|
private final PaperCommandManager<C> paperCommandManager;
|
||||||
private final String nmsVersion;
|
private final String nmsVersion;
|
||||||
|
|
||||||
PaperBrigadierListener(@Nonnull final PaperCommandManager<C> paperCommandManager) {
|
PaperBrigadierListener(final @NonNull PaperCommandManager<C> paperCommandManager) {
|
||||||
this.paperCommandManager = paperCommandManager;
|
this.paperCommandManager = paperCommandManager;
|
||||||
this.brigadierManager = new CloudBrigadierManager<>(this.paperCommandManager,
|
this.brigadierManager = new CloudBrigadierManager<>(this.paperCommandManager,
|
||||||
() -> new CommandContext<>(
|
() -> new CommandContext<>(
|
||||||
|
|
@ -120,8 +120,7 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
* @return Argument class
|
* @return Argument class
|
||||||
* @throws Exception If the type cannot be retrieved
|
* @throws Exception If the type cannot be retrieved
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
private @NonNull Class<?> getNMSArgument(final @NonNull String argument) throws Exception {
|
||||||
private Class<?> getNMSArgument(@Nonnull final String argument) throws Exception {
|
|
||||||
return Class.forName(String.format("net.minecraft.server.%s.Argument%s", this.nmsVersion, argument));
|
return Class.forName(String.format("net.minecraft.server.%s.Argument%s", this.nmsVersion, argument));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,8 +130,8 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
* @param type Type to map
|
* @param type Type to map
|
||||||
* @param constructor Constructor that construct the NMS argument type
|
* @param constructor Constructor that construct the NMS argument type
|
||||||
*/
|
*/
|
||||||
public void mapSimpleNMS(@Nonnull final Class<?> type,
|
public void mapSimpleNMS(final @NonNull Class<?> type,
|
||||||
@Nonnull final Constructor<?> constructor) {
|
final @NonNull Constructor<?> constructor) {
|
||||||
try {
|
try {
|
||||||
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, () -> {
|
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, () -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -156,8 +155,8 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
* @param type Type to map
|
* @param type Type to map
|
||||||
* @param argumentTypeSupplier Supplier of the NMS argument type
|
* @param argumentTypeSupplier Supplier of the NMS argument type
|
||||||
*/
|
*/
|
||||||
public void mapComplexNMS(@Nonnull final Class<?> type,
|
public void mapComplexNMS(final @NonNull Class<?> type,
|
||||||
@Nonnull final Supplier<ArgumentType<?>> argumentTypeSupplier) {
|
final @NonNull Supplier<ArgumentType<?>> argumentTypeSupplier) {
|
||||||
try {
|
try {
|
||||||
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, argumentTypeSupplier);
|
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, argumentTypeSupplier);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
@ -170,7 +169,7 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
public void onCommandRegister(final @NonNull CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||||
if (!(event.getCommand() instanceof PluginIdentifiableCommand)) {
|
if (!(event.getCommand() instanceof PluginIdentifiableCommand)) {
|
||||||
return;
|
return;
|
||||||
} else if (!((PluginIdentifiableCommand) event.getCommand())
|
} else if (!((PluginIdentifiableCommand) event.getCommand())
|
||||||
|
|
@ -190,8 +189,8 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BiPredicate<BukkitBrigadierCommandSource, CommandPermission> permissionChecker = (s, p) -> {
|
final BiPredicate<BukkitBrigadierCommandSource, CommandPermission> permissionChecker = (s, p) -> {
|
||||||
final C sender = paperCommandManager.getCommandSenderMapper().apply(s.getBukkitSender());
|
final C sender = this.paperCommandManager.getCommandSenderMapper().apply(s.getBukkitSender());
|
||||||
return paperCommandManager.hasPermission(sender, p);
|
return this.paperCommandManager.hasPermission(sender, p);
|
||||||
};
|
};
|
||||||
event.setLiteral(this.brigadierManager.createLiteralCommandNode(node,
|
event.setLiteral(this.brigadierManager.createLiteralCommandNode(node,
|
||||||
event.getLiteral(),
|
event.getLiteral(),
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,11 +50,11 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
* @throws Exception If the construction of the manager fails
|
* @throws Exception If the construction of the manager fails
|
||||||
*/
|
*/
|
||||||
public PaperCommandManager(@Nonnull final Plugin owningPlugin,
|
public PaperCommandManager(final @NonNull Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C>,
|
final @NonNull Function<CommandTree<C>,
|
||||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
final @NonNull Function<CommandSender, C> commandSenderMapper,
|
||||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper) throws
|
final @NonNull Function<C, CommandSender> backwardsCommandSenderMapper) throws
|
||||||
Exception {
|
Exception {
|
||||||
super(owningPlugin, commandExecutionCoordinator, commandSenderMapper, backwardsCommandSenderMapper);
|
super(owningPlugin, commandExecutionCoordinator, commandSenderMapper, backwardsCommandSenderMapper);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ import cloud.commandframework.meta.CommandMeta;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,10 +54,10 @@ public class VelocityCommandManager<C> extends CommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSource}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSource}
|
||||||
*/
|
*/
|
||||||
public VelocityCommandManager(
|
public VelocityCommandManager(
|
||||||
@Nonnull final ProxyServer proxyServer,
|
final @NonNull ProxyServer proxyServer,
|
||||||
@Nonnull final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSource, C> commandSenderMapper,
|
final @NonNull Function<@NonNull CommandSource, @NonNull C> commandSenderMapper,
|
||||||
@Nonnull final Function<C, CommandSource> backwardsCommandSenderMapper) {
|
final @NonNull Function<@NonNull C, @NonNull CommandSource> backwardsCommandSenderMapper) {
|
||||||
super(commandExecutionCoordinator, new VelocityPluginRegistrationHandler<>());
|
super(commandExecutionCoordinator, new VelocityPluginRegistrationHandler<>());
|
||||||
((VelocityPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((VelocityPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
|
|
@ -66,23 +66,20 @@ public class VelocityCommandManager<C> extends CommandManager<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final C sender, @Nonnull final String permission) {
|
public final boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
|
||||||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final CommandMeta createDefaultCommandMeta() {
|
public final @NonNull CommandMeta createDefaultCommandMeta() {
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
final @NonNull ProxyServer getProxyServer() {
|
||||||
final ProxyServer getProxyServer() {
|
|
||||||
return this.proxyServer;
|
return this.proxyServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
final @NonNull Function<@NonNull CommandSource, @NonNull C> getCommandSenderMapper() {
|
||||||
final Function<CommandSource, C> getCommandSenderMapper() {
|
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ final class VelocityPluginRegistrationHandler<C> implements CommandRegistrationH
|
||||||
private CloudBrigadierManager<C, CommandSource> brigadierManager;
|
private CloudBrigadierManager<C, CommandSource> brigadierManager;
|
||||||
private VelocityCommandManager<C> manager;
|
private VelocityCommandManager<C> manager;
|
||||||
|
|
||||||
void initialize(@Nonnull final VelocityCommandManager<C> velocityCommandManager) {
|
void initialize(final @NonNull VelocityCommandManager<C> velocityCommandManager) {
|
||||||
this.manager = velocityCommandManager;
|
this.manager = velocityCommandManager;
|
||||||
this.brigadierManager = new CloudBrigadierManager<>(velocityCommandManager,
|
this.brigadierManager = new CloudBrigadierManager<>(velocityCommandManager,
|
||||||
() -> new CommandContext<>(
|
() -> new CommandContext<>(
|
||||||
|
|
@ -65,7 +65,7 @@ final class VelocityPluginRegistrationHandler<C> implements CommandRegistrationH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
public boolean registerCommand(final @NonNull Command<?> command) {
|
||||||
final CommandArgument<?, ?> argument = command.getArguments().get(0);
|
final CommandArgument<?, ?> argument = command.getArguments().get(0);
|
||||||
final List<String> aliases = ((StaticArgument<C>) argument).getAlternativeAliases();
|
final List<String> aliases = ((StaticArgument<C>) argument).getAlternativeAliases();
|
||||||
final BrigadierCommand brigadierCommand = new BrigadierCommand(
|
final BrigadierCommand brigadierCommand = new BrigadierCommand(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue