Extending Java constructors with Nashorn?
-
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 wrapIPacketintoPacket<?>, 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; }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login