From 6cf3307a3b7379e20f9e740452edb79ef5e3cccb Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 3 Feb 2013 19:24:39 +0100 Subject: [PATCH] Moved packet-related classes to a seperate package. This is backwards compatible because they were all package private. --- .../protocol/injector/PacketConstructor.java | 3 +- .../injector/PacketFilterManager.java | 18 +++++++----- .../protocol/injector/StructureCache.java | 7 +++-- .../injector/{ => packet}/PacketInjector.java | 29 ++++++++++--------- .../PacketRegistry.java} | 6 ++-- .../{ => packet}/ReadPacketModifier.java | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-) rename ProtocolLib/src/main/java/com/comphenix/protocol/injector/{ => packet}/PacketInjector.java (89%) rename ProtocolLib/src/main/java/com/comphenix/protocol/injector/{MinecraftRegistry.java => packet/PacketRegistry.java} (98%) rename ProtocolLib/src/main/java/com/comphenix/protocol/injector/{ => packet}/ReadPacketModifier.java (99%) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketConstructor.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketConstructor.java index 3d138a13..ce5f5b1f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketConstructor.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketConstructor.java @@ -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); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java index e43921ef..c3a56fce 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java @@ -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 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 getClientPackets() throws FieldAccessException { - return MinecraftRegistry.getClientPackets(); + return PacketRegistry.getClientPackets(); } /** diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/StructureCache.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/StructureCache.java index b76f2179..d5455e9f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/StructureCache.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/StructureCache.java @@ -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 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 value = new StructureModifier( - MinecraftRegistry.getPacketClassFromID(id, true), MinecraftReflection.getPacketClass(), true); + PacketRegistry.getPacketClassFromID(id, true), MinecraftReflection.getPacketClass(), true); result = structureModifiers.putIfAbsent(id, value); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java similarity index 89% rename from ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketInjector.java rename to ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java index 095350a2..1911907e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java @@ -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 overwritten = MinecraftRegistry.getOverwrittenPackets(); - Map previous = MinecraftRegistry.getPreviousPackets(); - Map registry = MinecraftRegistry.getPacketToID(); - Class old = MinecraftRegistry.getPacketClassFromID(packetID); + Map overwritten = PacketRegistry.getOverwrittenPackets(); + Map previous = PacketRegistry.getPreviousPackets(); + Map 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 registry = MinecraftRegistry.getPacketToID(); - Map previous = MinecraftRegistry.getPreviousPackets(); - Map overwritten = MinecraftRegistry.getOverwrittenPackets(); + Map registry = PacketRegistry.getPacketToID(); + Map previous = PacketRegistry.getPreviousPackets(); + Map 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 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 overwritten = MinecraftRegistry.getOverwrittenPackets(); - Map previous = MinecraftRegistry.getPreviousPackets(); + Map overwritten = PacketRegistry.getOverwrittenPackets(); + Map previous = PacketRegistry.getPreviousPackets(); // Remove every packet handler for (Integer id : previous.keySet().toArray(new Integer[0])) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java similarity index 98% rename from ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java rename to ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java index 15561e8f..73f4e587 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/MinecraftRegistry.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java @@ -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; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ReadPacketModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java similarity index 99% rename from ProtocolLib/src/main/java/com/comphenix/protocol/injector/ReadPacketModifier.java rename to ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java index ceb702c6..3c7b897a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ReadPacketModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java @@ -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;