diff --git a/ProtocolLib/src/com/comphenix/protocol/injector/NetworkServerInjector.java b/ProtocolLib/src/com/comphenix/protocol/injector/NetworkServerInjector.java index eaa1d65e..d5f145e9 100644 --- a/ProtocolLib/src/com/comphenix/protocol/injector/NetworkServerInjector.java +++ b/ProtocolLib/src/com/comphenix/protocol/injector/NetworkServerInjector.java @@ -112,10 +112,13 @@ public class NetworkServerInjector extends PlayerInjector { CollectionGenerator.INSTANCE); Object proxyObject = serverInstances.forEnhancer(ex).getDefault(serverClass); - + // Inject it now if (proxyObject != null) { serverHandlerRef.setValue(proxyObject); + } else { + throw new RuntimeException( + "Cannot hook player: Unable to find a valid constructor for the NetServerHandler object."); } } diff --git a/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java b/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java index a05b30a7..612e6e70 100644 --- a/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java +++ b/ProtocolLib/src/com/comphenix/protocol/injector/PlayerInjector.java @@ -132,21 +132,26 @@ abstract class PlayerInjector { // What a mess try { if (netHandlerField == null) - netHandlerField = FuzzyReflection.fromClass(networkManagerField.getType(), true). + netHandlerField = FuzzyReflection.fromClass(networkManager.getClass(), true). getFieldByType("net\\.minecraft\\.NetHandler"); } catch (RuntimeException e1) { + // Swallow it + } + + // Second attempt + if (netHandlerField == null) { try { // Well, that sucks. Try just Minecraft objects then. - netHandlerField = FuzzyReflection.fromClass(networkManagerField.getType(), true). + netHandlerField = FuzzyReflection.fromClass(networkManager.getClass(), true). getFieldByType(FuzzyReflection.MINECRAFT_OBJECT); } catch (RuntimeException e2) { - return new IllegalAccessException("Cannot locate net handler. " + e2.getMessage()); + throw new IllegalAccessException("Cannot locate net handler. " + e2.getMessage()); } } // Get the handler - if (netHandler != null) + if (netHandler == null) netHandler = FieldUtils.readField(netHandlerField, networkManager, true); return netHandler; } diff --git a/ProtocolLib/src/com/comphenix/protocol/reflect/instances/DefaultInstances.java b/ProtocolLib/src/com/comphenix/protocol/reflect/instances/DefaultInstances.java index 7c240ea0..0e548ff0 100644 --- a/ProtocolLib/src/com/comphenix/protocol/reflect/instances/DefaultInstances.java +++ b/ProtocolLib/src/com/comphenix/protocol/reflect/instances/DefaultInstances.java @@ -20,8 +20,6 @@ package com.comphenix.protocol.reflect.instances; import java.lang.reflect.Constructor; import java.util.*; -import javax.print.CancelablePrintJob; - import net.sf.cglib.proxy.Enhancer; import com.google.common.base.Objects; diff --git a/ProtocolLib/src/com/comphenix/protocol/reflect/instances/ExistingGenerator.java b/ProtocolLib/src/com/comphenix/protocol/reflect/instances/ExistingGenerator.java index 882bd614..97bad0a6 100644 --- a/ProtocolLib/src/com/comphenix/protocol/reflect/instances/ExistingGenerator.java +++ b/ProtocolLib/src/com/comphenix/protocol/reflect/instances/ExistingGenerator.java @@ -40,8 +40,9 @@ public class ExistingGenerator implements InstanceProvider { try { Object value = FieldUtils.readField(field, object, true); + // Use the type of the field, not the object itself if (value != null) - generator.addObject(value); + generator.addObject(field.getType(), value); } catch (Exception e) { // Yes, swallow it. No, really. @@ -72,6 +73,11 @@ public class ExistingGenerator implements InstanceProvider { existingValues.put(value.getClass(), value); } + private void addObject(Class type, Object value) { + existingValues.put(type, value); + } + + @Override public Object create(@Nullable Class type) {