diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java
index 4a7d76d1..66bec542 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java
@@ -59,16 +59,36 @@ public interface AsynchronousManager {
/**
* Retrieves a immutable set containing the ID of the sent server packets that will be
* observed by the asynchronous listeners.
+ *
+ * Deprecated: Use {@link #getSendingTypes()} instead.
* @return Every filtered server packet.
*/
+ @Deprecated
public abstract Set getSendingFilters();
+ /**
+ * Retrieves a immutable set containing the types of the sent server packets that will be
+ * observed by the asynchronous listeners.
+ * @return Every filtered server packet.
+ */
+ public abstract Set getSendingTypes();
+
/**
* Retrieves a immutable set containing the ID of the recieved client packets that will be
+ *
+ * Deprecated: Use {@link #getReceivingTypes()} instead.
* observed by the asynchronous listeners.
* @return Every filtered client packet.
*/
+ @Deprecated
public abstract Set getReceivingFilters();
+
+ /**
+ * Retrieves a immutable set containing the types of the recieved client packets that will be
+ * observed by the asynchronous listeners.
+ * @return Every filtered client packet.
+ */
+ public abstract Set getReceivingTypes();
/**
* Determine if a given synchronous packet has asynchronous listeners.
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java b/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java
index 7afc45b7..239f94fa 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java
@@ -166,10 +166,13 @@ public final class Packets {
/**
* Determine if the given packet is a valid server packet in the current version of Minecraft.
+ *
+ * Use {@link PacketType#isSupported()} instead.
* @param packetID - the packet to test.
* @return TRUE if this packet is supported, FALSE otherwise.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/
+ @Deprecated
public static boolean isSupported(int packetID) throws FieldAccessException {
return PacketFilterManager.getServerPackets().contains(packetID);
}
@@ -179,6 +182,7 @@ public final class Packets {
* @return Every supported server packet.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/
+ @Deprecated
public static Set getSupported() throws FieldAccessException {
return PacketFilterManager.getServerPackets();
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolManager.java
index 72c5f36c..5d92c700 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolManager.java
@@ -132,11 +132,38 @@ public interface ProtocolManager extends PacketStream {
/**
* Constructs a new encapsulated Minecraft packet with the given ID.
+ *
+ * Deprecated: Use {@link #createPacket(PacketType)} instead.
* @param id - packet ID.
* @return New encapsulated Minecraft packet.
*/
+ @Deprecated
public PacketContainer createPacket(int id);
+ /**
+ * Constructs a new encapsulated Minecraft packet with the given ID.
+ * @param type - packet type.
+ * @return New encapsulated Minecraft packet.
+ */
+ public PacketContainer createPacket(PacketType type);
+
+ /**
+ * Constructs a new encapsulated Minecraft packet with the given ID.
+ *
+ * If set to true, the forceDefaults option will force the system to automatically
+ * give non-primitive fields in the packet sensible default values. For instance, certain
+ * packets - like Packet60Explosion - require a List or Set to be non-null. If the
+ * forceDefaults option is true, the List or Set will be automatically created.
+ *
+ * Deprecated: Use {@link #createPacket(PacketType, boolean)} instead.
+ *
+ * @param id - packet ID.
+ * @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
+ * @return New encapsulated Minecraft packet.
+ */
+ @Deprecated
+ public PacketContainer createPacket(int id, boolean forceDefaults);
+
/**
* Constructs a new encapsulated Minecraft packet with the given ID.
*
@@ -145,11 +172,11 @@ public interface ProtocolManager extends PacketStream {
* packets - like Packet60Explosion - require a List or Set to be non-null. If the
* forceDefaults option is true, the List or Set will be automatically created.
*
- * @param id - packet ID.
+ * @param type - packet type.
* @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
* @return New encapsulated Minecraft packet.
*/
- public PacketContainer createPacket(int id, boolean forceDefaults);
+ public PacketContainer createPacket(PacketType type, boolean forceDefaults);
/**
* Construct a packet using the special builtin Minecraft constructors.
@@ -199,16 +226,34 @@ public interface ProtocolManager extends PacketStream {
/**
* Retrieves a immutable set containing the ID of the sent server packets that will be observed by listeners.
+ *
+ * Deprecated: Use {@link #getSendingFilterTypes()} instead.
* @return Every filtered server packet.
*/
+ @Deprecated
public Set getSendingFilters();
+ /**
+ * Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.
+ * @return Every filtered server packet.
+ */
+ public Set getSendingFilterTypes();
+
/**
* Retrieves a immutable set containing the ID of the recieved client packets that will be observed by listeners.
+ *
+ * Deprecated: Use {@link #getReceivingFilterTypes()} instead.
* @return Every filtered client packet.
*/
+ @Deprecated
public Set getReceivingFilters();
+ /**
+ * Retrieves a immutable set containing the type of the recieved client packets that will be observed by listeners.
+ * @return Every filtered client packet.
+ */
+ public Set getReceivingFilterTypes();
+
/**
* Retrieve the current Minecraft version.
* @return The current version.
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
index a1254163..119048b1 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
@@ -29,6 +29,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.PacketStream;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ListeningWhitelist;
@@ -37,6 +38,7 @@ import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.PacketFilterManager;
import com.comphenix.protocol.injector.PrioritizedListener;
import com.comphenix.protocol.injector.SortedPacketListenerList;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@@ -181,7 +183,7 @@ public class AsyncFilterManager implements AsynchronousManager {
}
private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
- return whitelist != null && whitelist.getWhitelist().size() > 0;
+ return whitelist != null && whitelist.getTypes().size() > 0;
}
@Override
@@ -220,14 +222,14 @@ public class AsyncFilterManager implements AsynchronousManager {
// Just remove it from the queue(s)
if (hasValidWhitelist(listener.getSendingWhitelist())) {
- List removed = serverProcessingQueue.removeListener(handler, listener.getSendingWhitelist());
+ List removed = serverProcessingQueue.removeListener(handler, listener.getSendingWhitelist());
// We're already taking care of this, so don't do anything
playerSendingHandler.sendServerPackets(removed, synchronusOK);
}
if (hasValidWhitelist(listener.getReceivingWhitelist())) {
- List removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
+ List removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
playerSendingHandler.sendClientPackets(removed, synchronusOK);
}
}
@@ -279,11 +281,21 @@ public class AsyncFilterManager implements AsynchronousManager {
@Override
public Set getSendingFilters() {
+ return PacketRegistry.toLegacy(serverProcessingQueue.keySet());
+ }
+
+ @Override
+ public Set getReceivingTypes() {
return serverProcessingQueue.keySet();
}
@Override
public Set getReceivingFilters() {
+ return PacketRegistry.toLegacy(clientProcessingQueue.keySet());
+ }
+
+ @Override
+ public Set getSendingTypes() {
return clientProcessingQueue.keySet();
}
@@ -297,7 +309,7 @@ public class AsyncFilterManager implements AsynchronousManager {
@Override
public boolean hasAsynchronousListeners(PacketEvent packet) {
- Collection> list = getProcessingQueue(packet).getListener(packet.getPacketID());
+ Collection> list = getProcessingQueue(packet).getListener(packet.getPacketType());
return list != null && list.size() > 0;
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java
index 914ad105..e92a8d51 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java
@@ -336,7 +336,7 @@ public class AsyncListenerHandler {
if (whitelist == null)
return "";
else
- return Joiner.on(", ").join(whitelist.getWhitelist());
+ return Joiner.on(", ").join(whitelist.getTypes());
}
/**
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketProcessingQueue.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketProcessingQueue.java
index 3671ba0e..d3622e3b 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketProcessingQueue.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketProcessingQueue.java
@@ -23,7 +23,6 @@ import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.Semaphore;
-import com.comphenix.protocol.Packets;
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PrioritizedListener;
@@ -67,7 +66,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap> list = getListener(packet.getPacketID());
+ Collection> list = getListener(packet.getPacketType());
marker.incrementProcessingDelay();
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketSendingQueue.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketSendingQueue.java
index 39556f29..04dbdb05 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketSendingQueue.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PacketSendingQueue.java
@@ -26,6 +26,7 @@ import java.util.concurrent.PriorityBlockingQueue;
import org.bukkit.entity.Player;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PlayerLoggedOutException;
import com.comphenix.protocol.reflect.FieldAccessException;
@@ -106,15 +107,14 @@ abstract class PacketSendingQueue {
* @param packetsRemoved - packets that no longer have any listeners.
* @param onMainThread - whether or not this is occuring on the main thread.
*/
- public synchronized void signalPacketUpdate(List packetsRemoved, boolean onMainThread) {
-
- Set lookup = new HashSet(packetsRemoved);
+ public synchronized void signalPacketUpdate(List packetsRemoved, boolean onMainThread) {
+ Set lookup = new HashSet(packetsRemoved);
// Note that this is O(n), so it might be expensive
for (PacketEventHolder holder : sendingQueue) {
PacketEvent event = holder.getEvent();
- if (lookup.contains(event.getPacketID())) {
+ if (lookup.contains(event.getPacketType())) {
event.getAsyncMarker().setProcessed(true);
}
}
@@ -280,8 +280,8 @@ abstract class PacketSendingQueue {
} catch (PlayerLoggedOutException e) {
System.out.println(String.format(
- "[ProtocolLib] Warning: Dropped packet index %s of ID %s",
- marker.getOriginalSendingIndex(), event.getPacketID()
+ "[ProtocolLib] Warning: Dropped packet index %s of type %s",
+ marker.getOriginalSendingIndex(), event.getPacketType()
));
} catch (IOException e) {
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java
index 6954504e..f07efb80 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java
@@ -26,6 +26,7 @@ import java.util.concurrent.ThreadFactory;
import org.bukkit.entity.Player;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.concurrency.ConcurrentPlayerMap;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.PacketEvent;
@@ -172,13 +173,13 @@ class PlayerSendingHandler {
/**
* Immediately send every server packet with the given list of IDs.
- * @param ids - ID of every packet to send immediately.
+ * @param types - types of every packet to send immediately.
* @param synchronusOK - whether or not we're running on the main thread.
*/
- public void sendServerPackets(List ids, boolean synchronusOK) {
+ public void sendServerPackets(List types, boolean synchronusOK) {
if (!cleaningUp) {
for (QueueContainer queue : playerSendingQueues.values()) {
- queue.getServerQueue().signalPacketUpdate(ids, synchronusOK);
+ queue.getServerQueue().signalPacketUpdate(types, synchronusOK);
}
}
}
@@ -188,10 +189,10 @@ class PlayerSendingHandler {
* @param ids - ID of every packet to send immediately.
* @param synchronusOK - whether or not we're running on the main thread.
*/
- public void sendClientPackets(List ids, boolean synchronusOK) {
+ public void sendClientPackets(List types, boolean synchronusOK) {
if (!cleaningUp) {
for (QueueContainer queue : playerSendingQueues.values()) {
- queue.getClientQueue().signalPacketUpdate(ids, synchronusOK);
+ queue.getClientQueue().signalPacketUpdate(types, synchronusOK);
}
}
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/AbstractConcurrentListenerMultimap.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/AbstractConcurrentListenerMultimap.java
index 826e6b0c..26dc08f0 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/AbstractConcurrentListenerMultimap.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/AbstractConcurrentListenerMultimap.java
@@ -23,8 +23,8 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicReferenceArray;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListeningWhitelist;
import com.comphenix.protocol.injector.PrioritizedListener;
import com.google.common.collect.Iterables;
@@ -36,12 +36,10 @@ import com.google.common.collect.Iterables;
*/
public abstract class AbstractConcurrentListenerMultimap {
// The core of our map
- private AtomicReferenceArray>> arrayListeners;
- private ConcurrentMap>> mapListeners;
+ private ConcurrentMap>> mapListeners;
- public AbstractConcurrentListenerMultimap(int maximumPacketID) {
- arrayListeners = new AtomicReferenceArray>>(maximumPacketID + 1);
- mapListeners = new ConcurrentHashMap>>();
+ public AbstractConcurrentListenerMultimap() {
+ mapListeners = new ConcurrentHashMap>>();
}
/**
@@ -52,14 +50,14 @@ public abstract class AbstractConcurrentListenerMultimap {
public void addListener(TListener listener, ListeningWhitelist whitelist) {
PrioritizedListener prioritized = new PrioritizedListener(listener, whitelist.getPriority());
- for (Integer packetID : whitelist.getWhitelist()) {
- addListener(packetID, prioritized);
+ for (PacketType type : whitelist.getTypes()) {
+ addListener(type, prioritized);
}
}
// Add the listener to a specific packet notifcation list
- private void addListener(Integer packetID, PrioritizedListener listener) {
- SortedCopyOnWriteArray> list = arrayListeners.get(packetID);
+ private void addListener(PacketType type, PrioritizedListener listener) {
+ SortedCopyOnWriteArray> list = mapListeners.get(type);
// We don't want to create this for every lookup
if (list == null) {
@@ -68,11 +66,10 @@ public abstract class AbstractConcurrentListenerMultimap {
final SortedCopyOnWriteArray> value = new SortedCopyOnWriteArray>();
// We may end up creating multiple multisets, but we'll agree on which to use
- if (arrayListeners.compareAndSet(packetID, null, value)) {
- mapListeners.put(packetID, value);
+ list = mapListeners.putIfAbsent(type, value);
+
+ if (list == null) {
list = value;
- } else {
- list = arrayListeners.get(packetID);
}
}
@@ -86,12 +83,12 @@ public abstract class AbstractConcurrentListenerMultimap {
* @param whitelist - the packet whitelist that was used.
* @return Every packet ID that was removed due to no listeners.
*/
- public List removeListener(TListener listener, ListeningWhitelist whitelist) {
- List removedPackets = new ArrayList();
+ public List removeListener(TListener listener, ListeningWhitelist whitelist) {
+ List removedPackets = new ArrayList();
// Again, not terribly efficient. But adding or removing listeners should be a rare event.
- for (Integer packetID : whitelist.getWhitelist()) {
- SortedCopyOnWriteArray> list = arrayListeners.get(packetID);
+ for (PacketType type : whitelist.getTypes()) {
+ SortedCopyOnWriteArray> list = mapListeners.get(type);
// Remove any listeners
if (list != null) {
@@ -101,16 +98,13 @@ public abstract class AbstractConcurrentListenerMultimap {
list.remove(new PrioritizedListener(listener, whitelist.getPriority()));
if (list.size() == 0) {
- arrayListeners.set(packetID, null);
- mapListeners.remove(packetID);
- removedPackets.add(packetID);
+ mapListeners.remove(type);
+ removedPackets.add(type);
}
}
}
-
// Move on to the next
}
-
return removedPackets;
}
@@ -118,11 +112,11 @@ public abstract class AbstractConcurrentListenerMultimap {
* Retrieve the registered listeners, in order from the lowest to the highest priority.
*
* The returned list is thread-safe and doesn't require synchronization.
- * @param packetID - packet ID.
+ * @param type - packet type.
* @return Registered listeners.
*/
- public Collection> getListener(int packetID) {
- return arrayListeners.get(packetID);
+ public Collection> getListener(PacketType type) {
+ return mapListeners.get(type);
}
/**
@@ -134,10 +128,10 @@ public abstract class AbstractConcurrentListenerMultimap {
}
/**
- * Retrieve every registered packet ID:
- * @return Registered packet ID.
+ * Retrieve every registered packet type:
+ * @return Registered packet type.
*/
- public Set keySet() {
+ public Set keySet() {
return mapListeners.keySet();
}
@@ -145,8 +139,6 @@ public abstract class AbstractConcurrentListenerMultimap {
* Remove all packet listeners.
*/
protected void clearListeners() {
- arrayListeners = new AtomicReferenceArray<
- SortedCopyOnWriteArray>>(arrayListeners.length());
mapListeners.clear();
}
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java
new file mode 100644
index 00000000..0fa73e6c
--- /dev/null
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java
@@ -0,0 +1,106 @@
+package com.comphenix.protocol.concurrency;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
+
+import net.minecraft.util.com.google.common.collect.Maps;
+
+/**
+ * Represents a concurrent set of packet types.
+ * @author Kristian
+ */
+public class PacketTypeSet {
+ private Set types = Collections.newSetFromMap(Maps.newConcurrentMap());
+ private Set> classes = Collections.newSetFromMap(Maps., Boolean>newConcurrentMap());
+
+ public PacketTypeSet() {
+ // Do nothing
+ }
+
+ public PacketTypeSet(Collection extends PacketType> values) {
+ for (PacketType type : values) {
+ addType(type);
+ }
+ }
+
+ /**
+ * Add a particular type to the set.
+ * @param type - the type to add.
+ */
+ public synchronized void addType(PacketType type) {
+ types.add(type);
+ classes.add(getPacketClass(type));
+ }
+
+ /**
+ * Remove a particular type to the set.
+ * @param type - the type to remove.
+ */
+ public synchronized void removeType(PacketType type) {
+ types.remove(type);
+ classes.remove(getPacketClass(type));
+ }
+
+ /**
+ * Retrieve the packet class associated with a particular type.
+ * @param type - the packet type.
+ * @return The associated packet type.
+ */
+ protected Class> getPacketClass(PacketType type) {
+ return PacketRegistry.getPacketClassFromType(type);
+ }
+
+ /**
+ * Determine if the given packet type exists in the set.
+ * @param type - the type to find.
+ * @return TRUE if it does, FALSE otherwise.
+ */
+ public boolean contains(PacketType type) {
+ return types.contains(type);
+ }
+
+ /**
+ * Determine if a packet type with the given packet class exists in the set.
+ * @param packetClass - the class to find.
+ * @return TRUE if it does, FALSE otherwise.
+ */
+ public boolean contains(Class> packetClass) {
+ return classes.contains(packetClass);
+ }
+
+ /**
+ * Determine if the type of a packet is in the current set.
+ * @param packet - the packet.
+ * @return TRUE if it is, FALSE otherwise.
+ */
+ public boolean containsPacket(Object packet) {
+ if (packet == null)
+ return false;
+ return classes.contains(packet.getClass());
+ }
+
+ /**
+ * Retrieve a view of this packet type set.
+ * @return The packet type values.
+ */
+ public Set values() {
+ return types;
+ }
+
+ /**
+ * Retrieve the number of entries in the set.
+ * @return The number of entries.
+ */
+ public int size() {
+ return types.size();
+ }
+
+ public synchronized void clear() {
+ types.clear();
+ classes.clear();
+ }
+}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
index f163ac2a..0c3b2c5e 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
@@ -23,7 +23,9 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
@@ -40,74 +42,92 @@ public class ListeningWhitelist {
public static final ListeningWhitelist EMPTY_WHITELIST = new ListeningWhitelist(ListenerPriority.LOW);
private final ListenerPriority priority;
- private final Set whitelist;
private final GamePhase gamePhase;
private final Set options;
-
+ private final Set types;
+
+ // Cache whitelist
+ private transient Set intWhitelist;
+
private ListeningWhitelist(Builder builder) {
this.priority = builder.priority;
- this.whitelist = builder.whitelist;
+ this.types = builder.types;
this.gamePhase = builder.gamePhase;
this.options = builder.options;
}
/**
* Creates a packet whitelist for a given priority with a set of packet IDs.
+ *
+ * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority.
* @param whitelist - set of IDs to observe/enable.
*/
+ @Deprecated
public ListeningWhitelist(ListenerPriority priority, Set whitelist) {
this(priority, whitelist, GamePhase.PLAYING);
}
/**
* Creates a packet whitelist for a given priority with a set of packet IDs.
+ *
+ * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority.
* @param whitelist - set of IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on.
*/
+ @Deprecated
public ListeningWhitelist(ListenerPriority priority, Set whitelist, GamePhase gamePhase) {
this.priority = priority;
- this.whitelist = safeSet(whitelist);
+ this.types = PacketRegistry.toPacketTypes(safeSet(whitelist));
this.gamePhase = gamePhase;
this.options = EnumSet.noneOf(ListenerOptions.class);
}
/**
* Creates a packet whitelist of a given priority for a list of packets.
+ *
+ * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable.
*/
+ @Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer... whitelist) {
this.priority = priority;
- this.whitelist = Sets.newHashSet(whitelist);
+ this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = GamePhase.PLAYING;
this.options = EnumSet.noneOf(ListenerOptions.class);
}
/**
* Creates a packet whitelist for a given priority with a set of packet IDs.
+ *
+ * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on.
*/
+ @Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase) {
this.priority = priority;
- this.whitelist = Sets.newHashSet(whitelist);
+ this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = gamePhase;
this.options = EnumSet.noneOf(ListenerOptions.class);
}
/**
* Creates a packet whitelist for a given priority with a set of packet IDs and options.
+ *
+ * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on.
* @param options - every special option associated with this whitelist.
*/
+ @Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase, ListenerOptions... options) {
this.priority = priority;
- this.whitelist = Sets.newHashSet(whitelist);
+ this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = gamePhase;
this.options = safeEnumSet(Arrays.asList(options), ListenerOptions.class);
}
@@ -117,7 +137,7 @@ public class ListeningWhitelist {
* @return TRUE if there are any packets, FALSE otherwise.
*/
public boolean isEnabled() {
- return whitelist != null && whitelist.size() > 0;
+ return types != null && types.size() > 0;
}
/**
@@ -130,12 +150,25 @@ public class ListeningWhitelist {
/**
* Retrieves the list of packets that will be observed by the listeners.
+ *
+ * Deprecated: Use {@link #getTypes()} instead.
* @return Packet whitelist.
*/
+ @Deprecated
public Set getWhitelist() {
- return whitelist;
+ if (intWhitelist == null)
+ intWhitelist = PacketRegistry.toLegacy(types);
+ return intWhitelist;
}
+ /**
+ * Retrieves a set of the packets that will be observed by the listeners.
+ * @return Packet whitelist.
+ */
+ public Set getTypes() {
+ return types;
+ }
+
/**
* Retrieve which game phase this listener is active under.
* @return The active game phase.
@@ -154,7 +187,7 @@ public class ListeningWhitelist {
@Override
public int hashCode() {
- return Objects.hashCode(priority, whitelist, gamePhase, options);
+ return Objects.hashCode(priority, types, gamePhase, options);
}
/**
@@ -193,7 +226,7 @@ public class ListeningWhitelist {
if (obj instanceof ListeningWhitelist) {
final ListeningWhitelist other = (ListeningWhitelist) obj;
return Objects.equal(priority, other.priority)
- && Objects.equal(whitelist, other.whitelist)
+ && Objects.equal(types, other.types)
&& Objects.equal(gamePhase, other.gamePhase)
&& Objects.equal(options, other.options);
} else {
@@ -208,7 +241,7 @@ public class ListeningWhitelist {
else
return Objects.toStringHelper(this).
add("priority", priority).
- add("packets", whitelist).
+ add("packets", types).
add("gamephase", gamePhase).
add("options", options).
toString();
@@ -262,7 +295,7 @@ public class ListeningWhitelist {
*/
public static class Builder {
private ListenerPriority priority;
- private Set whitelist;
+ private Set types;
private GamePhase gamePhase;
private Set options;
@@ -274,7 +307,7 @@ public class ListeningWhitelist {
if (template != null) {
priority(template.getPriority());
gamePhase(template.getGamePhase());
- whitelist(template.getWhitelist());
+ types(template.getTypes());
options(template.getOptions());
}
}
@@ -289,13 +322,84 @@ public class ListeningWhitelist {
return this;
}
+ /**
+ * Set the priority of the whitelist to monitor.
+ * @return This builder, for chaining.
+ */
+ public Builder monitor() {
+ return priority(ListenerPriority.MONITOR);
+ }
+
+ /**
+ * Set the priority of the whitelist to normal.
+ * @return This builder, for chaining.
+ */
+ public Builder normal() {
+ return priority(ListenerPriority.NORMAL);
+ }
+
+ /**
+ * Set the priority of the whitelist to lowest.
+ * @return This builder, for chaining.
+ */
+ public Builder lowest() {
+ return priority(ListenerPriority.LOWEST);
+ }
+
+ /**
+ * Set the priority of the whitelist to low.
+ * @return This builder, for chaining.
+ */
+ public Builder low() {
+ return priority(ListenerPriority.LOW);
+ }
+
+ /**
+ * Set the priority of the whitelist to highest.
+ * @return This builder, for chaining.
+ */
+ public Builder highest() {
+ return priority(ListenerPriority.HIGHEST);
+ }
+
+ /**
+ * Set the priority of the whitelist to high.
+ * @return This builder, for chaining.
+ */
+ public Builder high() {
+ return priority(ListenerPriority.HIGH);
+ }
+
/**
* Set the whitelist of packet IDs to copy when constructing new whitelists.
+ *
+ * Deprecated: Use {@link #types(Collection)} instead.
* @param whitelist - the whitelist of packets.
* @return This builder, for chaining.
*/
+ @Deprecated
public Builder whitelist(Collection whitelist) {
- this.whitelist = safeSet(whitelist);
+ this.types = PacketRegistry.toPacketTypes(safeSet(whitelist));
+ return this;
+ }
+
+ /**
+ * Set the whitelist of packet types to copy when constructing new whitelists.
+ * @param types - the whitelist of packets.
+ * @return This builder, for chaining.
+ */
+ public Builder types(PacketType... types) {
+ this.types = safeSet(Sets.newHashSet(types));
+ return this;
+ }
+
+ /**
+ * Set the whitelist of packet types to copy when constructing new whitelists.
+ * @param types - the whitelist of packets.
+ * @return This builder, for chaining.
+ */
+ public Builder types(Collection types) {
+ this.types = safeSet(types);
return this;
}
@@ -309,6 +413,14 @@ public class ListeningWhitelist {
return this;
}
+ /**
+ * Set the gamephase to {@link GamePhase#BOTH}.
+ * @return This builder, for chaining.
+ */
+ public Builder gamePhaseBoth() {
+ return gamePhase(GamePhase.BOTH);
+ }
+
/**
* Set the options to copy when constructing new whitelists.
* @param options - the options.
@@ -319,6 +431,16 @@ public class ListeningWhitelist {
return this;
}
+ /**
+ * Set the options to copy when constructing new whitelists.
+ * @param options - the options array.
+ * @return This builder, for chaining.
+ */
+ public Builder options(ListenerOptions[] serverOptions) {
+ this.options = safeSet(Sets.newHashSet(serverOptions));
+ return this;
+ }
+
/**
* Construct a new whitelist from the values in this builder.
* @return The new whitelist.
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
index 358c6bd0..ae535b83 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
@@ -28,6 +28,7 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.ListeningWhitelist;
import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.GamePhase;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FieldAccessException;
/**
@@ -49,15 +50,16 @@ public abstract class MonitorAdapter implements PacketListener {
initialize(plugin, side, logger);
}
+ @SuppressWarnings("deprecation")
private void initialize(Plugin plugin, ConnectionSide side, Logger logger) {
this.plugin = plugin;
// Recover in case something goes wrong
try {
if (side.isForServer())
- this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getSupported(), GamePhase.BOTH);
+ this.sending = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getServerPacketTypes()).gamePhaseBoth().build();
if (side.isForClient())
- this.receiving = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Client.getSupported(), GamePhase.BOTH);
+ this.receiving = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getClientPacketTypes()).gamePhaseBoth().build();
} catch (FieldAccessException e) {
if (side.isForServer())
this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getRegistry().values(), GamePhase.BOTH);
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
index 5db2bdf8..2dfbf4a4 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
@@ -22,9 +22,13 @@ import java.util.Set;
import javax.annotation.Nonnull;
+import net.minecraft.util.com.google.common.collect.Sets;
+
import org.bukkit.plugin.Plugin;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -53,21 +57,27 @@ public abstract class PacketAdapter implements PacketListener {
/**
* Initialize a packet listener with default priority.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, packets);
}
/**
* Initialize a packet listener for a single connection side.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Set packets) {
this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets.toArray(new Integer[0]));
}
@@ -76,11 +86,14 @@ public abstract class PacketAdapter implements PacketListener {
* Initialize a packet listener for a single connection side.
*
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Set packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, packets.toArray(new Integer[0]));
}
@@ -89,45 +102,57 @@ public abstract class PacketAdapter implements PacketListener {
* Initialize a packet listener for a single connection side.
*
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority.
* @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Set packets) {
this(plugin, connectionSide, listenerPriority, gamePhase, packets.toArray(new Integer[0]));
}
/**
* Initialize a packet listener for a single connection side.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Integer... packets) {
this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets);
}
/**
* Initialize a packet listener for a single connection side.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param options - which listener options to use.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerOptions[] options, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, GamePhase.PLAYING, options, packets);
}
/**
* Initialize a packet listener for a single connection side.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, packets);
}
@@ -136,12 +161,15 @@ public abstract class PacketAdapter implements PacketListener {
* Initialize a packet listener for a single connection side.
*
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority.
* @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for.
*/
+ @Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Integer... packets) {
this(plugin, connectionSide, listenerPriority, gamePhase, new ListenerOptions[0], packets);
}
@@ -152,6 +180,8 @@ public abstract class PacketAdapter implements PacketListener {
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
*
* Listener options must be specified in order for {@link NetworkMarker#getInputBuffer()} to function correctly.
+ *
+ * Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority.
@@ -159,7 +189,21 @@ public abstract class PacketAdapter implements PacketListener {
* @param options - which listener options to use.
* @param packets - the packet IDs the listener is looking for.
*/
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, ListenerOptions[] options, Integer... packets) {
+ @Deprecated
+ public PacketAdapter(
+ Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
+ GamePhase gamePhase, ListenerOptions[] options, Integer... packets) {
+
+ this(plugin, connectionSide, listenerPriority, gamePhase, options,
+ PacketRegistry.toPacketTypes(Sets.newHashSet(packets)).toArray(new PacketType[0])
+ );
+ }
+
+ // For internal use only
+ private PacketAdapter(
+ Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
+ GamePhase gamePhase, ListenerOptions[] options, PacketType... packets) {
+
if (plugin == null)
throw new IllegalArgumentException("plugin cannot be null");
if (connectionSide == null)
@@ -184,9 +228,20 @@ public abstract class PacketAdapter implements PacketListener {
// Add whitelists
if (connectionSide.isForServer())
- sendingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, serverOptions);
+ sendingWhitelist = ListeningWhitelist.newBuilder().
+ priority(listenerPriority).
+ types(packets).
+ gamePhase(gamePhase).
+ options(serverOptions).
+ build();
+
if (connectionSide.isForClient())
- receivingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, clientOptions);
+ receivingWhitelist = ListeningWhitelist.newBuilder().
+ priority(listenerPriority).
+ types(packets).
+ gamePhase(gamePhase).
+ options(clientOptions).
+ build();
this.plugin = plugin;
this.connectionSide = connectionSide;
@@ -292,7 +347,7 @@ public abstract class PacketAdapter implements PacketListener {
public static class AdapterParameteters {
private Plugin plugin;
private ConnectionSide connectionSide;
- private Integer[] packets;
+ private PacketType[] packets;
// Parameters with default values
private GamePhase gamePhase = GamePhase.PLAYING;
@@ -391,11 +446,20 @@ public abstract class PacketAdapter implements PacketListener {
* Set the packet IDs of the packets the listener is looking for.
*
* This parameter is required.
+ *
+ * Deprecated: Use {@link #types(PacketType...)} instead.
* @param packets - the packet IDs to look for.
* @return This builder, for chaining.
*/
+ @Deprecated
public AdapterParameteters packets(@Nonnull Integer... packets) {
- this.packets = Preconditions.checkNotNull(packets, "packets cannot be NULL");
+ Preconditions.checkNotNull(packets, "packets cannot be NULL");
+ PacketType[] types = new PacketType[packets.length];
+
+ for (int i = 0; i < types.length; i++) {
+ types[i] = PacketType.findLegacy(packets[i]);
+ }
+ this.packets = types;
return this;
}
@@ -406,9 +470,33 @@ public abstract class PacketAdapter implements PacketListener {
* @param packets - a set of the packet IDs to look for.
* @return This builder, for chaining.
*/
+ @Deprecated
public AdapterParameteters packets(@Nonnull Set packets) {
return packets(packets.toArray(new Integer[0]));
}
+
+ /**
+ * Set the packet types the listener is looking for.
+ *
+ * This parameter is required.
+ * @param packets
+ * @return This builder, for chaining.
+ */
+ public AdapterParameteters types(@Nonnull PacketType... packets) {
+ this.packets = Preconditions.checkNotNull(packets, "packets cannot be NULL");
+ return this;
+ }
+
+ /**
+ * Set the packet types the listener is looking for.
+ *
+ * This parameter is required.
+ * @param packets
+ * @return This builder, for chaining.
+ */
+ public AdapterParameteters types(@Nonnull Set packets) {
+ return types(packets.toArray(new PacketType[0]));
+ }
}
/**
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java
index dab294de..dcba0728 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java
@@ -25,6 +25,7 @@ import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.base.Objects;
@@ -293,6 +294,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
}
@Override
+ @Deprecated
public PacketContainer createPacket(int id) {
if (delegate != null)
return delegate.createPacket(id);
@@ -300,6 +302,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
}
@Override
+ @Deprecated
public PacketContainer createPacket(int id, boolean forceDefaults) {
if (delegate != null) {
return delegate.createPacket(id);
@@ -337,6 +340,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
}
@Override
+ @Deprecated
public Set getSendingFilters() {
if (delegate != null) {
return delegate.getSendingFilters();
@@ -352,6 +356,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
}
@Override
+ @Deprecated
public Set getReceivingFilters() {
if (delegate != null) {
return delegate.getReceivingFilters();
@@ -365,6 +370,26 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
}
}
+ @Override
+ public PacketContainer createPacket(PacketType type) {
+ return createPacket(type.getLegacyId());
+ }
+
+ @Override
+ public PacketContainer createPacket(PacketType type, boolean forceDefaults) {
+ return createPacket(type.getLegacyId(), forceDefaults);
+ }
+
+ @Override
+ public Set getSendingFilterTypes() {
+ return PacketRegistry.toPacketTypes(getSendingFilters());
+ }
+
+ @Override
+ public Set getReceivingFilterTypes() {
+ return PacketRegistry.toPacketTypes(getReceivingFilters());
+ }
+
@Override
public void updateEntity(Entity entity, List observers) throws FieldAccessException {
if (delegate != null)
@@ -426,6 +451,4 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
delegate.close();
closed = true;
}
-
-
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ListenerInvoker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ListenerInvoker.java
index 4073d08a..f3992b21 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ListenerInvoker.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/ListenerInvoker.java
@@ -17,6 +17,7 @@
package com.comphenix.protocol.injector;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.packet.InterceptWritePacket;
@@ -47,6 +48,13 @@ public interface ListenerInvoker {
@Deprecated
public abstract int getPacketID(Object packet);
+ /**
+ * Retrieve the associated type of a packet.
+ * @param packet - the packet.
+ * @return The packet type.
+ */
+ public abstract PacketType getPacketType(Object packet);
+
/**
* Retrieve the object responsible for intercepting write packets.
* @return Object that intercepts write packets.
@@ -58,6 +66,7 @@ public interface ListenerInvoker {
* @param packetId - the packet to check.
* @return TRUE if it does, FALSE otherwise.
*/
+ @Deprecated
public boolean requireInputBuffer(int packetId);
/**
@@ -71,6 +80,7 @@ public interface ListenerInvoker {
* @param clazz - class to register.
* @param packetID - the the new associated packet ID.
*/
+ @Deprecated
public abstract void registerPacketClass(Class> clazz, int packetID);
/**
@@ -79,5 +89,6 @@ public interface ListenerInvoker {
* @param forceVanilla - whether or not to look for vanilla classes, not injected classes.
* @return The associated class.
*/
+ @Deprecated
public abstract Class> getPacketClassFromID(int packetID, boolean forceVanilla);
}
\ No newline at end of file
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 c7a0fcd4..e1d65c3e 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java
@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
+import net.minecraft.util.com.google.common.collect.Sets;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -49,11 +50,9 @@ import org.bukkit.plugin.PluginManager;
import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.async.AsyncFilterManager;
import com.comphenix.protocol.async.AsyncMarker;
-import com.comphenix.protocol.concurrency.IntegerSet;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
@@ -148,7 +147,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
private InterceptWritePacket interceptWritePacket;
// Whether or not a packet must be input buffered
- private volatile IntegerSet inputBufferedPackets = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1);
+ private volatile Set inputBufferedPackets = Sets.newHashSet();
// The two listener containers
private SortedPacketListenerList recievedListeners;
@@ -278,8 +277,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Attempt to load the list of server and client packets
try {
- knowsServerPackets = PacketRegistry.getServerPackets() != null;
- knowsClientPackets = PacketRegistry.getClientPackets() != null;
+ knowsServerPackets = PacketRegistry.getClientPacketTypes() != null;
+ knowsClientPackets = PacketRegistry.getServerPacketTypes() != null;
} catch (FieldAccessException e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_LOAD_PACKET_LIST).error(e));
}
@@ -375,7 +374,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
verifyWhitelist(listener, sending);
sendingListeners.addListener(listener, sending);
- enablePacketFilters(listener, ConnectionSide.SERVER_SIDE, sending.getWhitelist());
+ enablePacketFilters(listener, ConnectionSide.SERVER_SIDE, sending.getTypes());
// Make sure this is possible
playerInjection.checkListener(listener);
@@ -387,7 +386,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (hasReceiving) {
verifyWhitelist(listener, receiving);
recievedListeners.addListener(listener, receiving);
- enablePacketFilters(listener, ConnectionSide.CLIENT_SIDE, receiving.getWhitelist());
+ enablePacketFilters(listener, ConnectionSide.CLIENT_SIDE, receiving.getTypes());
}
if (hasReceiving)
incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE));
@@ -403,8 +402,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (!whitelist.getGamePhase().hasLogin() &&
!whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) {
- for (int id : whitelist.getWhitelist()) {
- if (loginPackets.isLoginPacket(id, side)) {
+ for (PacketType type : whitelist.getTypes()) {
+ if (loginPackets.isLoginPacket(type)) {
return GamePhase.BOTH;
}
}
@@ -416,21 +415,21 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* Invoked when we need to update the input buffer set.
*/
private void updateRequireInputBuffers() {
- IntegerSet updated = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1);
+ Set updated = Sets.newHashSet();
for (PacketListener listener : packetListeners) {
ListeningWhitelist whitelist = listener.getReceivingWhitelist();
// We only check the recieving whitelist
if (whitelist.getOptions().contains(ListenerOptions.INTERCEPT_INPUT_BUFFER)) {
- for (int id : whitelist.getWhitelist()) {
- updated.add(id);
+ for (PacketType type : whitelist.getTypes()) {
+ updated.add(type);
}
}
}
// Update it
this.inputBufferedPackets = updated;
- this.packetInjector.inputBuffersChanged(updated.toSet());
+ this.packetInjector.inputBuffersChanged(updated);
}
/**
@@ -484,10 +483,10 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @throws IllegalArgumentException If the whitelist is illegal.
*/
public static void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist) {
- for (Integer id : whitelist.getWhitelist()) {
- if (id >= 256 || id < 0) {
- throw new IllegalArgumentException(String.format("Invalid packet id %s in listener %s.",
- id, PacketAdapter.getPluginName(listener))
+ for (PacketType type : whitelist.getTypes()) {
+ if (type == null) {
+ throw new IllegalArgumentException(String.format("Packet type in in listener %s was NULL.",
+ PacketAdapter.getPluginName(listener))
);
}
}
@@ -498,8 +497,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (listener == null)
throw new IllegalArgumentException("listener cannot be NULL");
- List sendingRemoved = null;
- List receivingRemoved = null;
+ List sendingRemoved = null;
+ List receivingRemoved = null;
ListeningWhitelist sending = listener.getSendingWhitelist();
ListeningWhitelist receiving = listener.getReceivingWhitelist();
@@ -556,7 +555,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
@Override
public boolean requireInputBuffer(int packetId) {
- return inputBufferedPackets.contains(packetId);
+ return inputBufferedPackets.contains(PacketType.findLegacy(packetId));
}
/**
@@ -567,7 +566,6 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @param event - the evnet to broadcast.
*/
private void handlePacket(SortedPacketListenerList packetListeners, PacketEvent event, boolean sending) {
-
// By default, asynchronous packets are queued for processing
if (asyncFilterManager.hasAsynchronousListeners(event)) {
event.setAsyncMarker(asyncFilterManager.createAsyncMarker());
@@ -603,32 +601,32 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @param side - which side the event will arrive from.
* @param packets - the packet id(s).
*/
- private void enablePacketFilters(PacketListener listener, ConnectionSide side, Iterable packets) {
+ private void enablePacketFilters(PacketListener listener, ConnectionSide side, Iterable packets) {
if (side == null)
throw new IllegalArgumentException("side cannot be NULL.");
// Note the difference between unsupported and valid.
// Every packet ID between and including 0 - 255 is valid, but only a subset is supported.
- for (int packetID : packets) {
+ for (PacketType type : packets) {
// Only register server packets that are actually supported by Minecraft
if (side.isForServer()) {
// Note that we may update the packet list here
- if (!knowsServerPackets || PacketRegistry.getServerPackets().contains(packetID))
- playerInjection.addPacketHandler(packetID);
+ if (!knowsServerPackets || PacketRegistry.getServerPacketTypes().contains(type))
+ playerInjection.addPacketHandler(type);
else
reporter.reportWarning(this,
- Report.newBuilder(REPORT_UNSUPPORTED_SERVER_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), packetID)
+ Report.newBuilder(REPORT_UNSUPPORTED_SERVER_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), type)
);
}
// As above, only for client packets
if (side.isForClient() && packetInjector != null) {
- if (!knowsClientPackets || PacketRegistry.getClientPackets().contains(packetID))
- packetInjector.addPacketHandler(packetID);
+ if (!knowsClientPackets || PacketRegistry.getClientPacketTypes().contains(type))
+ packetInjector.addPacketHandler(type);
else
reporter.reportWarning(this,
- Report.newBuilder(REPORT_UNSUPPORTED_CLIENT_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), packetID)
+ Report.newBuilder(REPORT_UNSUPPORTED_CLIENT_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), type)
);
}
}
@@ -639,15 +637,15 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @param packets - the packet id(s).
* @param side - which side the event no longer should arrive from.
*/
- private void disablePacketFilters(ConnectionSide side, Iterable packets) {
+ private void disablePacketFilters(ConnectionSide side, Iterable packets) {
if (side == null)
throw new IllegalArgumentException("side cannot be NULL.");
- for (int packetID : packets) {
+ for (PacketType type : packets) {
if (side.isForServer())
- playerInjection.removePacketHandler(packetID);
+ playerInjection.removePacketHandler(type);
if (side.isForClient() && packetInjector != null)
- packetInjector.removePacketHandler(packetID);
+ packetInjector.removePacketHandler(type);
}
}
@@ -812,15 +810,27 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
packetInjector.setCancelled(mcPacket, true);
}
}
-
+
@Override
+ @Deprecated
public PacketContainer createPacket(int id) {
- return createPacket(id, true);
+ return createPacket(PacketType.findLegacy(id), true);
}
@Override
+ public PacketContainer createPacket(PacketType type) {
+ return createPacket(type, true);
+ }
+
+ @Override
+ @Deprecated
public PacketContainer createPacket(int id, boolean forceDefaults) {
- PacketContainer packet = new PacketContainer(id);
+ return createPacket(PacketType.findLegacy(id), forceDefaults);
+ }
+
+ @Override
+ public PacketContainer createPacket(PacketType type, boolean forceDefaults) {
+ PacketContainer packet = new PacketContainer(type);
// Use any default values if possible
if (forceDefaults) {
@@ -846,13 +856,23 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
}
@Override
+ @Deprecated
public Set getSendingFilters() {
- return playerInjection.getSendingFilters();
+ return PacketRegistry.toLegacy(playerInjection.getSendingFilters());
}
@Override
public Set getReceivingFilters() {
- return ImmutableSet.copyOf(packetInjector.getPacketHandlers());
+ return PacketRegistry.toLegacy(packetInjector.getPacketHandlers());
+ }
+ @Override
+ public Set getSendingFilterTypes() {
+ return Collections.unmodifiableSet(playerInjection.getSendingFilters());
+ }
+
+ @Override
+ public Set getReceivingFilterTypes() {
+ return Collections.unmodifiableSet(packetInjector.getPacketHandlers());
}
@Override
@@ -993,16 +1013,22 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
}
@Override
+ @Deprecated
public int getPacketID(Object packet) {
+ return getPacketType(packet).getLegacyId();
+ }
+
+ @Override
+ public PacketType getPacketType(Object packet) {
if (packet == null)
throw new IllegalArgumentException("Packet cannot be NULL.");
if (!MinecraftReflection.isPacketClass(packet))
throw new IllegalArgumentException("The given object " + packet + " is not a packet.");
- Integer id = PacketRegistry.getPacketToID().get(packet.getClass());
+ PacketType type = PacketRegistry.getPacketType(packet.getClass());
- if (id != null) {
- return id;
+ if (type != null) {
+ return type;
} else {
throw new IllegalArgumentException(
"Unable to find associated packet of " + packet + ": Lookup returned NULL.");
@@ -1010,16 +1036,19 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
}
@Override
+ @Deprecated
public void registerPacketClass(Class> clazz, int packetID) {
PacketRegistry.getPacketToID().put(clazz, packetID);
}
@Override
+ @Deprecated
public void unregisterPacketClass(Class> clazz) {
PacketRegistry.getPacketToID().remove(clazz);
}
@Override
+ @Deprecated
public Class> getPacketClassFromID(int packetID, boolean forceVanilla) {
return PacketRegistry.getPacketClassFromID(packetID, forceVanilla);
}
@@ -1115,6 +1144,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @return An immutable set of every known server packet.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/
+ @Deprecated
public static Set getServerPackets() throws FieldAccessException {
return PacketRegistry.getServerPackets();
}
@@ -1124,6 +1154,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @return An immutable set of every known client packet.
* @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft.
*/
+ @Deprecated
public static Set getClientPackets() throws FieldAccessException {
return PacketRegistry.getClientPackets();
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java
index b6633ba2..a9fc1741 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java
@@ -19,7 +19,6 @@ package com.comphenix.protocol.injector;
import java.util.Collection;
-import com.comphenix.protocol.Packets;
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ListenerPriority;
@@ -39,7 +38,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
private TimedListenerManager timedManager = TimedListenerManager.getInstance();
public SortedPacketListenerList() {
- super(Packets.MAXIMUM_PACKET_ID);
+ super();
}
/**
@@ -48,7 +47,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param event - the packet event to invoke.
*/
public void invokePacketRecieving(ErrorReporter reporter, PacketEvent event) {
- Collection> list = getListener(event.getPacketID());
+ Collection> list = getListener(event.getPacketType());
if (list == null)
return;
@@ -77,7 +76,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param priorityFilter - the required priority for a listener to be invoked.
*/
public void invokePacketRecieving(ErrorReporter reporter, PacketEvent event, ListenerPriority priorityFilter) {
- Collection> list = getListener(event.getPacketID());
+ Collection> list = getListener(event.getPacketType());
if (list == null)
return;
@@ -131,7 +130,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param event - the packet event to invoke.
*/
public void invokePacketSending(ErrorReporter reporter, PacketEvent event) {
- Collection> list = getListener(event.getPacketID());
+ Collection> list = getListener(event.getPacketType());
if (list == null)
return;
@@ -159,7 +158,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param priorityFilter - the required priority for a listener to be invoked.
*/
public void invokePacketSending(ErrorReporter reporter, PacketEvent event, ListenerPriority priorityFilter) {
- Collection> list = getListener(event.getPacketID());
+ Collection> list = getListener(event.getPacketType());
if (list == null)
return;
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
index 74736b51..09c44c51 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
@@ -10,7 +10,6 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
-import net.minecraft.util.com.google.common.base.Joiner;
import net.minecraft.util.io.netty.buffer.ByteBuf;
import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelHandler;
@@ -33,7 +32,6 @@ import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketOutputHandler;
-import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.injector.server.SocketInjector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.FuzzyReflection;
@@ -83,10 +81,10 @@ class ChannelInjector extends ByteToMessageDecoder {
/**
* Determine if we need the buffer data of a given client side packet.
- * @param packetId - the packet Id.
+ * @param packetClass - the packet class.
* @return TRUE if we do, FALSE otherwise.
*/
- public boolean includeBuffer(int packetId);
+ public boolean includeBuffer(Class> packetClass);
/**
* Retrieve the current error reporter.
@@ -326,10 +324,10 @@ class ChannelInjector extends ByteToMessageDecoder {
if (packets.size() > 0) {
Object input = packets.get(0);
- int id = PacketRegistry.getPacketID(input.getClass());
+ Class> packetClass = input.getClass();
NetworkMarker marker = null;
- if (channelListener.includeBuffer(id)) {
+ if (channelListener.includeBuffer(packetClass)) {
byteBuffer.resetReaderIndex();
marker = new NetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer));
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java
index 5567aa45..584419d1 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java
@@ -18,8 +18,8 @@ import net.minecraft.util.io.netty.channel.ChannelInboundHandler;
import net.minecraft.util.io.netty.channel.ChannelInboundHandlerAdapter;
import net.minecraft.util.io.netty.channel.ChannelInitializer;
-import com.comphenix.protocol.Packets;
-import com.comphenix.protocol.concurrency.IntegerSet;
+import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.concurrency.PacketTypeSet;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker;
@@ -28,6 +28,7 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.ListenerInvoker;
import com.comphenix.protocol.injector.netty.ChannelInjector.ChannelListener;
import com.comphenix.protocol.injector.packet.PacketInjector;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.injector.spigot.AbstractPacketInjector;
@@ -46,11 +47,11 @@ public class NettyProtocolInjector implements ChannelListener {
private List bootstrapFields = Lists.newArrayList();
// Different sending filters
- private IntegerSet queuedFilters = new IntegerSet(Packets.PACKET_COUNT);
- private IntegerSet reveivedFilters = new IntegerSet(Packets.PACKET_COUNT);
+ private PacketTypeSet queuedFilters = new PacketTypeSet();
+ private PacketTypeSet reveivedFilters = new PacketTypeSet();
// Which packets are buffered
- private Set bufferedPackets;
+ private PacketTypeSet bufferedPackets;
private ListenerInvoker invoker;
// Handle errors
@@ -172,14 +173,14 @@ public class NettyProtocolInjector implements ChannelListener {
@Override
public Object onPacketSending(ChannelInjector injector, Object packet, NetworkMarker marker) {
- Integer id = invoker.getPacketID(packet);
+ Class> clazz = packet.getClass();
- if (id != null && queuedFilters.contains(id)) {
+ if (queuedFilters.contains(clazz)) {
// Check for ignored packets
if (injector.unignorePacket(packet)) {
return packet;
}
- PacketContainer container = new PacketContainer(id, packet);
+ PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet);
PacketEvent event = packetQueued(container, injector.getPlayer());
if (!event.isCancelled()) {
@@ -195,14 +196,14 @@ public class NettyProtocolInjector implements ChannelListener {
@Override
public Object onPacketReceiving(ChannelInjector injector, Object packet, NetworkMarker marker) {
- Integer id = invoker.getPacketID(packet);
+ Class> clazz = packet.getClass();
- if (id != null && reveivedFilters.contains(id)) {
+ if (reveivedFilters.contains(clazz)) {
// Check for ignored packets
if (injector.unignorePacket(packet)) {
return packet;
}
- PacketContainer container = new PacketContainer(id, packet);
+ PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet);
PacketEvent event = packetReceived(container, injector.getPlayer(), marker);
if (!event.isCancelled()) {
@@ -216,8 +217,8 @@ public class NettyProtocolInjector implements ChannelListener {
}
@Override
- public boolean includeBuffer(int packetId) {
- return bufferedPackets.contains(packetId);
+ public boolean includeBuffer(Class> packetClass) {
+ return bufferedPackets.contains(packetClass);
}
/**
@@ -313,8 +314,8 @@ public class NettyProtocolInjector implements ChannelListener {
}
@Override
- public void inputBuffersChanged(Set set) {
- bufferedPackets = set;
+ public void inputBuffersChanged(Set set) {
+ bufferedPackets = new PacketTypeSet(set);
}
};
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/InterceptWritePacket.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/InterceptWritePacket.java
index 55448597..21f0107f 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/InterceptWritePacket.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/InterceptWritePacket.java
@@ -98,6 +98,7 @@ public class InterceptWritePacket {
return proxyClass;
}
+ @SuppressWarnings("deprecation")
private Class> getProxyClass(int packetId) {
Class> stored = proxyClasses.get(packetId);
@@ -119,6 +120,7 @@ public class InterceptWritePacket {
* Construct a new instance of the proxy object.
* @return New instance of proxy, or NULL if we failed.
*/
+ @SuppressWarnings("deprecation")
public Object constructProxy(Object proxyObject, PacketEvent event, NetworkMarker marker) {
Class> proxyClass = null;
@@ -141,6 +143,7 @@ public class InterceptWritePacket {
/**
* Invoked when the write packet proxy class should be removed.
*/
+ @SuppressWarnings("deprecation")
public void cleanup() {
// Remove all proxy classes from the registry
for (Class> stored : proxyClasses.values()) {
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java
index 78e2cb8f..7d633324 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketInjector.java
@@ -4,6 +4,7 @@ import java.util.Set;
import org.bukkit.entity.Player;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
@@ -28,37 +29,37 @@ public interface PacketInjector {
public abstract void setCancelled(Object packet, boolean cancelled);
/**
- * Start intercepting packets with the given packet ID.
- * @param packetID - the ID of the packets to start intercepting.
+ * Start intercepting packets with the given packet type.
+ * @param type - the type of the packets to start intercepting.
* @return TRUE if we didn't already intercept these packets, FALSE otherwise.
*/
- public abstract boolean addPacketHandler(int packetID);
+ public abstract boolean addPacketHandler(PacketType type);
/**
- * Stop intercepting packets with the given packet ID.
- * @param packetID - the ID of the packets to stop intercepting.
+ * Stop intercepting packets with the given packet type.
+ * @param type - the type of the packets to stop intercepting.
* @return TRUE if we successfuly stopped intercepting a given packet ID, FALSE otherwise.
*/
- public abstract boolean removePacketHandler(int packetID);
+ public abstract boolean removePacketHandler(PacketType type);
/**
- * Determine if packets with the given packet ID is being intercepted.
- * @param packetID - the packet ID to lookup.
+ * Determine if packets with the given packet type is being intercepted.
+ * @param type - the packet type to lookup.
* @return TRUE if we do, FALSE otherwise.
*/
- public abstract boolean hasPacketHandler(int packetID);
+ public abstract boolean hasPacketHandler(PacketType type);
/**
* Invoked when input buffers have changed.
* @param set - the new set of packets that require the read buffer.
*/
- public abstract void inputBuffersChanged(Set set);
+ public abstract void inputBuffersChanged(Set set);
/**
- * Retrieve every intercepted packet ID.
- * @return Every intercepted packet ID.
+ * Retrieve every intercepted packet type.
+ * @return Every intercepted packet type.
*/
- public abstract Set getPacketHandlers();
+ public abstract Set getPacketHandlers();
/**
* Let the packet listeners process the given packet.
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java
index 7758a873..e6a692af 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java
@@ -283,7 +283,7 @@ public class PacketRegistry {
* @param types - packet type.
* @return Set of integers.
*/
- private static Set toLegacy(Set types) {
+ public static Set toLegacy(Set types) {
Set result = Sets.newHashSet();
for (PacketType type : types)
@@ -296,7 +296,7 @@ public class PacketRegistry {
* @param types - legacy packet IDs.
* @return Set of packet types.
*/
- private static Set toPacketTypes(Set ids) {
+ public static Set toPacketTypes(Set ids) {
Set result = Sets.newHashSet();
for (int id : ids)
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java
index 9cce756b..1569d57d 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java
@@ -32,6 +32,7 @@ import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.NoOp;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
@@ -196,14 +197,16 @@ class ProxyPacketInjector implements PacketInjector {
}
@Override
- public void inputBuffersChanged(Set set) {
+ public void inputBuffersChanged(Set set) {
// No need to do anything
}
@Override
- @SuppressWarnings("rawtypes")
- public boolean addPacketHandler(int packetID) {
- if (hasPacketHandler(packetID))
+ @SuppressWarnings({"rawtypes", "deprecation"})
+ public boolean addPacketHandler(PacketType type) {
+ final int packetID = type.getLegacyId();
+
+ if (hasPacketHandler(type))
return false;
Enhancer ex = new Enhancer();
@@ -216,15 +219,15 @@ class ProxyPacketInjector implements PacketInjector {
Map overwritten = PacketRegistry.getOverwrittenPackets();
Map previous = PacketRegistry.getPreviousPackets();
Map registry = PacketRegistry.getPacketToID();
- Class old = PacketRegistry.getPacketClassFromID(packetID);
+ Class old = PacketRegistry.getPacketClassFromType(type);
// If this packet is not known
if (old == null) {
- throw new IllegalStateException("Packet ID " + packetID + " is not a valid packet ID in this version.");
+ throw new IllegalStateException("Packet ID " + type + " is not a valid packet type in this version.");
}
// Check for previous injections
if (Factory.class.isAssignableFrom(old)) {
- throw new IllegalStateException("Packet " + packetID + " has already been injected.");
+ throw new IllegalStateException("Packet " + type + " has already been injected.");
}
if (filter == null) {
@@ -275,9 +278,11 @@ class ProxyPacketInjector implements PacketInjector {
}
@Override
- @SuppressWarnings("rawtypes")
- public boolean removePacketHandler(int packetID) {
- if (!hasPacketHandler(packetID))
+ @SuppressWarnings({"rawtypes", "deprecation"})
+ public boolean removePacketHandler(PacketType type) {
+ final int packetID = type.getLegacyId();
+
+ if (!hasPacketHandler(type))
return false;
Map registry = PacketRegistry.getPacketToID();
@@ -285,7 +290,7 @@ class ProxyPacketInjector implements PacketInjector {
Map overwritten = PacketRegistry.getOverwrittenPackets();
Class old = previous.get(packetID);
- Class proxy = PacketRegistry.getPacketClassFromID(packetID);
+ Class proxy = PacketRegistry.getPacketClassFromType(type);
lookup.setLookup(packetID, old);
previous.remove(packetID);
@@ -299,18 +304,21 @@ class ProxyPacketInjector implements PacketInjector {
* @param packetId - the packet to check.
* @return TRUE if it does, FALSE otherwise.
*/
+ @Deprecated
public boolean requireInputBuffers(int packetId) {
return manager.requireInputBuffer(packetId);
}
+ @SuppressWarnings("deprecation")
@Override
- public boolean hasPacketHandler(int packetID) {
- return PacketRegistry.getPreviousPackets().containsKey(packetID);
+ public boolean hasPacketHandler(PacketType type) {
+ return PacketRegistry.getPreviousPackets().containsKey(type.getLegacyId());
}
+ @SuppressWarnings("deprecation")
@Override
- public Set getPacketHandlers() {
- return PacketRegistry.getPreviousPackets().keySet();
+ public Set getPacketHandlers() {
+ return PacketRegistry.toPacketTypes(PacketRegistry.getPreviousPackets().keySet());
}
// Called from the ReadPacketModified monitor
@@ -327,7 +335,7 @@ class ProxyPacketInjector implements PacketInjector {
return packetRecieved(packet, client, buffered);
} else {
// The timeout elapsed!
- reporter.reportWarning(this, Report.newBuilder(REPORT_UNKNOWN_ORIGIN_FOR_PACKET).messageParam(input, packet.getID()));
+ reporter.reportWarning(this, Report.newBuilder(REPORT_UNKNOWN_ORIGIN_FOR_PACKET).messageParam(input, packet.getType()));
return null;
}
@@ -348,14 +356,14 @@ class ProxyPacketInjector implements PacketInjector {
}
@Override
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({"rawtypes", "deprecation"})
public synchronized void cleanupAll() {
Map overwritten = PacketRegistry.getOverwrittenPackets();
Map previous = PacketRegistry.getPreviousPackets();
// Remove every packet handler
for (Integer id : previous.keySet().toArray(new Integer[0])) {
- removePacketHandler(id);
+ removePacketHandler(PacketType.findLegacy(id));
}
overwritten.clear();
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java
index 8029786e..02bc34db 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java
@@ -96,6 +96,7 @@ class ReadPacketModifier implements MethodInterceptor {
return getOverride(packet) == CANCEL_MARKER;
}
+ @SuppressWarnings("deprecation")
@Override
public Object intercept(Object thisObj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
// Atomic retrieval
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java
index 2f974c32..b5138290 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
+import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
@@ -110,10 +111,11 @@ class InjectedArrayList extends ArrayList