+ rename and move options into definition

This commit is contained in:
tueem 2024-10-14 17:12:44 +02:00
parent bde3c401fb
commit 1a4dfff8ec
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB

@ -3,7 +3,7 @@ package net.tomatentum.marinara.interaction.methods;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.CommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition;
import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand; import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand;
import net.tomatentum.marinara.interaction.commands.annotation.CommandOption; import net.tomatentum.marinara.interaction.commands.annotation.CommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
@ -14,9 +14,7 @@ import net.tomatentum.marinara.wrapper.LibraryWrapper;
public class CommandInteractionMethod extends InteractionMethod { public class CommandInteractionMethod extends InteractionMethod {
private CommandOption[] options; private ExecutableCommandDefinition commandDefinition;
private CommandDefinition commandDefinition;
CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) { CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
super(method, handler, wrapper); super(method, handler, wrapper);
@ -25,12 +23,12 @@ public class CommandInteractionMethod extends InteractionMethod {
@Override @Override
public Object getParameter(Object context, int index) { public Object getParameter(Object context, int index) {
return wrapper.convertCommandOption(context, options[index].type(), options[index].name()); return wrapper.convertCommandOption(context, commandDefinition.options()[index].type(), commandDefinition.options()[index].name());
} }
@Override @Override
public boolean canRun(Object context) { public boolean canRun(Object context) {
CommandDefinition other = wrapper.getCommandDefinition(context); ExecutableCommandDefinition other = wrapper.getCommandDefinition(context);
return commandDefinition.equals(other); return commandDefinition.equals(other);
} }
@ -39,22 +37,18 @@ public class CommandInteractionMethod extends InteractionMethod {
return InteractionType.COMMAND; return InteractionType.COMMAND;
} }
public CommandOption[] getOptions() { public ExecutableCommandDefinition getCommandDefinition() {
return options;
}
public CommandDefinition getCommandDefinition() {
return commandDefinition; return commandDefinition;
} }
private void parseMethod() { private void parseMethod() {
ReflectionUtil.checkValidCommandMethod(method); ReflectionUtil.checkValidCommandMethod(method);
parseOptions();
ApplicationCommand cmd = ReflectionUtil.getAnnotation(method, ApplicationCommand.class); ApplicationCommand cmd = ReflectionUtil.getAnnotation(method, ApplicationCommand.class);
CommandDefinition.Builder builder = new CommandDefinition.Builder(); ExecutableCommandDefinition.Builder builder = new ExecutableCommandDefinition.Builder();
builder.setApplicationCommandName(cmd.name()); builder.setApplicationCommandName(cmd.name());
builder.setApplicationCommandDescription(cmd.description()); builder.setApplicationCommandDescription(cmd.description());
builder.setOptions(parseOptions());
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);