♻️ Reformat + Update .editorconfig
This commit is contained in:
parent
8bdec87a74
commit
2aac3980d5
169 changed files with 4261 additions and 2448 deletions
|
|
@ -48,9 +48,11 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
|||
private final CommandArgument<C, ?> command;
|
||||
private final cloud.commandframework.Command<C> cloudCommand;
|
||||
|
||||
JavacordCommand(final cloud.commandframework.@NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull JavacordCommandManager<C> manager) {
|
||||
JavacordCommand(
|
||||
final cloud.commandframework.@NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull JavacordCommandManager<C> manager
|
||||
) {
|
||||
this.command = command;
|
||||
this.manager = manager;
|
||||
this.cloudCommand = cloudCommand;
|
||||
|
|
@ -85,70 +87,78 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
|||
final String finalContent = messageContent;
|
||||
//noinspection unchecked
|
||||
if (((StaticArgument<C>) command).getAliases()
|
||||
.stream()
|
||||
.map(String::toLowerCase)
|
||||
.noneMatch(commandAlias -> finalContent.toLowerCase().startsWith(commandAlias))) {
|
||||
.stream()
|
||||
.map(String::toLowerCase)
|
||||
.noneMatch(commandAlias -> finalContent.toLowerCase().startsWith(commandAlias))) {
|
||||
return;
|
||||
}
|
||||
|
||||
manager.executeCommand(sender, finalContent)
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
|
||||
if (throwable instanceof NoSuchCommandException) {
|
||||
//Ignore, should never happen
|
||||
return;
|
||||
}
|
||||
if (throwable instanceof NoSuchCommandException) {
|
||||
//Ignore, should never happen
|
||||
return;
|
||||
}
|
||||
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
manager.handleException(sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(
|
||||
"Invalid Command Syntax. Correct command syntax is: `"
|
||||
+ e.getCorrectSyntax()
|
||||
+ "`")
|
||||
);
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
manager.handleException(
|
||||
sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(
|
||||
"Invalid Command Syntax. Correct command syntax is: `"
|
||||
+ e.getCorrectSyntax()
|
||||
+ "`")
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (throwable instanceof InvalidCommandSenderException) {
|
||||
manager.handleException(sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(e.getMessage()));
|
||||
if (throwable instanceof InvalidCommandSenderException) {
|
||||
manager.handleException(
|
||||
sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(e.getMessage())
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (throwable instanceof NoPermissionException) {
|
||||
manager.handleException(sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(MESSAGE_NO_PERMS));
|
||||
if (throwable instanceof NoPermissionException) {
|
||||
manager.handleException(
|
||||
sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(MESSAGE_NO_PERMS)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (throwable instanceof ArgumentParseException) {
|
||||
manager.handleException(sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(
|
||||
"Invalid Command Argument: `" + e.getCause().getMessage() + "`"));
|
||||
if (throwable instanceof ArgumentParseException) {
|
||||
manager.handleException(
|
||||
sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable,
|
||||
(c, e) -> commandSender.sendErrorMessage(
|
||||
"Invalid Command Argument: `" + e.getCause().getMessage() + "`")
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
commandSender.sendErrorMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}));
|
||||
commandSender.sendErrorMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,15 +59,17 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
|
|||
* @param commandPermissionMapper Function used to check if a command sender has the permission to execute a command
|
||||
* @throws Exception If the construction of the manager fails
|
||||
*/
|
||||
public JavacordCommandManager(final @NonNull DiscordApi discordApi,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull JavacordCommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C,
|
||||
@NonNull JavacordCommandSender> backwardsCommandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
|
||||
final @Nullable BiFunction<@NonNull C,
|
||||
@NonNull String, @NonNull Boolean> commandPermissionMapper)
|
||||
public JavacordCommandManager(
|
||||
final @NonNull DiscordApi discordApi,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull JavacordCommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C,
|
||||
@NonNull JavacordCommandSender> backwardsCommandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
|
||||
final @Nullable BiFunction<@NonNull C,
|
||||
@NonNull String, @NonNull Boolean> commandPermissionMapper
|
||||
)
|
||||
throws Exception {
|
||||
super(commandExecutionCoordinator, new JavacordRegistrationHandler<>());
|
||||
((JavacordRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||
|
|
@ -81,7 +83,8 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
|
|||
|
||||
@Override
|
||||
public final boolean hasPermission(
|
||||
final @NonNull C sender, final @NonNull String permission) {
|
||||
final @NonNull C sender, final @NonNull String permission
|
||||
) {
|
||||
if (permission.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -131,4 +134,5 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
|
|||
public @NonNull DiscordApi getDiscordApi() {
|
||||
return this.discordApi;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,38 +26,40 @@ package cloud.commandframework.javacord;
|
|||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
final class JavacordRegistrationHandler<C> implements CommandRegistrationHandler {
|
||||
|
||||
private final Map<CommandArgument<?, ?>, JavacordCommand<C>> registeredCommands = new HashMap<>();
|
||||
private final Map<CommandArgument<?, ?>, JavacordCommand<C>> registeredCommands = new HashMap<>();
|
||||
|
||||
private JavacordCommandManager<C> javacordCommandManager;
|
||||
private JavacordCommandManager<C> javacordCommandManager;
|
||||
|
||||
JavacordRegistrationHandler() {
|
||||
}
|
||||
|
||||
void initialize(final @NonNull JavacordCommandManager<C> javacordCommandManager) {
|
||||
this.javacordCommandManager = javacordCommandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(final @NonNull Command<?> command) {
|
||||
/* We only care about the root command argument */
|
||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||
return false;
|
||||
JavacordRegistrationHandler() {
|
||||
}
|
||||
|
||||
void initialize(final @NonNull JavacordCommandManager<C> javacordCommandManager) {
|
||||
this.javacordCommandManager = javacordCommandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(final @NonNull 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 JavacordCommand<C> javacordCommand = new JavacordCommand<>(
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.javacordCommandManager
|
||||
);
|
||||
this.registeredCommands.put(commandArgument, javacordCommand);
|
||||
this.javacordCommandManager.getDiscordApi().addMessageCreateListener(javacordCommand);
|
||||
return true;
|
||||
}
|
||||
@SuppressWarnings("unchecked") final JavacordCommand<C> javacordCommand = new JavacordCommand<>(
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.javacordCommandManager);
|
||||
this.registeredCommands.put(commandArgument, javacordCommand);
|
||||
this.javacordCommandManager.getDiscordApi().addMessageCreateListener(javacordCommand);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ public class JavacordPrivateSender extends JavacordCommandSender {
|
|||
@NonNull
|
||||
public PrivateChannel getPrivateChannel() {
|
||||
return getEvent().getPrivateChannel()
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"PrivateTextChannel not present even though message was sent in a private channel"));
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"PrivateTextChannel not present even though message was sent in a private channel"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ public class JavacordServerSender extends JavacordCommandSender {
|
|||
@NonNull
|
||||
public ServerChannel getServerChannel() {
|
||||
return getEvent().getServerTextChannel()
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"ServerTextChannel not present even though message was sent in a server channel"));
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"ServerTextChannel not present even though message was sent in a server channel"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +59,8 @@ public class JavacordServerSender extends JavacordCommandSender {
|
|||
@NonNull
|
||||
public Server getServer() {
|
||||
return getEvent().getServer()
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"Server not present even though message was sent on a server"));
|
||||
.orElseThrow(() -> new UnsupportedOperationException(
|
||||
"Server not present even though message was sent on a server"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue