Skip to content

Commit

Permalink
Moved packet-related classes to a seperate package.
Browse files Browse the repository at this point in the history
This is backwards compatible because they were all package private.
  • Loading branch information
aadnk committed Feb 3, 2013
1 parent 3219dee commit 6cf3307
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -114,7 +115,7 @@ public PacketConstructor withPacket(int id, Object[] values) {
}
}

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);
Expand Down
Expand Up @@ -51,6 +51,8 @@
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;
Expand Down Expand Up @@ -184,8 +186,8 @@ public boolean apply(@Nullable GamePhase phase) {

// 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);
}
Expand Down Expand Up @@ -692,22 +694,22 @@ public int getPacketID(Object packet) {
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.
Expand Down Expand Up @@ -823,7 +825,7 @@ public Object intercept(Object obj, Method method, Object[] args,
* @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();
}

/**
Expand All @@ -832,7 +834,7 @@ public static Set<Integer> getServerPackets() throws FieldAccessException {
* @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();
}

/**
Expand Down
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -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) {
Expand Down Expand Up @@ -82,7 +83,7 @@ public static StructureModifier<Object> getStructure(Class<?> packetType) {
*/
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);
}

/**
Expand All @@ -99,7 +100,7 @@ public static StructureModifier<Object> getStructure(int id, boolean compile) {
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);

Expand Down
Expand Up @@ -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;
Expand All @@ -33,6 +33,7 @@
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;
Expand All @@ -43,7 +44,7 @@
*
* @author Kristian
*/
class PacketInjector {
public class PacketInjector {

// The "put" method that associates a packet ID with a packet class
private static Method putMethod;
Expand Down Expand Up @@ -118,10 +119,10 @@ public boolean addPacketHandler(int packetID) {
// * 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) {
Expand Down Expand Up @@ -167,14 +168,14 @@ public boolean removePacketHandler(int packetID) {
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);
Expand All @@ -194,11 +195,11 @@ public boolean removePacketHandler(int packetID) {
}

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
Expand Down Expand Up @@ -234,8 +235,8 @@ public PacketEvent packetRecieved(PacketContainer packet, Player client) {

@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])) {
Expand Down
Expand Up @@ -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;
Expand All @@ -33,12 +33,12 @@
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;
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 6cf3307

Please sign in to comment.