i want to create a code where i can call listeners from any class. Example there is a class called MyCustomClass.java which contains this method:
public ListenerReturn canCreatureAttack(final CanCreatureAttack canCreatureAttack)
{
if (canCreatureAttack.getAttacker().isSuperPlayer))
{
return new listenerReturn(true);
}
return false;
}
Now in the same class in initialization constructor i store in a global ListenerContainer static class the current object and the method and the parameter CanCreatureAttack(actor, target)
Later in some other code i can do a check using
final ListenerReturn return = ListenerContainer.executeListener("myClassName", new CanCreatureAttack(actor, target));
and this will execute the method in that class without invoke or reflection like Consumer and return the result ListenerReturn.
But how i can do this i'm confused.