Create a new dedicated Minecraft reflection class.

This commit is contained in:
Kristian S. Stangeland 2012-12-05 23:47:55 +01:00
parent 88009292bb
commit 45c28d47c8
5 changed files with 21 additions and 12 deletions

View File

@ -39,6 +39,7 @@ import org.bukkit.entity.Player;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.collect.Lists;
/**
@ -193,7 +194,7 @@ class EntityUtilities {
// The Minecraft field that's NOT filled in by the constructor
trackedEntitiesField = FuzzyReflection.fromObject(tracker, true).
getFieldByType(FuzzyReflection.MINECRAFT_OBJECT, ignoredTypes);
getFieldByType(MinecraftReflection.MINECRAFT_OBJECT, ignoredTypes);
}
// Read the entity hashmap

View File

@ -37,6 +37,7 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftReflection;
/**
* This class is responsible for adding or removing proxy objects that intercepts recieved packets.
@ -92,7 +93,8 @@ class PacketInjector {
private void initialize() throws IllegalAccessException {
if (intHashMap == null) {
// We're looking for the first static field with a Minecraft-object. This should be a IntHashMap.
Field intHashMapField = FuzzyReflection.fromClass(Packet.class, true).getFieldByType(FuzzyReflection.MINECRAFT_OBJECT);
Field intHashMapField = FuzzyReflection.fromClass(Packet.class, true).
getFieldByType(MinecraftReflection.MINECRAFT_OBJECT);
try {
intHashMap = FieldUtils.readField(intHashMapField, (Object) null, true);

View File

@ -25,9 +25,6 @@ import java.lang.reflect.Method;
import java.net.Socket;
import java.net.SocketAddress;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.NetLoginHandler;
import net.minecraft.server.Packet;
import net.sf.cglib.proxy.Factory;
import org.bukkit.craftbukkit.entity.CraftPlayer;
@ -45,6 +42,7 @@ import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.reflect.VolatileField;
import com.comphenix.protocol.utility.MinecraftReflection;
abstract class PlayerInjector {
@ -122,7 +120,7 @@ abstract class PlayerInjector {
* @param player - the player to retrieve.
* @return Notch player object.
*/
protected EntityPlayer getEntityPlayer(Player player) {
protected Object getEntityPlayer(Player player) {
CraftPlayer craft = (CraftPlayer) player;
return craft.getHandle();
}
@ -379,7 +377,7 @@ abstract class PlayerInjector {
try {
// Well, that sucks. Try just Minecraft objects then.
netHandlerField = FuzzyReflection.fromClass(networkManager.getClass(), true).
getFieldByType(FuzzyReflection.MINECRAFT_OBJECT);
getFieldByType(MinecraftReflection.MINECRAFT_OBJECT);
} catch (RuntimeException e2) {
throw new IllegalAccessException("Cannot locate net handler. " + e2.getMessage());

View File

@ -32,11 +32,6 @@ import java.util.regex.Pattern;
* @author Kristian
*/
public class FuzzyReflection {
/**
* Matches a Minecraft object.
*/
public static final String MINECRAFT_OBJECT = "net\\.minecraft(\\.\\w+)+";
// The class we're actually representing
private Class<?> source;

View File

@ -0,0 +1,13 @@
package com.comphenix.protocol.utility;
/**
* Methods and constants specifically used in conjuction with reflecting Minecraft object.
* @author Kristian
*
*/
public class MinecraftReflection {
/**
* Matches a Minecraft object.
*/
public static final String MINECRAFT_OBJECT = "net\\.minecraft(\\.\\w+)+";
}