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.SlashCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||||
|
|
||||||
public record ExecutableSlashCommandDefinition(
|
public record ExecutableSlashCommandDefinition(
|
||||||
SlashCommand applicationCommand,
|
SlashCommand applicationCommand,
|
||||||
SubCommand subCommand,
|
SubCommand subCommand,
|
||||||
String[] subCommandGroups,
|
SubCommandGroup subCommandGroup,
|
||||||
SlashCommandOption[] options) {
|
SlashCommandOption[] options) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -16,8 +17,8 @@ public record ExecutableSlashCommandDefinition(
|
|||||||
return false;
|
return false;
|
||||||
ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o;
|
ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o;
|
||||||
return other.applicationCommand.name().equals(this.applicationCommand.name()) &&
|
return other.applicationCommand.name().equals(this.applicationCommand.name()) &&
|
||||||
other.subCommandGroups.equals(this.subCommandGroups) &&
|
other.subCommandGroup.name().equals(this.subCommandGroup.name()) &&
|
||||||
other.subCommand.equals(this.subCommand);
|
other.subCommand.name().equals(this.subCommand.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,17 +33,13 @@ public record ExecutableSlashCommandDefinition(
|
|||||||
public static class Builder {
|
public static class Builder {
|
||||||
private SlashCommand applicationCommand;
|
private SlashCommand applicationCommand;
|
||||||
private SubCommand subCommand;
|
private SubCommand subCommand;
|
||||||
private String[] subCommandGroupNames;
|
private SubCommandGroup subCommandGroup;
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
this.subCommandGroupNames = new String[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExecutableSlashCommandDefinition build() {
|
public ExecutableSlashCommandDefinition build() {
|
||||||
if (applicationCommand == null)
|
if (applicationCommand == null)
|
||||||
throw new IllegalArgumentException("applicationCommandName cant be 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) {
|
public void setApplicationCommand(SlashCommand applicationCommand) {
|
||||||
@ -53,8 +50,8 @@ public record ExecutableSlashCommandDefinition(
|
|||||||
this.subCommand = subCommand;
|
this.subCommand = subCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubCommandGroupNames(String[] subCommandGroupNames) {
|
public void setSubCommandGroup(SubCommandGroup subCommandGroup) {
|
||||||
this.subCommandGroupNames = subCommandGroupNames;
|
this.subCommandGroup = subCommandGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlashCommand getApplicationCommand() {
|
public SlashCommand getApplicationCommand() {
|
||||||
@ -65,8 +62,8 @@ public record ExecutableSlashCommandDefinition(
|
|||||||
return subCommand;
|
return subCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getSubCommandGroupNames() {
|
public SubCommandGroup getSubCommandGroup() {
|
||||||
return subCommandGroupNames;
|
return subCommandGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
|||||||
public class SlashCommandDefinition {
|
public class SlashCommandDefinition {
|
||||||
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
||||||
private SlashCommand applicationCommand;
|
private SlashCommand applicationCommand;
|
||||||
private int subCommandGroupCount = -1;
|
|
||||||
private boolean isRootCommand = false;
|
private boolean isRootCommand = false;
|
||||||
|
|
||||||
public SlashCommandDefinition(SlashCommand applicationCommand) {
|
public SlashCommandDefinition(SlashCommand applicationCommand) {
|
||||||
@ -18,10 +17,6 @@ public class SlashCommandDefinition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SlashCommandDefinition addExecutableCommand(ExecutableSlashCommandDefinition def) {
|
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 (def.applicationCommand() != null) {
|
||||||
if (applicationCommand == null)
|
if (applicationCommand == null)
|
||||||
this.applicationCommand = def.applicationCommand();
|
this.applicationCommand = def.applicationCommand();
|
||||||
@ -55,8 +50,4 @@ public class SlashCommandDefinition {
|
|||||||
executableDefinitons.forEach(set::add);
|
executableDefinitons.forEach(set::add);
|
||||||
return set.toArray(new ExecutableSlashCommandDefinition[0]);
|
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) {
|
public static InteractionMethod create(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
|
||||||
if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class))
|
if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class))
|
||||||
return new CommandInteractionMethod(method, handler, wrapper);
|
return new SlashCommandInteractionMethod(method, handler, wrapper);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
|||||||
import net.tomatentum.marinara.util.ReflectionUtil;
|
import net.tomatentum.marinara.util.ReflectionUtil;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
|
|
||||||
public class CommandInteractionMethod extends InteractionMethod {
|
public class SlashCommandInteractionMethod extends InteractionMethod {
|
||||||
|
|
||||||
private ExecutableSlashCommandDefinition commandDefinition;
|
private ExecutableSlashCommandDefinition commandDefinition;
|
||||||
|
|
||||||
CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
|
SlashCommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
|
||||||
super(method, handler, wrapper);
|
super(method, handler, wrapper);
|
||||||
parseMethod();
|
parseMethod();
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class CommandInteractionMethod extends InteractionMethod {
|
|||||||
|
|
||||||
if (ReflectionUtil.isAnnotationPresent(method, SubCommandGroup.class)) {
|
if (ReflectionUtil.isAnnotationPresent(method, SubCommandGroup.class)) {
|
||||||
SubCommandGroup cmdGroup = ReflectionUtil.getAnnotation(method, SubCommandGroup.class);
|
SubCommandGroup cmdGroup = ReflectionUtil.getAnnotation(method, SubCommandGroup.class);
|
||||||
builder.setSubCommandGroupNames(cmdGroup.name().split(" "));
|
builder.setSubCommandGroup(cmdGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ReflectionUtil.isAnnotationPresent(method, SubCommand.class)) {
|
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.InteractionType;
|
||||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
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.interaction.methods.InteractionMethod;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ public class InteractionRegistry {
|
|||||||
public void registerCommands() {
|
public void registerCommands() {
|
||||||
List<SlashCommandDefinition> defs = new ArrayList<>();
|
List<SlashCommandDefinition> defs = new ArrayList<>();
|
||||||
List<ExecutableSlashCommandDefinition> execDefs = interactionMethods.stream()
|
List<ExecutableSlashCommandDefinition> execDefs = interactionMethods.stream()
|
||||||
.filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class))
|
.filter((x) -> x.getClass().isAssignableFrom(SlashCommandInteractionMethod.class))
|
||||||
.map((x) -> ((CommandInteractionMethod)x).getCommandDefinition())
|
.map((x) -> ((SlashCommandInteractionMethod)x).getCommandDefinition())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
execDefs.forEach((def) -> {
|
execDefs.forEach((def) -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user