create seperate class for ContextObjectProviders and renamed some context parameters from parameter to context.
First parts of AutocompleteInteraction added
This commit is contained in:
		| @@ -24,9 +24,9 @@ public class ButtonInteractionMethod extends InteractionMethod { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Object getParameter(Object parameter, int index) { | ||||
|     public Object getParameter(Object context, int index) { | ||||
|         Class<?> type = getMethod().getParameterTypes()[index+1]; | ||||
|         return marinara.getWrapper().getComponentContextObject(parameter, type); | ||||
|         return marinara.getWrapper().getContextObjectProvider().getComponentContextObject(context, type); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -38,4 +38,5 @@ public class ButtonInteractionMethod extends InteractionMethod { | ||||
|     public InteractionType getType() { | ||||
|         return InteractionType.BUTTON; | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -26,7 +26,7 @@ public class SlashCommandInteractionMethod extends InteractionMethod { | ||||
|  | ||||
|     @Override | ||||
|     public Object getParameter(Object context, int index) { | ||||
|         return marinara.getWrapper().convertCommandOption(context, commandDefinition.options()[index].type(), commandDefinition.options()[index].name()); | ||||
|         return marinara.getWrapper().getContextObjectProvider().convertCommandOption(context, commandDefinition.options()[index].name()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -0,0 +1,11 @@ | ||||
| package net.tomatentum.marinara.wrapper; | ||||
|  | ||||
| public interface ContextObjectProvider { | ||||
|  | ||||
|     public Object convertCommandOption(Object context, String optionName); | ||||
|  | ||||
|     public Object getComponentContextObject(Object context, Class<?> type); | ||||
|     public Object getInteractionContextObject(Object context, Class<?> type); | ||||
|  | ||||
|     public Object getAutocompleteFocusedOption(Object context); | ||||
| } | ||||
| @@ -6,7 +6,6 @@ import java.util.function.Consumer; | ||||
|  | ||||
| import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition; | ||||
| import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; | ||||
| import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType; | ||||
| import net.tomatentum.marinara.interaction.InteractionType; | ||||
|  | ||||
| public abstract class LibraryWrapper { | ||||
| @@ -17,7 +16,6 @@ public abstract class LibraryWrapper { | ||||
|         interactionSubscriber = new ArrayList<>(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public void handleInteraction(Object context) { | ||||
|         interactionSubscriber.forEach((o) -> o.accept(context)); | ||||
|     } | ||||
| @@ -32,9 +30,10 @@ public abstract class LibraryWrapper { | ||||
|     public abstract InteractionType getInteractionType(Class<?> clazz); | ||||
|  | ||||
|     public abstract void registerSlashCommands(SlashCommandDefinition[] defs);  | ||||
|     public abstract Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName); | ||||
|     public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context); | ||||
|  | ||||
|     public abstract String getButtonId(Object context); | ||||
|     public abstract Object getComponentContextObject(Object context, Class<?> type); | ||||
|  | ||||
|     public abstract ContextObjectProvider getContextObjectProvider(); | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user