diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/commands/ExecutableSlashCommandDefinition.java b/lib/src/main/java/net/tomatentum/marinara/interaction/commands/ExecutableSlashCommandDefinition.java index 03d755e..933a4a0 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/commands/ExecutableSlashCommandDefinition.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/commands/ExecutableSlashCommandDefinition.java @@ -3,11 +3,12 @@ package net.tomatentum.marinara.interaction.commands; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption; import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; +import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup; public record ExecutableSlashCommandDefinition( SlashCommand applicationCommand, SubCommand subCommand, - String[] subCommandGroups, + SubCommandGroup subCommandGroup, SlashCommandOption[] options) { @Override @@ -16,8 +17,8 @@ public record ExecutableSlashCommandDefinition( return false; ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o; return other.applicationCommand.name().equals(this.applicationCommand.name()) && - other.subCommandGroups.equals(this.subCommandGroups) && - other.subCommand.equals(this.subCommand); + other.subCommandGroup.name().equals(this.subCommandGroup.name()) && + other.subCommand.name().equals(this.subCommand.name()); } @Override @@ -32,17 +33,13 @@ public record ExecutableSlashCommandDefinition( public static class Builder { private SlashCommand applicationCommand; private SubCommand subCommand; - private String[] subCommandGroupNames; - - public Builder() { - this.subCommandGroupNames = new String[0]; - } + private SubCommandGroup subCommandGroup; public ExecutableSlashCommandDefinition build() { if (applicationCommand == null) throw new IllegalArgumentException("applicationCommandName cant be null"); - return new ExecutableSlashCommandDefinition(applicationCommand, subCommand, subCommandGroupNames, subCommand != null ? subCommand.options() : applicationCommand.options()); + return new ExecutableSlashCommandDefinition(applicationCommand, subCommand, subCommandGroup, subCommand != null ? subCommand.options() : applicationCommand.options()); } public void setApplicationCommand(SlashCommand applicationCommand) { @@ -53,8 +50,8 @@ public record ExecutableSlashCommandDefinition( this.subCommand = subCommand; } - public void setSubCommandGroupNames(String[] subCommandGroupNames) { - this.subCommandGroupNames = subCommandGroupNames; + public void setSubCommandGroup(SubCommandGroup subCommandGroup) { + this.subCommandGroup = subCommandGroup; } public SlashCommand getApplicationCommand() { @@ -65,8 +62,8 @@ public record ExecutableSlashCommandDefinition( return subCommand; } - public String[] getSubCommandGroupNames() { - return subCommandGroupNames; + public SubCommandGroup getSubCommandGroup() { + return subCommandGroup; } } diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/commands/SlashCommandDefinition.java b/lib/src/main/java/net/tomatentum/marinara/interaction/commands/SlashCommandDefinition.java index 133cf5b..988ced3 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/commands/SlashCommandDefinition.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/commands/SlashCommandDefinition.java @@ -9,7 +9,6 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; public class SlashCommandDefinition { private List executableDefinitons; private SlashCommand applicationCommand; - private int subCommandGroupCount = -1; private boolean isRootCommand = false; public SlashCommandDefinition(SlashCommand applicationCommand) { @@ -18,10 +17,6 @@ public class SlashCommandDefinition { } public SlashCommandDefinition addExecutableCommand(ExecutableSlashCommandDefinition def) { - if (this.subCommandGroupCount == -1) - this.subCommandGroupCount = def.subCommandGroups().length; - if (def.subCommandGroups().length != subCommandGroupCount) - throw new IllegalArgumentException(def + ": has a non matching amount of subcommand groups. All subcommands must have the same amount of subcommand groups!"); if (def.applicationCommand() != null) { if (applicationCommand == null) this.applicationCommand = def.applicationCommand(); @@ -55,8 +50,4 @@ public class SlashCommandDefinition { executableDefinitons.forEach(set::add); return set.toArray(new ExecutableSlashCommandDefinition[0]); } - public int getSubCommandGroupCount() { - return subCommandGroupCount; - } - } diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java index 7a5a909..89e1ff0 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java @@ -16,7 +16,7 @@ public abstract class InteractionMethod { public static InteractionMethod create(Method method, InteractionHandler handler, LibraryWrapper wrapper) { if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class)) - return new CommandInteractionMethod(method, handler, wrapper); + return new SlashCommandInteractionMethod(method, handler, wrapper); return null; } diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/CommandInteractionMethod.java b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/SlashCommandInteractionMethod.java similarity index 90% rename from lib/src/main/java/net/tomatentum/marinara/interaction/methods/CommandInteractionMethod.java rename to lib/src/main/java/net/tomatentum/marinara/interaction/methods/SlashCommandInteractionMethod.java index 7bf7ecf..6498078 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/CommandInteractionMethod.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/SlashCommandInteractionMethod.java @@ -11,11 +11,11 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup; import net.tomatentum.marinara.util.ReflectionUtil; import net.tomatentum.marinara.wrapper.LibraryWrapper; -public class CommandInteractionMethod extends InteractionMethod { +public class SlashCommandInteractionMethod extends InteractionMethod { private ExecutableSlashCommandDefinition commandDefinition; - CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) { + SlashCommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) { super(method, handler, wrapper); parseMethod(); } @@ -49,7 +49,7 @@ public class CommandInteractionMethod extends InteractionMethod { if (ReflectionUtil.isAnnotationPresent(method, SubCommandGroup.class)) { SubCommandGroup cmdGroup = ReflectionUtil.getAnnotation(method, SubCommandGroup.class); - builder.setSubCommandGroupNames(cmdGroup.name().split(" ")); + builder.setSubCommandGroup(cmdGroup); } if (ReflectionUtil.isAnnotationPresent(method, SubCommand.class)) { diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index 3d9037f..90ce054 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -9,7 +9,7 @@ import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; -import net.tomatentum.marinara.interaction.methods.CommandInteractionMethod; +import net.tomatentum.marinara.interaction.methods.SlashCommandInteractionMethod; import net.tomatentum.marinara.interaction.methods.InteractionMethod; import net.tomatentum.marinara.wrapper.LibraryWrapper; @@ -31,8 +31,8 @@ public class InteractionRegistry { public void registerCommands() { List defs = new ArrayList<>(); List execDefs = interactionMethods.stream() - .filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class)) - .map((x) -> ((CommandInteractionMethod)x).getCommandDefinition()) + .filter((x) -> x.getClass().isAssignableFrom(SlashCommandInteractionMethod.class)) + .map((x) -> ((SlashCommandInteractionMethod)x).getCommandDefinition()) .toList(); execDefs.forEach((def) -> {