NameTagChanger
NameTagChanger copied to clipboard
ClassCastException when reloading the plugin
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
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.
try { NameTagChanger.INSTANCE.disable() }
catch (Exception ex) { ex.printStackTrace(); }
It’s the first thing in my onDisable()
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();
}
Doesn’t disable() itself Validate.assert(enabled,...)?
Well yes, but Validate.isTrue(...)
throws exceptions if the condition isn't met. It is really just a safeguard to make sure nothing breaks.
It doesn't throw ClassCastExceptions though :see_no_evil:
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.