NameTagChanger icon indicating copy to clipboard operation
NameTagChanger copied to clipboard

ClassCastException when reloading the plugin

Open Xesau opened this issue 6 years ago • 7 comments

When reloading the plugin, the following exception occurs:

java.lang.ExceptionInInitializerError: null 
    at eu.xesau.kd.Main.onEnable(Main.java:55) ~[?:?]
Caused by: java.lang.ClassCastException:
    com.bringholm.packetinterceptor.v1_0.PacketInterceptor$ChannelInterceptor cannot be cast to com.bringholm.packetinterceptor.v1_0.PacketInterceptor$ChannelInterceptor

I do setPlugin in onEnable, and NameTagChanger.INSTANCE.disable() in onDisable

Xesau avatar Jun 18 '18 13:06 Xesau

Can you show me more precisely how you are calling NameTagChanger.INSTANCE.disable() when the plugin disables? I am fairly certain that this has to do with the fact that the packet handlers are not being cleared when the plugin disables, which is being done by the disable() method.

Also, I strongly recommend not using the /reload command at all. It reloads the entire plugin and classes, and since I have to inject classes into the Minecraft internals, this has the potential to cause heaps of problems.

Alvin-LB avatar Jun 21 '18 10:06 Alvin-LB

try { NameTagChanger.INSTANCE.disable() }
catch (Exception ex) { ex.printStackTrace(); }

It’s the first thing in my onDisable()

Xesau avatar Jun 21 '18 17:06 Xesau

Double check that that method is being called. When I do it myself I get the same exception as you if I don't call NameTagChanger.INSTANCE.disable(), but if I add the following, my code works fine:

if (NameTagChanger.INSTANCE.isEnabled()) {
    NameTagChanger.INSTANCE.disable();
}

Alvin-LB avatar Jun 21 '18 17:06 Alvin-LB

Doesn’t disable() itself Validate.assert(enabled,...)?

Xesau avatar Jun 21 '18 17:06 Xesau

Well yes, but Validate.isTrue(...) throws exceptions if the condition isn't met. It is really just a safeguard to make sure nothing breaks.

Alvin-LB avatar Jun 21 '18 17:06 Alvin-LB

It doesn't throw ClassCastExceptions though :see_no_evil:

Xesau avatar Jun 21 '18 19:06 Xesau

Yes, that's why I asked you to make sure your onDisable is being run. Print a message before you call NameTagChanger.INSTANCE.disable() anď make sure you see it in console.

Alvin-LB avatar Jun 23 '18 07:06 Alvin-LB