@idk-my-name
What Java.extend()
returns is something that behaves like a type (Forgot what it really is, probably a JSAdaptor or something).
Similar to what you will get from using Java.type()
.
ArrayList = Java.type("java.util.ArrayList")
arrayList = new ArrayList()
BBConsumer = Java.extend(Listenable, Consumer, {
handleEvents: function() { return true},
accept: function(e) {
// onBlockBB here
}
})
consumer = new BBConsumer()
registerListener(consumer)
// not registerListener(BBConsumer)
/* I am sure there would be a better name for BBConsumer
And if you want to use it like a anonymous class in Java you could just read the BlockAnimations.js or better, nashorn document
https://github.com/CzechHek/Core/blob/879f36d7e41ccc7868285b0a808866b360f30822/Scripts/BlockAnimations.js#L35
*/
Not sure if the type from Java.extend
would have other unexpected methods that only takes 1 parameters, you might want to check if the parameter's super class is Event
.
Or you could just explicitly specify the accept
method in it.
method = consumer.class.getMethod("accept", java.lang.Object.class)
Edit:
Nvm, I forgot that this was scriptAPI, the Consumer
here is a Consumer<?>
, not Consumer<BlockBBEvent>
which means the accepct()
takes an java.lang.Object
, and it will register a Listener that listens to any event that is an java.lang.Object
, which probably means all events.'
Here is what I did
registry = getField(LiquidBounce.eventManager, "registry").get(LiquidBounce.eventManager)
BBs = registry.getOrDefault(BlockBBEvent.class, new ArrayList())
BBs.add(new EventHook(consumer,
consumer.class.getMethod("accept", java.lang.Object.class),
LiquidBounce.moduleManager.class
.getDeclaredMethod("onKey", KeyEvent.class)
.getAnnotation(EventTarget.class)))
registry[BlockBBEvent.class] = BBs