Create a new dedicated Minecraft reflection class.
Dieser Commit ist enthalten in:
Ursprung
88009292bb
Commit
45c28d47c8
@ -39,6 +39,7 @@ import org.bukkit.entity.Player;
|
|||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import com.comphenix.protocol.reflect.FieldUtils;
|
import com.comphenix.protocol.reflect.FieldUtils;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,7 +194,7 @@ class EntityUtilities {
|
|||||||
|
|
||||||
// The Minecraft field that's NOT filled in by the constructor
|
// The Minecraft field that's NOT filled in by the constructor
|
||||||
trackedEntitiesField = FuzzyReflection.fromObject(tracker, true).
|
trackedEntitiesField = FuzzyReflection.fromObject(tracker, true).
|
||||||
getFieldByType(FuzzyReflection.MINECRAFT_OBJECT, ignoredTypes);
|
getFieldByType(MinecraftReflection.MINECRAFT_OBJECT, ignoredTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the entity hashmap
|
// Read the entity hashmap
|
||||||
|
@ -37,6 +37,7 @@ import com.comphenix.protocol.events.PacketEvent;
|
|||||||
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
||||||
import com.comphenix.protocol.reflect.FieldUtils;
|
import com.comphenix.protocol.reflect.FieldUtils;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
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.
|
* 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 {
|
private void initialize() throws IllegalAccessException {
|
||||||
if (intHashMap == null) {
|
if (intHashMap == null) {
|
||||||
// We're looking for the first static field with a Minecraft-object. This should be a IntHashMap.
|
// 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 {
|
try {
|
||||||
intHashMap = FieldUtils.readField(intHashMapField, (Object) null, true);
|
intHashMap = FieldUtils.readField(intHashMapField, (Object) null, true);
|
||||||
|
@ -25,9 +25,6 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
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 net.sf.cglib.proxy.Factory;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
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.FuzzyReflection;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.comphenix.protocol.reflect.VolatileField;
|
import com.comphenix.protocol.reflect.VolatileField;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
|
|
||||||
abstract class PlayerInjector {
|
abstract class PlayerInjector {
|
||||||
|
|
||||||
@ -122,7 +120,7 @@ abstract class PlayerInjector {
|
|||||||
* @param player - the player to retrieve.
|
* @param player - the player to retrieve.
|
||||||
* @return Notch player object.
|
* @return Notch player object.
|
||||||
*/
|
*/
|
||||||
protected EntityPlayer getEntityPlayer(Player player) {
|
protected Object getEntityPlayer(Player player) {
|
||||||
CraftPlayer craft = (CraftPlayer) player;
|
CraftPlayer craft = (CraftPlayer) player;
|
||||||
return craft.getHandle();
|
return craft.getHandle();
|
||||||
}
|
}
|
||||||
@ -379,7 +377,7 @@ abstract class PlayerInjector {
|
|||||||
try {
|
try {
|
||||||
// Well, that sucks. Try just Minecraft objects then.
|
// Well, that sucks. Try just Minecraft objects then.
|
||||||
netHandlerField = FuzzyReflection.fromClass(networkManager.getClass(), true).
|
netHandlerField = FuzzyReflection.fromClass(networkManager.getClass(), true).
|
||||||
getFieldByType(FuzzyReflection.MINECRAFT_OBJECT);
|
getFieldByType(MinecraftReflection.MINECRAFT_OBJECT);
|
||||||
|
|
||||||
} catch (RuntimeException e2) {
|
} catch (RuntimeException e2) {
|
||||||
throw new IllegalAccessException("Cannot locate net handler. " + e2.getMessage());
|
throw new IllegalAccessException("Cannot locate net handler. " + e2.getMessage());
|
||||||
|
@ -32,11 +32,6 @@ import java.util.regex.Pattern;
|
|||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public class FuzzyReflection {
|
public class FuzzyReflection {
|
||||||
|
|
||||||
/**
|
|
||||||
* Matches a Minecraft object.
|
|
||||||
*/
|
|
||||||
public static final String MINECRAFT_OBJECT = "net\\.minecraft(\\.\\w+)+";
|
|
||||||
|
|
||||||
// The class we're actually representing
|
// The class we're actually representing
|
||||||
private Class<?> source;
|
private Class<?> source;
|
||||||
|
@ -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+)+";
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren