diff --git a/src/main/java/de/presti/ree6/commands/CommandEvent.java b/src/main/java/de/presti/ree6/commands/CommandEvent.java index 759060c03..01c3c5263 100644 --- a/src/main/java/de/presti/ree6/commands/CommandEvent.java +++ b/src/main/java/de/presti/ree6/commands/CommandEvent.java @@ -1,6 +1,5 @@ package de.presti.ree6.commands; -import de.presti.ree6.commands.interfaces.ICommand; import de.presti.ree6.language.LanguageService; import de.presti.ree6.main.Main; import lombok.Getter; @@ -25,11 +24,10 @@ public class CommandEvent { /** - * The Command that has been executed. + * The Name of Command that has been executed. */ @Getter - @Nonnull - ICommand iCommand; + String command; /** * The Member associated with the Command execution. @@ -70,7 +68,7 @@ public class CommandEvent { /** * Constructor used to save the Data. * - * @param iCommand the {@link ICommand} + * @param command the Command Name. * @param member the {@link Member} Entity. * @param guild the {@link Guild} Entity. * @param message the {@link Message} Entity. @@ -78,8 +76,8 @@ public class CommandEvent { * @param arguments the given Arguments. * @param slashCommandInteractionEvent the {@link SlashCommandInteractionEvent} Entity. */ - public CommandEvent(@Nonnull ICommand iCommand, @Nonnull Member member, @Nonnull Guild guild, @Nullable Message message, @Nonnull MessageChannelUnion textChannel, @Nullable String[] arguments, @Nullable SlashCommandInteractionEvent slashCommandInteractionEvent) { - this.iCommand = iCommand; + public CommandEvent(String command, @Nonnull Member member, @Nonnull Guild guild, @Nullable Message message, @Nonnull MessageChannelUnion textChannel, @Nullable String[] arguments, @Nullable SlashCommandInteractionEvent slashCommandInteractionEvent) { + this.command = command; this.member = member; this.guild = guild; this.message = message; diff --git a/src/main/java/de/presti/ree6/commands/CommandManager.java b/src/main/java/de/presti/ree6/commands/CommandManager.java index 0914a49a0..1694cb680 100644 --- a/src/main/java/de/presti/ree6/commands/CommandManager.java +++ b/src/main/java/de/presti/ree6/commands/CommandManager.java @@ -90,29 +90,48 @@ public void addSlashCommand(JDA jda) { commandData = new CommandDataImpl(command.getClass().getAnnotation(Command.class).name(), command.getClass().getAnnotation(Command.class).description()); } - for (DiscordLocale discordLocale : DiscordLocale.values()) { - if (!LanguageService.languageResources.containsKey(discordLocale)) continue; + if (commandData instanceof CommandDataImpl commandData1) { - String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description() + "_slash"); + for (DiscordLocale discordLocale : DiscordLocale.values()) { + if (!LanguageService.languageResources.containsKey(discordLocale)) continue; + + String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description() + "_slash"); + if (description.equals("Missing language resource!")) { + description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description()); + } + + if (!description.equals("Missing language resource!")) { + commandData1.setDescriptionLocalization(discordLocale, description); + } + } + + String description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description() + "_slash"); if (description.equals("Missing language resource!")) { - description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description()); + description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description()); } if (!description.equals("Missing language resource!")) { - if (commandData instanceof CommandDataImpl commandData1) { - commandData1.setDescriptionLocalization(discordLocale, description); - } + commandData1.setDescription(description); } - } - if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) { - commandData.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR)); - } + if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) { + commandData1.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR)); + } - commandData.setGuildOnly(true); + commandData1.setGuildOnly(true); - //noinspection ResultOfMethodCallIgnored - listUpdateAction.addCommands(commandData); + //noinspection ResultOfMethodCallIgnored + listUpdateAction.addCommands(commandData1); + } else { + if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) { + commandData.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR)); + } + + commandData.setGuildOnly(true); + + //noinspection ResultOfMethodCallIgnored + listUpdateAction.addCommands(commandData); + } } listUpdateAction.queue(); @@ -279,7 +298,7 @@ private boolean performMessageCommand(Member member, Guild guild, String message String[] argumentsParsed = Arrays.copyOfRange(arguments, 1, arguments.length); // Perform the Command. - command.onASyncPerform(new CommandEvent(command, member, guild, message, textChannel, argumentsParsed, null)); + command.onASyncPerform(new CommandEvent(command.getClass().getAnnotation(Command.class).name(), member, guild, message, textChannel, argumentsParsed, null)); return true; } @@ -289,7 +308,6 @@ private boolean performMessageCommand(Member member, Guild guild, String message * * @param textChannel the TextChannel where the command has been performed. * @param slashCommandInteractionEvent the Slash-Command Event. - * * @return true, if a command has been performed. */ private boolean performSlashCommand(MessageChannelUnion textChannel, SlashCommandInteractionEvent slashCommandInteractionEvent) { @@ -309,7 +327,7 @@ private boolean performSlashCommand(MessageChannelUnion textChannel, SlashComman } // Perform the Command. - command.onASyncPerform(new CommandEvent(command, slashCommandInteractionEvent.getMember(), slashCommandInteractionEvent.getGuild(), null, textChannel, null, slashCommandInteractionEvent)); + command.onASyncPerform(new CommandEvent(command.getClass().getAnnotation(Command.class).name(), slashCommandInteractionEvent.getMember(), slashCommandInteractionEvent.getGuild(), null, textChannel, null, slashCommandInteractionEvent)); return true; } diff --git a/src/main/java/de/presti/ree6/commands/interfaces/ICommand.java b/src/main/java/de/presti/ree6/commands/interfaces/ICommand.java index 74bc1763b..d33a4a04c 100644 --- a/src/main/java/de/presti/ree6/commands/interfaces/ICommand.java +++ b/src/main/java/de/presti/ree6/commands/interfaces/ICommand.java @@ -32,7 +32,7 @@ default void onASyncPerform(CommandEvent commandEvent) { return null; }); // Update Stats. - Main.getInstance().getSqlConnector().getSqlWorker().addStats(commandEvent.getGuild().getId(), commandEvent.getICommand().getClass().getAnnotation(Command.class).name()); + Main.getInstance().getSqlConnector().getSqlWorker().addStats(commandEvent.getGuild().getId(), commandEvent.getCommand()); } /**