mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-30 22:53:26 +01:00
Switch to using PacketType whenever the new code will be running.
We don't convert legacy code.
This commit is contained in:
parent
6842166b94
commit
9052de5316
@ -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.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #getSendingTypes()} instead.
|
||||
* @return Every filtered server packet.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract Set<Integer> 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<PacketType> getSendingTypes();
|
||||
|
||||
/**
|
||||
* Retrieves a immutable set containing the ID of the recieved client packets that will be
|
||||
* <p>
|
||||
* Deprecated: Use {@link #getReceivingTypes()} instead.
|
||||
* observed by the asynchronous listeners.
|
||||
* @return Every filtered client packet.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract Set<Integer> 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<PacketType> getReceivingTypes();
|
||||
|
||||
/**
|
||||
* Determine if a given synchronous packet has asynchronous listeners.
|
||||
|
@ -166,10 +166,13 @@ public final class Packets {
|
||||
|
||||
/**
|
||||
* Determine if the given packet is a valid server packet in the current version of Minecraft.
|
||||
* <p>
|
||||
* 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<Integer> getSupported() throws FieldAccessException {
|
||||
return PacketFilterManager.getServerPackets();
|
||||
}
|
||||
|
@ -132,11 +132,38 @@ public interface ProtocolManager extends PacketStream {
|
||||
|
||||
/**
|
||||
* Constructs a new encapsulated Minecraft packet with the given ID.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* If set to true, the <i>forceDefaults</i> 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
@ -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.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #getSendingFilterTypes()} instead.
|
||||
* @return Every filtered server packet.
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<Integer> 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<PacketType> getSendingFilterTypes();
|
||||
|
||||
/**
|
||||
* Retrieves a immutable set containing the ID of the recieved client packets that will be observed by listeners.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #getReceivingFilterTypes()} instead.
|
||||
* @return Every filtered client packet.
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<Integer> 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<PacketType> getReceivingFilterTypes();
|
||||
|
||||
/**
|
||||
* Retrieve the current Minecraft version.
|
||||
* @return The current version.
|
||||
|
@ -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<Integer> removed = serverProcessingQueue.removeListener(handler, listener.getSendingWhitelist());
|
||||
List<PacketType> 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<Integer> removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
|
||||
List<PacketType> removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
|
||||
playerSendingHandler.sendClientPackets(removed, synchronusOK);
|
||||
}
|
||||
}
|
||||
@ -279,11 +281,21 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
|
||||
@Override
|
||||
public Set<Integer> getSendingFilters() {
|
||||
return PacketRegistry.toLegacy(serverProcessingQueue.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PacketType> getReceivingTypes() {
|
||||
return serverProcessingQueue.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getReceivingFilters() {
|
||||
return PacketRegistry.toLegacy(clientProcessingQueue.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PacketType> 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;
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ public class AsyncListenerHandler {
|
||||
if (whitelist == null)
|
||||
return "";
|
||||
else
|
||||
return Joiner.on(", ").join(whitelist.getWhitelist());
|
||||
return Joiner.on(", ").join(whitelist.getTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<AsyncList
|
||||
}
|
||||
|
||||
public PacketProcessingQueue(PlayerSendingHandler sendingHandler, int initialSize, int maximumSize, int maximumConcurrency) {
|
||||
super(Packets.MAXIMUM_PACKET_ID);
|
||||
super();
|
||||
|
||||
try {
|
||||
this.processingQueue = Synchronization.queue(MinMaxPriorityQueue.
|
||||
@ -126,7 +125,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
||||
if (holder != null) {
|
||||
PacketEvent packet = holder.getEvent();
|
||||
AsyncMarker marker = packet.getAsyncMarker();
|
||||
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID());
|
||||
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketType());
|
||||
|
||||
marker.incrementProcessingDelay();
|
||||
|
||||
|
@ -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<Integer> packetsRemoved, boolean onMainThread) {
|
||||
|
||||
Set<Integer> lookup = new HashSet<Integer>(packetsRemoved);
|
||||
public synchronized void signalPacketUpdate(List<PacketType> packetsRemoved, boolean onMainThread) {
|
||||
Set<PacketType> lookup = new HashSet<PacketType>(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) {
|
||||
|
@ -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<Integer> ids, boolean synchronusOK) {
|
||||
public void sendServerPackets(List<PacketType> 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<Integer> ids, boolean synchronusOK) {
|
||||
public void sendClientPackets(List<PacketType> types, boolean synchronusOK) {
|
||||
if (!cleaningUp) {
|
||||
for (QueueContainer queue : playerSendingQueues.values()) {
|
||||
queue.getClientQueue().signalPacketUpdate(ids, synchronusOK);
|
||||
queue.getClientQueue().signalPacketUpdate(types, synchronusOK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<TListener> {
|
||||
// The core of our map
|
||||
private AtomicReferenceArray<SortedCopyOnWriteArray<PrioritizedListener<TListener>>> arrayListeners;
|
||||
private ConcurrentMap<Integer, SortedCopyOnWriteArray<PrioritizedListener<TListener>>> mapListeners;
|
||||
private ConcurrentMap<PacketType, SortedCopyOnWriteArray<PrioritizedListener<TListener>>> mapListeners;
|
||||
|
||||
public AbstractConcurrentListenerMultimap(int maximumPacketID) {
|
||||
arrayListeners = new AtomicReferenceArray<SortedCopyOnWriteArray<PrioritizedListener<TListener>>>(maximumPacketID + 1);
|
||||
mapListeners = new ConcurrentHashMap<Integer, SortedCopyOnWriteArray<PrioritizedListener<TListener>>>();
|
||||
public AbstractConcurrentListenerMultimap() {
|
||||
mapListeners = new ConcurrentHashMap<PacketType, SortedCopyOnWriteArray<PrioritizedListener<TListener>>>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,14 +50,14 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
|
||||
public void addListener(TListener listener, ListeningWhitelist whitelist) {
|
||||
PrioritizedListener<TListener> prioritized = new PrioritizedListener<TListener>(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<TListener> listener) {
|
||||
SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = arrayListeners.get(packetID);
|
||||
private void addListener(PacketType type, PrioritizedListener<TListener> listener) {
|
||||
SortedCopyOnWriteArray<PrioritizedListener<TListener>> 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<TListener> {
|
||||
final SortedCopyOnWriteArray<PrioritizedListener<TListener>> value = new SortedCopyOnWriteArray<PrioritizedListener<TListener>>();
|
||||
|
||||
// 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<TListener> {
|
||||
* @param whitelist - the packet whitelist that was used.
|
||||
* @return Every packet ID that was removed due to no listeners.
|
||||
*/
|
||||
public List<Integer> removeListener(TListener listener, ListeningWhitelist whitelist) {
|
||||
List<Integer> removedPackets = new ArrayList<Integer>();
|
||||
public List<PacketType> removeListener(TListener listener, ListeningWhitelist whitelist) {
|
||||
List<PacketType> removedPackets = new ArrayList<PacketType>();
|
||||
|
||||
// Again, not terribly efficient. But adding or removing listeners should be a rare event.
|
||||
for (Integer packetID : whitelist.getWhitelist()) {
|
||||
SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = arrayListeners.get(packetID);
|
||||
for (PacketType type : whitelist.getTypes()) {
|
||||
SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = mapListeners.get(type);
|
||||
|
||||
// Remove any listeners
|
||||
if (list != null) {
|
||||
@ -101,16 +98,13 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
|
||||
list.remove(new PrioritizedListener<TListener>(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<TListener> {
|
||||
* Retrieve the registered listeners, in order from the lowest to the highest priority.
|
||||
* <p>
|
||||
* The returned list is thread-safe and doesn't require synchronization.
|
||||
* @param packetID - packet ID.
|
||||
* @param type - packet type.
|
||||
* @return Registered listeners.
|
||||
*/
|
||||
public Collection<PrioritizedListener<TListener>> getListener(int packetID) {
|
||||
return arrayListeners.get(packetID);
|
||||
public Collection<PrioritizedListener<TListener>> getListener(PacketType type) {
|
||||
return mapListeners.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,10 +128,10 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve every registered packet ID:
|
||||
* @return Registered packet ID.
|
||||
* Retrieve every registered packet type:
|
||||
* @return Registered packet type.
|
||||
*/
|
||||
public Set<Integer> keySet() {
|
||||
public Set<PacketType> keySet() {
|
||||
return mapListeners.keySet();
|
||||
}
|
||||
|
||||
@ -145,8 +139,6 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
|
||||
* Remove all packet listeners.
|
||||
*/
|
||||
protected void clearListeners() {
|
||||
arrayListeners = new AtomicReferenceArray<
|
||||
SortedCopyOnWriteArray<PrioritizedListener<TListener>>>(arrayListeners.length());
|
||||
mapListeners.clear();
|
||||
}
|
||||
}
|
||||
|
@ -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<PacketType> types = Collections.newSetFromMap(Maps.<PacketType, Boolean>newConcurrentMap());
|
||||
private Set<Class<?>> classes = Collections.newSetFromMap(Maps.<Class<?>, 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<PacketType> 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();
|
||||
}
|
||||
}
|
@ -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<Integer> whitelist;
|
||||
private final GamePhase gamePhase;
|
||||
private final Set<ListenerOptions> options;
|
||||
|
||||
private final Set<PacketType> types;
|
||||
|
||||
// Cache whitelist
|
||||
private transient Set<Integer> 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.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #newBuilder()} instead.
|
||||
* @param priority - the listener priority.
|
||||
* @param whitelist - set of IDs to observe/enable.
|
||||
*/
|
||||
@Deprecated
|
||||
public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist) {
|
||||
this(priority, whitelist, GamePhase.PLAYING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet whitelist for a given priority with a set of packet IDs.
|
||||
* <p>
|
||||
* 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<Integer> 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #getTypes()} instead.
|
||||
* @return Packet whitelist.
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<Integer> 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<PacketType> 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<Integer> whitelist;
|
||||
private Set<PacketType> types;
|
||||
private GamePhase gamePhase;
|
||||
private Set<ListenerOptions> 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.
|
||||
* <p>
|
||||
* Deprecated: Use {@link #types(Collection)} instead.
|
||||
* @param whitelist - the whitelist of packets.
|
||||
* @return This builder, for chaining.
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder whitelist(Collection<Integer> 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<PacketType> 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.
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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<Integer> 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.
|
||||
* <p>
|
||||
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
|
||||
* <p>
|
||||
* 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<Integer> 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.
|
||||
* <p>
|
||||
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
|
||||
* <p>
|
||||
* 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<Integer> packets) {
|
||||
this(plugin, connectionSide, listenerPriority, gamePhase, packets.toArray(new Integer[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a packet listener for a single connection side.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Listener options must be specified in order for {@link NetworkMarker#getInputBuffer()} to function correctly.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This parameter is required.
|
||||
* <p>
|
||||
* 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<Integer> packets) {
|
||||
return packets(packets.toArray(new Integer[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the packet types the listener is looking for.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This parameter is required.
|
||||
* @param packets
|
||||
* @return This builder, for chaining.
|
||||
*/
|
||||
public AdapterParameteters types(@Nonnull Set<PacketType> packets) {
|
||||
return types(packets.toArray(new PacketType[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<Integer> getSendingFilters() {
|
||||
if (delegate != null) {
|
||||
return delegate.getSendingFilters();
|
||||
@ -352,6 +356,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Set<Integer> 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<PacketType> getSendingFilterTypes() {
|
||||
return PacketRegistry.toPacketTypes(getSendingFilters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PacketType> getReceivingFilterTypes() {
|
||||
return PacketRegistry.toPacketTypes(getReceivingFilters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException {
|
||||
if (delegate != null)
|
||||
@ -426,6 +451,4 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
||||
delegate.close();
|
||||
closed = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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<PacketType> 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<PacketType> 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<Integer> sendingRemoved = null;
|
||||
List<Integer> receivingRemoved = null;
|
||||
List<PacketType> sendingRemoved = null;
|
||||
List<PacketType> 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<Integer> packets) {
|
||||
private void enablePacketFilters(PacketListener listener, ConnectionSide side, Iterable<PacketType> 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<Integer> packets) {
|
||||
private void disablePacketFilters(ConnectionSide side, Iterable<PacketType> 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<Integer> getSendingFilters() {
|
||||
return playerInjection.getSendingFilters();
|
||||
return PacketRegistry.toLegacy(playerInjection.getSendingFilters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getReceivingFilters() {
|
||||
return ImmutableSet.copyOf(packetInjector.getPacketHandlers());
|
||||
return PacketRegistry.toLegacy(packetInjector.getPacketHandlers());
|
||||
}
|
||||
@Override
|
||||
public Set<PacketType> getSendingFilterTypes() {
|
||||
return Collections.unmodifiableSet(playerInjection.getSendingFilters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PacketType> 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<Integer> 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<Integer> getClientPackets() throws FieldAccessException {
|
||||
return PacketRegistry.getClientPackets();
|
||||
}
|
||||
|
@ -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<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
||||
Collection<PrioritizedListener<PacketListener>> 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<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
||||
Collection<PrioritizedListener<PacketListener>> 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<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
||||
Collection<PrioritizedListener<PacketListener>> 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<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
||||
Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketType());
|
||||
|
||||
if (list == null)
|
||||
return;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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<VolatileField> 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<Integer> 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<Integer> set) {
|
||||
bufferedPackets = set;
|
||||
public void inputBuffersChanged(Set<PacketType> set) {
|
||||
bufferedPackets = new PacketTypeSet(set);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -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<Integer> set);
|
||||
public abstract void inputBuffersChanged(Set<PacketType> set);
|
||||
|
||||
/**
|
||||
* Retrieve every intercepted packet ID.
|
||||
* @return Every intercepted packet ID.
|
||||
* Retrieve every intercepted packet type.
|
||||
* @return Every intercepted packet type.
|
||||
*/
|
||||
public abstract Set<Integer> getPacketHandlers();
|
||||
public abstract Set<PacketType> getPacketHandlers();
|
||||
|
||||
/**
|
||||
* Let the packet listeners process the given packet.
|
||||
|
@ -283,7 +283,7 @@ public class PacketRegistry {
|
||||
* @param types - packet type.
|
||||
* @return Set of integers.
|
||||
*/
|
||||
private static Set<Integer> toLegacy(Set<PacketType> types) {
|
||||
public static Set<Integer> toLegacy(Set<PacketType> types) {
|
||||
Set<Integer> 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<PacketType> toPacketTypes(Set<Integer> ids) {
|
||||
public static Set<PacketType> toPacketTypes(Set<Integer> ids) {
|
||||
Set<PacketType> result = Sets.newHashSet();
|
||||
|
||||
for (int id : ids)
|
||||
|
@ -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<Integer> set) {
|
||||
public void inputBuffersChanged(Set<PacketType> 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<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
|
||||
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
|
||||
Map<Class, Integer> 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<Class, Integer> registry = PacketRegistry.getPacketToID();
|
||||
@ -285,7 +290,7 @@ class ProxyPacketInjector implements PacketInjector {
|
||||
Map<Integer, Class> 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<Integer> getPacketHandlers() {
|
||||
return PacketRegistry.getPreviousPackets().keySet();
|
||||
public Set<PacketType> 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<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
|
||||
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
|
||||
|
||||
// Remove every packet handler
|
||||
for (Integer id : previous.keySet().toArray(new Integer[0])) {
|
||||
removePacketHandler(id);
|
||||
removePacketHandler(PacketType.findLegacy(id));
|
||||
}
|
||||
|
||||
overwritten.clear();
|
||||
|
@ -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
|
||||
|
@ -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<Object> {
|
||||
* @param source - packet to invert.
|
||||
* @return The inverted packet.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
Object createNegativePacket(Object source) {
|
||||
ListenerInvoker invoker = injector.getInvoker();
|
||||
|
||||
int packetID = invoker.getPacketID(source);
|
||||
PacketType type = invoker.getPacketType(source);
|
||||
|
||||
// We want to subtract the byte amount that were added to the running
|
||||
// total of outstanding packets. Otherwise, cancelling too many packets
|
||||
@ -145,7 +147,7 @@ class InjectedArrayList extends ArrayList<Object> {
|
||||
|
||||
try {
|
||||
// Temporarily associate the fake packet class
|
||||
invoker.registerPacketClass(proxyClass, packetID);
|
||||
invoker.registerPacketClass(proxyClass, type.getLegacyId());
|
||||
Object proxy = proxyClass.newInstance();
|
||||
|
||||
InjectedArrayList.registerDelegate(proxy, source);
|
||||
|
@ -133,6 +133,7 @@ class NetworkFieldInjector extends PlayerInjector {
|
||||
return null;
|
||||
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK };
|
||||
|
||||
// Unfortunately, we don't support chunk packets
|
||||
|
@ -130,6 +130,7 @@ public class NetworkObjectInjector extends PlayerInjector {
|
||||
return null;
|
||||
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK };
|
||||
|
||||
// Unfortunately, we don't support chunk packets
|
||||
|
@ -7,6 +7,7 @@ import java.net.InetSocketAddress;
|
||||
import java.util.Set;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
@ -59,16 +60,16 @@ public interface PlayerInjectionHandler {
|
||||
public abstract void setPlayerHook(GamePhase phase, PlayerInjectHooks playerHook);
|
||||
|
||||
/**
|
||||
* Add an underlying packet handler of the given ID.
|
||||
* @param packetID - packet ID to register.
|
||||
* Add an underlying packet handler of the given type.
|
||||
* @param type - packet type to register.
|
||||
*/
|
||||
public abstract void addPacketHandler(int packetID);
|
||||
public abstract void addPacketHandler(PacketType type);
|
||||
|
||||
/**
|
||||
* Remove an underlying packet handler of ths ID.
|
||||
* @param packetID - packet ID to unregister.
|
||||
* Remove an underlying packet handler of this type.
|
||||
* @param type - packet type to unregister.
|
||||
*/
|
||||
public abstract void removePacketHandler(int packetID);
|
||||
public abstract void removePacketHandler(PacketType type);
|
||||
|
||||
/**
|
||||
* Retrieve a player by its DataInput connection.
|
||||
@ -157,7 +158,7 @@ public interface PlayerInjectionHandler {
|
||||
* Retrieve the current list of registered sending listeners.
|
||||
* @return List of the sending listeners's packet IDs.
|
||||
*/
|
||||
public abstract Set<Integer> getSendingFilters();
|
||||
public abstract Set<PacketType> getSendingFilters();
|
||||
|
||||
/**
|
||||
* Whether or not this player injection handler can also recieve packets.
|
||||
|
@ -581,6 +581,7 @@ public abstract class PlayerInjector implements SocketInjector {
|
||||
* @param packet - packet to sent.
|
||||
* @return The given packet, or the packet replaced by the listeners.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public Object handlePacketSending(Object packet) {
|
||||
try {
|
||||
// Get the packet ID too
|
||||
|
@ -34,6 +34,7 @@ import net.sf.cglib.proxy.Factory;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.concurrency.BlockingHashMap;
|
||||
import com.comphenix.protocol.concurrency.IntegerSet;
|
||||
@ -49,6 +50,7 @@ import com.comphenix.protocol.injector.GamePhase;
|
||||
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||
import com.comphenix.protocol.injector.PlayerLoggedOutException;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.injector.server.AbstractInputStreamLookup;
|
||||
import com.comphenix.protocol.injector.server.BukkitSocketInjector;
|
||||
import com.comphenix.protocol.injector.server.InputStreamLookupBuilder;
|
||||
@ -199,22 +201,14 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
checkListener(packetListeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an underlying packet handler of the given ID.
|
||||
* @param packetID - packet ID to register.
|
||||
*/
|
||||
@Override
|
||||
public void addPacketHandler(int packetID) {
|
||||
sendingFilters.add(packetID);
|
||||
public void addPacketHandler(PacketType type) {
|
||||
sendingFilters.add(type.getLegacyId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an underlying packet handler of ths ID.
|
||||
* @param packetID - packet ID to unregister.
|
||||
*/
|
||||
@Override
|
||||
public void removePacketHandler(int packetID) {
|
||||
sendingFilters.remove(packetID);
|
||||
public void removePacketHandler(PacketType type) {
|
||||
sendingFilters.remove(type.getLegacyId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -545,7 +539,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
} else {
|
||||
throw new PlayerLoggedOutException(String.format(
|
||||
"Unable to send packet %s (%s): Player %s has logged out.",
|
||||
packet.getID(), packet, reciever
|
||||
packet.getType(), packet, reciever
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -706,7 +700,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
|
||||
// These are illegal
|
||||
for (int packetID : result.getPackets())
|
||||
removePacketHandler(packetID);
|
||||
removePacketHandler(PacketType.findLegacy(packetID));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -716,8 +710,8 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
* @return List of the sending listeners's packet IDs.
|
||||
*/
|
||||
@Override
|
||||
public Set<Integer> getSendingFilters() {
|
||||
return sendingFilters.toSet();
|
||||
public Set<PacketType> getSendingFilters() {
|
||||
return PacketRegistry.toPacketTypes(sendingFilters.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,13 +2,14 @@ package com.comphenix.protocol.injector.spigot;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.comphenix.protocol.concurrency.IntegerSet;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
import com.comphenix.protocol.injector.packet.PacketInjector;
|
||||
|
||||
public abstract class AbstractPacketInjector implements PacketInjector {
|
||||
private IntegerSet reveivedFilters;
|
||||
private PacketTypeSet reveivedFilters;
|
||||
|
||||
public AbstractPacketInjector(IntegerSet reveivedFilters) {
|
||||
public AbstractPacketInjector(PacketTypeSet reveivedFilters) {
|
||||
this.reveivedFilters = reveivedFilters;
|
||||
}
|
||||
|
||||
@ -24,25 +25,25 @@ public abstract class AbstractPacketInjector implements PacketInjector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPacketHandler(int packetID) {
|
||||
reveivedFilters.add(packetID);
|
||||
public boolean addPacketHandler(PacketType type) {
|
||||
reveivedFilters.addType(type);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePacketHandler(int packetID) {
|
||||
reveivedFilters.remove(packetID);
|
||||
public boolean removePacketHandler(PacketType type) {
|
||||
reveivedFilters.removeType(type);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPacketHandler(int packetID) {
|
||||
return reveivedFilters.contains(packetID);
|
||||
public boolean hasPacketHandler(PacketType type) {
|
||||
return reveivedFilters.contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getPacketHandlers() {
|
||||
return reveivedFilters.toSet();
|
||||
public Set<PacketType> getPacketHandlers() {
|
||||
return reveivedFilters.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,16 +5,17 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.concurrency.IntegerSet;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.GamePhase;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
||||
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
||||
|
||||
public abstract class AbstractPlayerHandler implements PlayerInjectionHandler {
|
||||
protected IntegerSet sendingFilters;
|
||||
protected PacketTypeSet sendingFilters;
|
||||
|
||||
public AbstractPlayerHandler(IntegerSet sendingFilters) {
|
||||
public AbstractPlayerHandler(PacketTypeSet sendingFilters) {
|
||||
this.sendingFilters = sendingFilters;
|
||||
}
|
||||
|
||||
@ -29,18 +30,18 @@ public abstract class AbstractPlayerHandler implements PlayerInjectionHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPacketHandler(int packetID) {
|
||||
sendingFilters.add(packetID);
|
||||
public void addPacketHandler(PacketType type) {
|
||||
sendingFilters.addType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePacketHandler(int packetID) {
|
||||
sendingFilters.remove(packetID);
|
||||
public void removePacketHandler(PacketType type) {
|
||||
sendingFilters.removeType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getSendingFilters() {
|
||||
return sendingFilters.toSet();
|
||||
public Set<PacketType> getSendingFilters() {
|
||||
return sendingFilters.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,8 +4,8 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.packet.PacketInjector;
|
||||
@ -18,23 +18,23 @@ import com.google.common.collect.Sets;
|
||||
*/
|
||||
class DummyPacketInjector extends AbstractPacketInjector implements PacketInjector {
|
||||
private SpigotPacketInjector injector;
|
||||
private IntegerSet lastBufferedPackets = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1);
|
||||
private PacketTypeSet lastBufferedPackets = new PacketTypeSet();
|
||||
|
||||
public DummyPacketInjector(SpigotPacketInjector injector, IntegerSet reveivedFilters) {
|
||||
public DummyPacketInjector(SpigotPacketInjector injector, PacketTypeSet reveivedFilters) {
|
||||
super(reveivedFilters);
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inputBuffersChanged(Set<Integer> set) {
|
||||
Set<Integer> removed = Sets.difference(lastBufferedPackets.toSet(), set);
|
||||
Set<Integer> added = Sets.difference(set, lastBufferedPackets.toSet());
|
||||
public void inputBuffersChanged(Set<PacketType> set) {
|
||||
Set<PacketType> removed = Sets.difference(lastBufferedPackets.values(), set);
|
||||
Set<PacketType> added = Sets.difference(set, lastBufferedPackets.values());
|
||||
|
||||
// Update the proxy packet injector
|
||||
for (int packet : removed) {
|
||||
for (PacketType packet : removed) {
|
||||
injector.getProxyPacketInjector().removePacketHandler(packet);
|
||||
}
|
||||
for (int packet : added) {
|
||||
for (PacketType packet : added) {
|
||||
injector.getProxyPacketInjector().addPacketHandler(packet);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.concurrency.IntegerSet;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
@ -17,7 +17,8 @@ import com.comphenix.protocol.events.PacketEvent;
|
||||
*/
|
||||
class DummyPlayerHandler extends AbstractPlayerHandler {
|
||||
private SpigotPacketInjector injector;
|
||||
public DummyPlayerHandler(SpigotPacketInjector injector, IntegerSet sendingFilters) {
|
||||
|
||||
public DummyPlayerHandler(SpigotPacketInjector injector, PacketTypeSet sendingFilters) {
|
||||
super(sendingFilters);
|
||||
this.injector = injector;
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
import net.sf.cglib.proxy.NoOp;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.concurrency.IntegerSet;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
import com.comphenix.protocol.error.DelegatedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
@ -80,8 +79,8 @@ public class SpigotPacketInjector implements SpigotPacketListener {
|
||||
private Plugin plugin;
|
||||
|
||||
// Different sending filters
|
||||
private IntegerSet queuedFilters;
|
||||
private IntegerSet reveivedFilters;
|
||||
private PacketTypeSet queuedFilters;
|
||||
private PacketTypeSet reveivedFilters;
|
||||
|
||||
// NetworkManager to injector and player
|
||||
private ConcurrentMap<Object, NetworkObjectInjector> networkManagerInjector = Maps.newConcurrentMap();
|
||||
@ -109,8 +108,8 @@ public class SpigotPacketInjector implements SpigotPacketListener {
|
||||
this.reporter = reporter;
|
||||
this.invoker = invoker;
|
||||
this.server = server;
|
||||
this.queuedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1);
|
||||
this.reveivedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1);
|
||||
this.queuedFilters = new PacketTypeSet();
|
||||
this.reveivedFilters = new PacketTypeSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -417,9 +416,10 @@ public class SpigotPacketInjector implements SpigotPacketListener {
|
||||
|
||||
@Override
|
||||
public Object packetReceived(Object networkManager, Object connection, Object packet) {
|
||||
Integer id = invoker.getPacketID(packet);
|
||||
|
||||
if (id != null && reveivedFilters.contains(id)) {
|
||||
if (reveivedFilters.contains(packet.getClass())) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Integer id = invoker.getPacketID(packet);
|
||||
|
||||
// Check for ignored packets
|
||||
if (ignoredPackets.remove(packet)) {
|
||||
return packet;
|
||||
@ -440,9 +440,10 @@ public class SpigotPacketInjector implements SpigotPacketListener {
|
||||
|
||||
@Override
|
||||
public Object packetQueued(Object networkManager, Object connection, Object packet) {
|
||||
Integer id = invoker.getPacketID(packet);
|
||||
|
||||
if (id != null && queuedFilters.contains(id)) {
|
||||
if (queuedFilters.contains(packet.getClass())) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Integer id = invoker.getPacketID(packet);
|
||||
|
||||
// Check for ignored packets
|
||||
if (ignoredPackets.remove(packet)) {
|
||||
return packet;
|
||||
|
@ -383,7 +383,7 @@ public class BukkitConverters {
|
||||
|
||||
@Override
|
||||
protected NbtBase<?> getSpecificValue(Object generic) {
|
||||
return NbtFactory.fromNMS(generic);
|
||||
return NbtFactory.fromNMS(generic, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
@ -132,7 +132,7 @@ public class WrappedAttribute {
|
||||
*/
|
||||
public PacketContainer getParentPacket() {
|
||||
return new PacketContainer(
|
||||
Packets.Server.UPDATE_ATTRIBUTES,
|
||||
PacketType.Play.Server.UPDATE_ATTRIBUTES,
|
||||
modifier.withType(MinecraftReflection.getPacketClass()).read(0)
|
||||
);
|
||||
}
|
||||
@ -351,7 +351,7 @@ public class WrappedAttribute {
|
||||
* @return This builder, for chaining.
|
||||
*/
|
||||
public Builder packet(PacketContainer packet) {
|
||||
if (Preconditions.checkNotNull(packet, "packet cannot be NULL").getID() != Packets.Server.UPDATE_ATTRIBUTES) {
|
||||
if (Preconditions.checkNotNull(packet, "packet cannot be NULL").getType() != PacketType.Play.Server.UPDATE_ATTRIBUTES) {
|
||||
throw new IllegalArgumentException("Packet must be UPDATE_ATTRIBUTES (44)");
|
||||
}
|
||||
this.packet = packet;
|
||||
|
Loading…
Reference in New Issue
Block a user