Moved packet-related classes to a seperate package.

This is backwards compatible because they were all package private.
This commit is contained in:
Kristian S. Stangeland 2013-02-03 19:24:39 +01:00
parent 3219deed79
commit 6cf3307a3b
6 changed files with 35 additions and 30 deletions

View File

@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.google.common.collect.ImmutableList;
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)
throw new IllegalArgumentException("Could not find a packet by the id " + id);

View File

@ -51,6 +51,8 @@ import com.comphenix.protocol.async.AsyncFilterManager;
import com.comphenix.protocol.async.AsyncMarker;
import com.comphenix.protocol.error.ErrorReporter;
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.reflect.FieldAccessException;
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
try {
this.serverPackets = MinecraftRegistry.getServerPackets();
this.clientPackets = MinecraftRegistry.getClientPackets();
this.serverPackets = PacketRegistry.getServerPackets();
this.clientPackets = PacketRegistry.getClientPackets();
} catch (FieldAccessException 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))
throw new IllegalArgumentException("The given object " + packet + " is not a packet.");
return MinecraftRegistry.getPacketToID().get(packet.getClass());
return PacketRegistry.getPacketToID().get(packet.getClass());
}
@Override
public void registerPacketClass(Class<?> clazz, int packetID) {
MinecraftRegistry.getPacketToID().put(clazz, packetID);
PacketRegistry.getPacketToID().put(clazz, packetID);
}
@Override
public void unregisterPacketClass(Class<?> clazz) {
MinecraftRegistry.getPacketToID().remove(clazz);
PacketRegistry.getPacketToID().remove(clazz);
}
@Override
public Class<?> getPacketClassFromID(int packetID, boolean forceVanilla) {
return MinecraftRegistry.getPacketClassFromID(packetID, forceVanilla);
return PacketRegistry.getPacketClassFromID(packetID, forceVanilla);
}
// 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.
*/
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.
*/
public static Set<Integer> getClientPackets() throws FieldAccessException {
return MinecraftRegistry.getClientPackets();
return PacketRegistry.getClientPackets();
}
/**

View File

@ -22,6 +22,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
import com.comphenix.protocol.reflect.compiler.CompileListener;
@ -46,7 +47,7 @@ public class StructureCache {
*/
public static Object newPacket(int id) {
try {
return MinecraftRegistry.getPacketClassFromID(id, true).newInstance();
return PacketRegistry.getPacketClassFromID(id, true).newInstance();
} catch (InstantiationException e) {
return null;
} catch (IllegalAccessException e) {
@ -82,7 +83,7 @@ public class StructureCache {
*/
public static StructureModifier<Object> getStructure(Class<?> packetType, boolean compile) {
// 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) {
// Use the vanilla class definition
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);

View File

@ -15,7 +15,7 @@
* 02111-1307 USA
*/
package com.comphenix.protocol.injector;
package com.comphenix.protocol.injector.packet;
import java.io.DataInputStream;
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.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.ListenerInvoker;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection;
@ -43,7 +44,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
*
* @author Kristian
*/
class PacketInjector {
public class PacketInjector {
// The "put" method that associates a packet ID with a packet class
private static Method putMethod;
@ -118,10 +119,10 @@ class PacketInjector {
// * Object removeObject(int par1)
// So, we'll use the classMapToInt registry instead.
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
Map<Class, Integer> registry = MinecraftRegistry.getPacketToID();
Class old = MinecraftRegistry.getPacketClassFromID(packetID);
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
Map<Class, Integer> registry = PacketRegistry.getPacketToID();
Class old = PacketRegistry.getPacketClassFromID(packetID);
// If this packet is not known
if (old == null) {
@ -167,14 +168,14 @@ class PacketInjector {
if (!hasPacketHandler(packetID))
return false;
Map<Class, Integer> registry = MinecraftRegistry.getPacketToID();
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
Map<Class, Integer> registry = PacketRegistry.getPacketToID();
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
// Use the old class definition
try {
Class old = previous.get(packetID);
Class proxy = MinecraftRegistry.getPacketClassFromID(packetID);
Class proxy = PacketRegistry.getPacketClassFromID(packetID);
putMethod.invoke(intHashMap, packetID, old);
previous.remove(packetID);
@ -194,11 +195,11 @@ class PacketInjector {
}
public boolean hasPacketHandler(int packetID) {
return MinecraftRegistry.getPreviousPackets().containsKey(packetID);
return PacketRegistry.getPreviousPackets().containsKey(packetID);
}
public Set<Integer> getPacketHandlers() {
return MinecraftRegistry.getPreviousPackets().keySet();
return PacketRegistry.getPreviousPackets().keySet();
}
// Called from the ReadPacketModified monitor
@ -234,8 +235,8 @@ class PacketInjector {
@SuppressWarnings("rawtypes")
public synchronized void cleanupAll() {
Map<Integer, Class> overwritten = MinecraftRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = MinecraftRegistry.getPreviousPackets();
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
// Remove every packet handler
for (Integer id : previous.keySet().toArray(new Integer[0])) {

View File

@ -15,7 +15,7 @@
* 02111-1307 USA
*/
package com.comphenix.protocol.injector;
package com.comphenix.protocol.injector.packet;
import java.lang.reflect.Field;
import java.util.HashMap;
@ -33,12 +33,12 @@ import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* Static registries in Minecraft.
* Static packet registry in Minecraft.
*
* @author Kristian
*/
@SuppressWarnings("rawtypes")
class MinecraftRegistry {
public class PacketRegistry {
// Fuzzy reflection
private static FuzzyReflection packetRegistry;

View File

@ -15,7 +15,7 @@
* 02111-1307 USA
*/
package com.comphenix.protocol.injector;
package com.comphenix.protocol.injector.packet;
import java.io.DataInputStream;
import java.lang.reflect.Method;