Extending Java constructors with Nashorn?
Unsolved
General
-
Let's say that there's a listener that subscribes into PacketEvent and calls my WrappedPacketEvent:
var WrappedListener = Java.extend((Java.type('net.ccbluex.liquidbounce.event.Listenable')), (Java.type('java.util.function.Consumer')), { handleEvents: function() { return true }, accept: function(e) { e instanceof PacketEvent && LiquidBounce.INSTANCE.eventManager.callEvent(new WrappedPacketEvent(e.getPacket().wrapped)); } });
But how can I extend Event and create my own constructor that accepts
Packet<?>
? (Consumer?) -
For understanding:
The problem is inIPacket
.
I want to wrapIPacket
intoPacket<?>
, so onPacket will acceptPacket<?>
instead ofIPacket
(xversion problem, I need to write e.getPacket().wrapped instead of just e.getPacket(), that's really annoying) -
There's how far I got:
var WrappedListener = Java.extend((Java.type('net.ccbluex.liquidbounce.event.Listenable')), (Java.type('java.util.function.Consumer')), { handleEvents: function() { return module[0].state }, accept: function(e) { e instanceof PacketEvent && LiquidBounce.INSTANCE.eventManager.callEvent(new WrappedPacketEvent(e.getPacket().wrapped)); } }); function WrappedPacketEvent(packet) { var isCancelled; this.isCancelled = function() isCancelled; this.cancelEvent = function() { isCancelled = true; } this.getPacket = function() packet; }