Clear registered hooks on disable. + comments + messages.

This commit is contained in:
asofold 2014-07-16 16:08:50 +02:00
parent 7169788554
commit 616e5436a2

View File

@ -25,13 +25,13 @@ public class ProtocolLibComponent implements DisableListener{
public ProtocolLibComponent(Plugin plugin) { public ProtocolLibComponent(Plugin plugin) {
// Register with ProtocolLib // Register with ProtocolLib
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available."); LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available, attempt to add packet level hooks...");
// Classes having a constructor with Plugin as argument. // Classes having a constructor with Plugin as argument.
List<Class<? extends PacketAdapter>> adapterClasses = Arrays.asList( List<Class<? extends PacketAdapter>> adapterClasses = Arrays.asList(
FlyingFrequency.class, FlyingFrequency.class,
SoundDistance.class SoundDistance.class // Need too: SPAWN_ENTITY_WEATHER, wither/dragon: WORLD_EVENT
); );
// TODO: Configurability. // TODO: Configurability (INotifyConfig, method to set up hooks).
for (Class<? extends PacketAdapter> clazz : adapterClasses) { for (Class<? extends PacketAdapter> clazz : adapterClasses) {
try { try {
// Construct a new instance using reflection. // Construct a new instance using reflection.
@ -52,13 +52,10 @@ public class ProtocolLibComponent implements DisableListener{
try { try {
protocolManager.removePacketListener(adapter); protocolManager.removePacketListener(adapter);
} catch (Throwable t) { } catch (Throwable t) {
LogUtil.logWarning("[NoCheatPlus] Failed to unregister protocol listener: " + adapter.getClass().getName()); LogUtil.logWarning("[NoCheatPlus] Failed to unregister packet level hook: " + adapter.getClass().getName());
} }
} }
registeredPacketAdapters.clear();
} }
} }