add remaining parts of AutocompleteInteraction
This commit is contained in:
		| @@ -0,0 +1,51 @@ | ||||
| package net.tomatentum.marinara.interaction.methods; | ||||
|  | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| import net.tomatentum.marinara.Marinara; | ||||
| import net.tomatentum.marinara.interaction.InteractionHandler; | ||||
| import net.tomatentum.marinara.interaction.InteractionType; | ||||
| import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; | ||||
| import net.tomatentum.marinara.parser.AnnotationParser; | ||||
| import net.tomatentum.marinara.parser.SlashCommandParser; | ||||
|  | ||||
| public class AutoCompleteInteractionMethod extends InteractionMethod { | ||||
|  | ||||
|     private ExecutableSlashCommandDefinition commandDefinition; | ||||
|  | ||||
|     public AutoCompleteInteractionMethod(Method method,  | ||||
|         InteractionHandler handler,  | ||||
|         Marinara marinara | ||||
|         ) { | ||||
|         super(method, handler, marinara); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public AnnotationParser[] getParsers() { | ||||
|         return new AnnotationParser[] {  | ||||
|             new SlashCommandParser(method, (x) -> { this.commandDefinition = x; } )  | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Object getParameter(Object context, int index) { | ||||
|         Class<?> type = getMethod().getParameterTypes()[index+1]; | ||||
|         Object autocompleteOptionValue = marinara.getWrapper().getContextObjectProvider().getAutocompleteFocusedOption(context); | ||||
|         if (autocompleteOptionValue != null) | ||||
|             return autocompleteOptionValue; | ||||
|  | ||||
|         return marinara.getWrapper().getContextObjectProvider().getComponentContextObject(context, type); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean canRun(Object context) { | ||||
|         ExecutableSlashCommandDefinition other = marinara.getWrapper().getCommandDefinition(context); | ||||
|         return commandDefinition.equals(other); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public InteractionType getType() { | ||||
|         return InteractionType.AUTOCOMPLETE; | ||||
|     } | ||||
|      | ||||
| } | ||||
| @@ -11,6 +11,7 @@ import net.tomatentum.marinara.Marinara; | ||||
| import net.tomatentum.marinara.checks.AppliedCheck; | ||||
| import net.tomatentum.marinara.interaction.InteractionHandler; | ||||
| import net.tomatentum.marinara.interaction.InteractionType; | ||||
| import net.tomatentum.marinara.interaction.annotation.AutoComplete; | ||||
| import net.tomatentum.marinara.interaction.annotation.Button; | ||||
| import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; | ||||
| import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; | ||||
| @@ -20,6 +21,8 @@ import net.tomatentum.marinara.parser.InteractionCheckParser; | ||||
| public abstract class InteractionMethod { | ||||
|  | ||||
|     public static InteractionMethod create(Method method, InteractionHandler handler, Marinara marinara) { | ||||
|         if (method.isAnnotationPresent(AutoComplete.class)) | ||||
|             return new AutoCompleteInteractionMethod(method, handler, marinara); | ||||
|         if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class)) | ||||
|             return new SlashCommandInteractionMethod(method, handler, marinara); | ||||
|         if (method.isAnnotationPresent(Button.class)) | ||||
| @@ -53,7 +56,7 @@ public abstract class InteractionMethod { | ||||
|  | ||||
|     public abstract AnnotationParser[] getParsers(); | ||||
|  | ||||
|     public abstract Object getParameter(Object parameter, int index); | ||||
|     public abstract Object getParameter(Object context, int index); | ||||
|  | ||||
|     public abstract boolean canRun(Object context); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user