Alvin-LB / NameTagChanger

Library to be shaded into Bukkit Plugins to allow for modification of player name tags.
MIT License
31 stars 10 forks source link

ClassCastException when reloading the plugin #3

Open Xesau opened 6 years ago

Xesau commented 6 years ago

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

Alvin-LB commented 6 years ago

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.

Xesau commented 6 years ago
try { NameTagChanger.INSTANCE.disable() }
catch (Exception ex) { ex.printStackTrace(); }

It’s the first thing in my onDisable()

Alvin-LB commented 6 years ago

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();
}
Xesau commented 6 years ago

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

Alvin-LB commented 6 years ago

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

Xesau commented 6 years ago

It doesn't throw ClassCastExceptions though :see_no_evil:

Alvin-LB commented 6 years ago

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.