add initial InteractionRegistry
This commit is contained in:
parent
7fb27795d9
commit
7901e8c380
@ -0,0 +1,33 @@
|
||||
package net.tomatentum.marinara.registry;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import net.tomatentum.marinara.handler.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
|
||||
public class InteractionRegistry {
|
||||
private List<InteractionMethod> interactionMethods;
|
||||
private LibraryWrapper wrapper;
|
||||
|
||||
public InteractionRegistry(LibraryWrapper wrapper) {
|
||||
this.wrapper = wrapper;
|
||||
wrapper.subscribeInteractions(this::handle);
|
||||
}
|
||||
|
||||
public void registerInteractions(InteractionHandler interactionHandler) {
|
||||
for (Method method : interactionHandler.getClass().getMethods()) {
|
||||
interactionMethods.add(InteractionMethod.create(method, interactionHandler, wrapper));
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(Object context) {
|
||||
interactionMethods.forEach((m) -> {
|
||||
InteractionType type = wrapper.getInteractionType(context.getClass());
|
||||
if (m.getType().equals(type))
|
||||
m.run(context);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user