Handle 1.3 correctly.

This commit is contained in:
Kristian S. Stangeland 2012-09-26 04:06:10 +02:00
parent 22f2f45d1e
commit 9efb85e7c3
4 changed files with 20 additions and 8 deletions

View File

@ -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.");
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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) {