rename and removal of ability for multiple subcommandgroups because I was dumb
This commit is contained in:
parent
f4a6bf937d
commit
d86c307166
23
lib/src/main/java/net/tomatentum/marinara/interaction/commands/ExecutableSlashCommandDefinition.java
23
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||
public class SlashCommandDefinition {
|
||||
private List<ExecutableSlashCommandDefinition> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
@ -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<SlashCommandDefinition> defs = new ArrayList<>();
|
||||
List<ExecutableSlashCommandDefinition> 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) -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user