I have a variable, which is a new interface. I would like to change something inside of that. I am not sure if this is possible with something like Reflection or Javassist.
This is fairly hard to explain, but if you look at the example you might understand me a bit better.
If you need more information, please ask because I really need to know this.
(this is code from ProtocolLib, which uses Netty. I want to patch something in ProtocolLib at runtime; hence I want to use something like Reflection or Javassist)
Actually; I just noticed that with some spaghetti code I can get this to work using Reflection. I will edit this post once again to let you know if this worked and then share my solution for others that might encounter the same issue as me.
Here is an example:
final ChannelInboundHandler endInitProtocol = new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel channel) throws Exception {
try {
synchronized (networkManagers) {
if (MinecraftVersion.getCurrentVersion().getMinor() >= 12 /* I want to change this 12 to an 8 using Reflection or something like Javassist */) {
channel.eventLoop().submit(() ->
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
} else {
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject();
}
}
} catch (Exception ex) {
reporter.reportDetailed(ProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).messageParam(channel).error(ex));
}
}
};
I completely forgot to tell that this question has been solved.
My solution: I downloaded the ProtocolLib source code, then I made my changes to get it to work. I then compiled ProtocolLib, opened it with WinRAR, and extracted the anonymous class (ProtocolInjector$1). I added that class to my resources folder. I then used Javassist to create a new class out of the compiled class file (.class) at runtime and then I replaced the broken ProtocolInjector$1 class with the compiled fixed one.
You can see my commit here on how I fixed that: GitHub