Moved packet-related classes to a seperate package.
This is backwards compatible because they were all package private.
Dieser Commit ist enthalten in:
Ursprung
3219deed79
Commit
6cf3307a3b
@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@ -114,7 +115,7 @@ public class PacketConstructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> packetType = MinecraftRegistry.getPacketClassFromID(id, true);
|
Class<?> packetType = PacketRegistry.getPacketClassFromID(id, true);
|
||||||
|
|
||||||
if (packetType == null)
|
if (packetType == null)
|
||||||
throw new IllegalArgumentException("Could not find a packet by the id " + id);
|
throw new IllegalArgumentException("Could not find a packet by the id " + id);
|
||||||
|
@ -51,6 +51,8 @@ import com.comphenix.protocol.async.AsyncFilterManager;
|
|||||||
import com.comphenix.protocol.async.AsyncMarker;
|
import com.comphenix.protocol.async.AsyncMarker;
|
||||||
import com.comphenix.protocol.error.ErrorReporter;
|
import com.comphenix.protocol.error.ErrorReporter;
|
||||||
import com.comphenix.protocol.events.*;
|
import com.comphenix.protocol.events.*;
|
||||||
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||||
|
import com.comphenix.protocol.injector.packet.PacketInjector;
|
||||||
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
@ -184,8 +186,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
|
|
||||||
// Attempt to load the list of server and client packets
|
// Attempt to load the list of server and client packets
|
||||||
try {
|
try {
|
||||||
this.serverPackets = MinecraftRegistry.getServerPackets();
|
this.serverPackets = PacketRegistry.getServerPackets();
|
||||||
this.clientPackets = MinecraftRegistry.getClientPackets();
|
this.clientPackets = PacketRegistry.getClientPackets();
|
||||||
} catch (FieldAccessException e) {
|
} catch (FieldAccessException e) {
|
||||||
reporter.reportWarning(this, "Cannot load server and client packet list.", e);
|
reporter.reportWarning(this, "Cannot load server and client packet list.", e);
|
||||||
}
|
}
|
||||||
@ -692,22 +694,22 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
if (!MinecraftReflection.isPacketClass(packet))
|
if (!MinecraftReflection.isPacketClass(packet))
|
||||||
throw new IllegalArgumentException("The given object " + packet + " is not a packet.");
|
throw new IllegalArgumentException("The given object " + packet + " is not a packet.");
|
||||||
|
|
||||||
return MinecraftRegistry.getPacketToID().get(packet.getClass());
|
return PacketRegistry.getPacketToID().get(packet.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerPacketClass(Class<?> clazz, int packetID) {
|
public void registerPacketClass(Class<?> clazz, int packetID) {
|
||||||
MinecraftRegistry.getPacketToID().put(clazz, packetID);
|
PacketRegistry.getPacketToID().put(clazz, packetID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterPacketClass(Class<?> clazz) {
|
public void unregisterPacketClass(Class<?> clazz) {
|
||||||
MinecraftRegistry.getPacketToID().remove(clazz);
|
PacketRegistry.getPacketToID().remove(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getPacketClassFromID(int packetID, boolean forceVanilla) {
|
public Class<?> getPacketClassFromID(int packetID, boolean forceVanilla) {
|
||||||
return MinecraftRegistry.getPacketClassFromID(packetID, forceVanilla);
|
return PacketRegistry.getPacketClassFromID(packetID, forceVanilla);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes, this is crazy.
|
// Yes, this is crazy.
|
||||||
@ -823,7 +825,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
|
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
|
||||||
*/
|
*/
|
||||||
public static Set<Integer> getServerPackets() throws FieldAccessException {
|
public static Set<Integer> getServerPackets() throws FieldAccessException {
|
||||||
return MinecraftRegistry.getServerPackets();
|
return PacketRegistry.getServerPackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -832,7 +834,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
* @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft.
|
* @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft.
|
||||||
*/
|
*/
|
||||||
public static Set<Integer> getClientPackets() throws FieldAccessException {
|
public static Set<Integer> getClientPackets() throws FieldAccessException {
|
||||||
return MinecraftRegistry.getClientPackets();
|
return PacketRegistry.getClientPackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,7 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
|
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
|
||||||
import com.comphenix.protocol.reflect.compiler.CompileListener;
|
import com.comphenix.protocol.reflect.compiler.CompileListener;
|
||||||
@ -46,7 +47,7 @@ public class StructureCache {
|
|||||||
*/
|
*/
|
||||||
public static Object newPacket(int id) {
|
public static Object newPacket(int id) {
|
||||||
try {
|
try {
|
||||||
return MinecraftRegistry.getPacketClassFromID(id, true).newInstance();
|
return PacketRegistry.getPacketClassFromID(id, true).newInstance();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@ -82,7 +83,7 @@ public class StructureCache {
|
|||||||
*/
|
*/
|
||||||
public static StructureModifier<Object> getStructure(Class<?> packetType, boolean compile) {
|
public static StructureModifier<Object> getStructure(Class<?> packetType, boolean compile) {
|
||||||
// Get the ID from the class
|
// Get the ID from the class
|
||||||
return getStructure(MinecraftRegistry.getPacketID(packetType), compile);
|
return getStructure(PacketRegistry.getPacketID(packetType), compile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +100,7 @@ public class StructureCache {
|
|||||||
if (result == null) {
|
if (result == null) {
|
||||||
// Use the vanilla class definition
|
// Use the vanilla class definition
|
||||||
final StructureModifier<Object> value = new StructureModifier<Object>(
|
final StructureModifier<Object> value = new StructureModifier<Object>(
|
||||||
MinecraftRegistry.getPacketClassFromID(id, true), MinecraftReflection.getPacketClass(), true);
|
PacketRegistry.getPacketClassFromID(id, true), MinecraftReflection.getPacketClass(), true);
|
||||||
|
|
||||||
result = structureModifiers.putIfAbsent(id, value);
|
result = structureModifiers.putIfAbsent(id, value);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.comphenix.protocol.injector;
|
package com.comphenix.protocol.injector.packet;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -33,6 +33,7 @@ import net.sf.cglib.proxy.Enhancer;
|
|||||||
import com.comphenix.protocol.error.ErrorReporter;
|
import com.comphenix.protocol.error.ErrorReporter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||||
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;
|
||||||
@ -43,7 +44,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||||||
*
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
class PacketInjector {
|
public class PacketInjector {
|
||||||
|
|
||||||
// The "put" method that associates a packet ID with a packet class
|
// The "put" method that associates a packet ID with a packet class
|
||||||
private static Method putMethod;
|
private static Method putMethod;
|
||||||
@ -118,10 +119,10 @@ class PacketInjector {
|
|||||||
// * Object removeObject(int par1)
|
// * Object removeObject(int par1)
|
||||||
|
|
||||||
// So, we'll use the classMapToInt registry instead.
|
// So, we'll use the classMapToInt registry instead.
|
||||||
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
|
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
|
||||||
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
|
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
|
||||||
Map<Class, Integer> registry = MinecraftRegistry.getPacketToID();
|
Map<Class, Integer> registry = PacketRegistry.getPacketToID();
|
||||||
Class old = MinecraftRegistry.getPacketClassFromID(packetID);
|
Class old = PacketRegistry.getPacketClassFromID(packetID);
|
||||||
|
|
||||||
// If this packet is not known
|
// If this packet is not known
|
||||||
if (old == null) {
|
if (old == null) {
|
||||||
@ -167,14 +168,14 @@ class PacketInjector {
|
|||||||
if (!hasPacketHandler(packetID))
|
if (!hasPacketHandler(packetID))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Map<Class, Integer> registry = MinecraftRegistry.getPacketToID();
|
Map<Class, Integer> registry = PacketRegistry.getPacketToID();
|
||||||
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
|
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
|
||||||
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
|
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
|
||||||
|
|
||||||
// Use the old class definition
|
// Use the old class definition
|
||||||
try {
|
try {
|
||||||
Class old = previous.get(packetID);
|
Class old = previous.get(packetID);
|
||||||
Class proxy = MinecraftRegistry.getPacketClassFromID(packetID);
|
Class proxy = PacketRegistry.getPacketClassFromID(packetID);
|
||||||
|
|
||||||
putMethod.invoke(intHashMap, packetID, old);
|
putMethod.invoke(intHashMap, packetID, old);
|
||||||
previous.remove(packetID);
|
previous.remove(packetID);
|
||||||
@ -194,11 +195,11 @@ class PacketInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPacketHandler(int packetID) {
|
public boolean hasPacketHandler(int packetID) {
|
||||||
return MinecraftRegistry.getPreviousPackets().containsKey(packetID);
|
return PacketRegistry.getPreviousPackets().containsKey(packetID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getPacketHandlers() {
|
public Set<Integer> getPacketHandlers() {
|
||||||
return MinecraftRegistry.getPreviousPackets().keySet();
|
return PacketRegistry.getPreviousPackets().keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from the ReadPacketModified monitor
|
// Called from the ReadPacketModified monitor
|
||||||
@ -234,8 +235,8 @@ class PacketInjector {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public synchronized void cleanupAll() {
|
public synchronized void cleanupAll() {
|
||||||
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
|
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
|
||||||
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
|
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
|
||||||
|
|
||||||
// Remove every packet handler
|
// Remove every packet handler
|
||||||
for (Integer id : previous.keySet().toArray(new Integer[0])) {
|
for (Integer id : previous.keySet().toArray(new Integer[0])) {
|
@ -15,7 +15,7 @@
|
|||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.comphenix.protocol.injector;
|
package com.comphenix.protocol.injector.packet;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -33,12 +33,12 @@ import com.google.common.base.Objects;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static registries in Minecraft.
|
* Static packet registry in Minecraft.
|
||||||
*
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
class MinecraftRegistry {
|
public class PacketRegistry {
|
||||||
|
|
||||||
// Fuzzy reflection
|
// Fuzzy reflection
|
||||||
private static FuzzyReflection packetRegistry;
|
private static FuzzyReflection packetRegistry;
|
@ -15,7 +15,7 @@
|
|||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.comphenix.protocol.injector;
|
package com.comphenix.protocol.injector.packet;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
In neuem Issue referenzieren
Einen Benutzer sperren