Archiviert
13
0

Switch to using PacketType whenever the new code will be running.

We don't convert legacy code.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-05 06:52:20 +01:00
Ursprung 6842166b94
Commit 9052de5316
37 geänderte Dateien mit 720 neuen und 249 gelöschten Zeilen

Datei anzeigen

@ -59,17 +59,37 @@ public interface AsynchronousManager {
/** /**
* Retrieves a immutable set containing the ID of the sent server packets that will be * Retrieves a immutable set containing the ID of the sent server packets that will be
* observed by the asynchronous listeners. * observed by the asynchronous listeners.
* <p>
* Deprecated: Use {@link #getSendingTypes()} instead.
* @return Every filtered server packet. * @return Every filtered server packet.
*/ */
@Deprecated
public abstract Set<Integer> getSendingFilters(); 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 * 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. * observed by the asynchronous listeners.
* @return Every filtered client packet. * @return Every filtered client packet.
*/ */
@Deprecated
public abstract Set<Integer> getReceivingFilters(); 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. * Determine if a given synchronous packet has asynchronous listeners.
* @param packet - packet to test. * @param packet - packet to test.

Datei anzeigen

@ -166,10 +166,13 @@ public final class Packets {
/** /**
* Determine if the given packet is a valid server packet in the current version of Minecraft. * 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. * @param packetID - the packet to test.
* @return TRUE if this packet is supported, FALSE otherwise. * @return TRUE if this packet is supported, FALSE otherwise.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft. * @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/ */
@Deprecated
public static boolean isSupported(int packetID) throws FieldAccessException { public static boolean isSupported(int packetID) throws FieldAccessException {
return PacketFilterManager.getServerPackets().contains(packetID); return PacketFilterManager.getServerPackets().contains(packetID);
} }
@ -179,6 +182,7 @@ public final class Packets {
* @return Every supported server packet. * @return Every supported server packet.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft. * @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/ */
@Deprecated
public static Set<Integer> getSupported() throws FieldAccessException { public static Set<Integer> getSupported() throws FieldAccessException {
return PacketFilterManager.getServerPackets(); return PacketFilterManager.getServerPackets();
} }

Datei anzeigen

@ -132,11 +132,38 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Constructs a new encapsulated Minecraft packet with the given ID. * Constructs a new encapsulated Minecraft packet with the given ID.
* <p>
* Deprecated: Use {@link #createPacket(PacketType)} instead.
* @param id - packet ID. * @param id - packet ID.
* @return New encapsulated Minecraft packet. * @return New encapsulated Minecraft packet.
*/ */
@Deprecated
public PacketContainer createPacket(int id); 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. * Constructs a new encapsulated Minecraft packet with the given ID.
* <p> * <p>
@ -145,11 +172,11 @@ public interface ProtocolManager extends PacketStream {
* packets - like Packet60Explosion - require a List or Set to be non-null. If the * 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. * 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. * @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
* @return New encapsulated Minecraft packet. * @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. * 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. * 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. * @return Every filtered server packet.
*/ */
@Deprecated
public Set<Integer> getSendingFilters(); 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. * 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. * @return Every filtered client packet.
*/ */
@Deprecated
public Set<Integer> getReceivingFilters(); 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. * Retrieve the current Minecraft version.
* @return The current version. * @return The current version.

Datei anzeigen

@ -29,6 +29,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.PacketStream; import com.comphenix.protocol.PacketStream;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ListeningWhitelist; 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.PacketFilterManager;
import com.comphenix.protocol.injector.PrioritizedListener; import com.comphenix.protocol.injector.PrioritizedListener;
import com.comphenix.protocol.injector.SortedPacketListenerList; import com.comphenix.protocol.injector.SortedPacketListenerList;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -181,7 +183,7 @@ public class AsyncFilterManager implements AsynchronousManager {
} }
private boolean hasValidWhitelist(ListeningWhitelist whitelist) { private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
return whitelist != null && whitelist.getWhitelist().size() > 0; return whitelist != null && whitelist.getTypes().size() > 0;
} }
@Override @Override
@ -220,14 +222,14 @@ public class AsyncFilterManager implements AsynchronousManager {
// Just remove it from the queue(s) // Just remove it from the queue(s)
if (hasValidWhitelist(listener.getSendingWhitelist())) { 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 // We're already taking care of this, so don't do anything
playerSendingHandler.sendServerPackets(removed, synchronusOK); playerSendingHandler.sendServerPackets(removed, synchronusOK);
} }
if (hasValidWhitelist(listener.getReceivingWhitelist())) { if (hasValidWhitelist(listener.getReceivingWhitelist())) {
List<Integer> removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist()); List<PacketType> removed = clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
playerSendingHandler.sendClientPackets(removed, synchronusOK); playerSendingHandler.sendClientPackets(removed, synchronusOK);
} }
} }
@ -279,11 +281,21 @@ public class AsyncFilterManager implements AsynchronousManager {
@Override @Override
public Set<Integer> getSendingFilters() { public Set<Integer> getSendingFilters() {
return PacketRegistry.toLegacy(serverProcessingQueue.keySet());
}
@Override
public Set<PacketType> getReceivingTypes() {
return serverProcessingQueue.keySet(); return serverProcessingQueue.keySet();
} }
@Override @Override
public Set<Integer> getReceivingFilters() { public Set<Integer> getReceivingFilters() {
return PacketRegistry.toLegacy(clientProcessingQueue.keySet());
}
@Override
public Set<PacketType> getSendingTypes() {
return clientProcessingQueue.keySet(); return clientProcessingQueue.keySet();
} }
@ -297,7 +309,7 @@ public class AsyncFilterManager implements AsynchronousManager {
@Override @Override
public boolean hasAsynchronousListeners(PacketEvent packet) { 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; return list != null && list.size() > 0;
} }

Datei anzeigen

@ -336,7 +336,7 @@ public class AsyncListenerHandler {
if (whitelist == null) if (whitelist == null)
return ""; return "";
else else
return Joiner.on(", ").join(whitelist.getWhitelist()); return Joiner.on(", ").join(whitelist.getTypes());
} }
/** /**

Datei anzeigen

@ -23,7 +23,6 @@ import java.util.PriorityQueue;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap; import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PrioritizedListener; 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) { public PacketProcessingQueue(PlayerSendingHandler sendingHandler, int initialSize, int maximumSize, int maximumConcurrency) {
super(Packets.MAXIMUM_PACKET_ID); super();
try { try {
this.processingQueue = Synchronization.queue(MinMaxPriorityQueue. this.processingQueue = Synchronization.queue(MinMaxPriorityQueue.
@ -126,7 +125,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
if (holder != null) { if (holder != null) {
PacketEvent packet = holder.getEvent(); PacketEvent packet = holder.getEvent();
AsyncMarker marker = packet.getAsyncMarker(); AsyncMarker marker = packet.getAsyncMarker();
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID()); Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketType());
marker.incrementProcessingDelay(); marker.incrementProcessingDelay();

Datei anzeigen

@ -26,6 +26,7 @@ import java.util.concurrent.PriorityBlockingQueue;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.PlayerLoggedOutException;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
@ -106,15 +107,14 @@ abstract class PacketSendingQueue {
* @param packetsRemoved - packets that no longer have any listeners. * @param packetsRemoved - packets that no longer have any listeners.
* @param onMainThread - whether or not this is occuring on the main thread. * @param onMainThread - whether or not this is occuring on the main thread.
*/ */
public synchronized void signalPacketUpdate(List<Integer> packetsRemoved, boolean onMainThread) { public synchronized void signalPacketUpdate(List<PacketType> packetsRemoved, boolean onMainThread) {
Set<PacketType> lookup = new HashSet<PacketType>(packetsRemoved);
Set<Integer> lookup = new HashSet<Integer>(packetsRemoved);
// Note that this is O(n), so it might be expensive // Note that this is O(n), so it might be expensive
for (PacketEventHolder holder : sendingQueue) { for (PacketEventHolder holder : sendingQueue) {
PacketEvent event = holder.getEvent(); PacketEvent event = holder.getEvent();
if (lookup.contains(event.getPacketID())) { if (lookup.contains(event.getPacketType())) {
event.getAsyncMarker().setProcessed(true); event.getAsyncMarker().setProcessed(true);
} }
} }
@ -280,8 +280,8 @@ abstract class PacketSendingQueue {
} catch (PlayerLoggedOutException e) { } catch (PlayerLoggedOutException e) {
System.out.println(String.format( System.out.println(String.format(
"[ProtocolLib] Warning: Dropped packet index %s of ID %s", "[ProtocolLib] Warning: Dropped packet index %s of type %s",
marker.getOriginalSendingIndex(), event.getPacketID() marker.getOriginalSendingIndex(), event.getPacketType()
)); ));
} catch (IOException e) { } catch (IOException e) {

Datei anzeigen

@ -26,6 +26,7 @@ import java.util.concurrent.ThreadFactory;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.concurrency.ConcurrentPlayerMap; import com.comphenix.protocol.concurrency.ConcurrentPlayerMap;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
@ -172,13 +173,13 @@ class PlayerSendingHandler {
/** /**
* Immediately send every server packet with the given list of IDs. * 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. * @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) { if (!cleaningUp) {
for (QueueContainer queue : playerSendingQueues.values()) { 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 ids - ID of every packet to send immediately.
* @param synchronusOK - whether or not we're running on the main thread. * @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) { if (!cleaningUp) {
for (QueueContainer queue : playerSendingQueues.values()) { for (QueueContainer queue : playerSendingQueues.values()) {
queue.getClientQueue().signalPacketUpdate(ids, synchronusOK); queue.getClientQueue().signalPacketUpdate(types, synchronusOK);
} }
} }
} }

Datei anzeigen

@ -23,8 +23,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; 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.events.ListeningWhitelist;
import com.comphenix.protocol.injector.PrioritizedListener; import com.comphenix.protocol.injector.PrioritizedListener;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -36,12 +36,10 @@ import com.google.common.collect.Iterables;
*/ */
public abstract class AbstractConcurrentListenerMultimap<TListener> { public abstract class AbstractConcurrentListenerMultimap<TListener> {
// The core of our map // The core of our map
private AtomicReferenceArray<SortedCopyOnWriteArray<PrioritizedListener<TListener>>> arrayListeners; private ConcurrentMap<PacketType, SortedCopyOnWriteArray<PrioritizedListener<TListener>>> mapListeners;
private ConcurrentMap<Integer, SortedCopyOnWriteArray<PrioritizedListener<TListener>>> mapListeners;
public AbstractConcurrentListenerMultimap(int maximumPacketID) { public AbstractConcurrentListenerMultimap() {
arrayListeners = new AtomicReferenceArray<SortedCopyOnWriteArray<PrioritizedListener<TListener>>>(maximumPacketID + 1); mapListeners = new ConcurrentHashMap<PacketType, SortedCopyOnWriteArray<PrioritizedListener<TListener>>>();
mapListeners = new ConcurrentHashMap<Integer, SortedCopyOnWriteArray<PrioritizedListener<TListener>>>();
} }
/** /**
@ -52,14 +50,14 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
public void addListener(TListener listener, ListeningWhitelist whitelist) { public void addListener(TListener listener, ListeningWhitelist whitelist) {
PrioritizedListener<TListener> prioritized = new PrioritizedListener<TListener>(listener, whitelist.getPriority()); PrioritizedListener<TListener> prioritized = new PrioritizedListener<TListener>(listener, whitelist.getPriority());
for (Integer packetID : whitelist.getWhitelist()) { for (PacketType type : whitelist.getTypes()) {
addListener(packetID, prioritized); addListener(type, prioritized);
} }
} }
// Add the listener to a specific packet notifcation list // Add the listener to a specific packet notifcation list
private void addListener(Integer packetID, PrioritizedListener<TListener> listener) { private void addListener(PacketType type, PrioritizedListener<TListener> listener) {
SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = arrayListeners.get(packetID); SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = mapListeners.get(type);
// We don't want to create this for every lookup // We don't want to create this for every lookup
if (list == null) { if (list == null) {
@ -68,11 +66,10 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
final SortedCopyOnWriteArray<PrioritizedListener<TListener>> value = new SortedCopyOnWriteArray<PrioritizedListener<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 // We may end up creating multiple multisets, but we'll agree on which to use
if (arrayListeners.compareAndSet(packetID, null, value)) { list = mapListeners.putIfAbsent(type, value);
mapListeners.put(packetID, value);
if (list == null) {
list = value; list = value;
} else {
list = arrayListeners.get(packetID);
} }
} }
@ -86,12 +83,12 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
* @param whitelist - the packet whitelist that was used. * @param whitelist - the packet whitelist that was used.
* @return Every packet ID that was removed due to no listeners. * @return Every packet ID that was removed due to no listeners.
*/ */
public List<Integer> removeListener(TListener listener, ListeningWhitelist whitelist) { public List<PacketType> removeListener(TListener listener, ListeningWhitelist whitelist) {
List<Integer> removedPackets = new ArrayList<Integer>(); List<PacketType> removedPackets = new ArrayList<PacketType>();
// Again, not terribly efficient. But adding or removing listeners should be a rare event. // Again, not terribly efficient. But adding or removing listeners should be a rare event.
for (Integer packetID : whitelist.getWhitelist()) { for (PacketType type : whitelist.getTypes()) {
SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = arrayListeners.get(packetID); SortedCopyOnWriteArray<PrioritizedListener<TListener>> list = mapListeners.get(type);
// Remove any listeners // Remove any listeners
if (list != null) { if (list != null) {
@ -101,16 +98,13 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
list.remove(new PrioritizedListener<TListener>(listener, whitelist.getPriority())); list.remove(new PrioritizedListener<TListener>(listener, whitelist.getPriority()));
if (list.size() == 0) { if (list.size() == 0) {
arrayListeners.set(packetID, null); mapListeners.remove(type);
mapListeners.remove(packetID); removedPackets.add(type);
removedPackets.add(packetID);
} }
} }
} }
// Move on to the next // Move on to the next
} }
return removedPackets; return removedPackets;
} }
@ -118,11 +112,11 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
* Retrieve the registered listeners, in order from the lowest to the highest priority. * Retrieve the registered listeners, in order from the lowest to the highest priority.
* <p> * <p>
* The returned list is thread-safe and doesn't require synchronization. * The returned list is thread-safe and doesn't require synchronization.
* @param packetID - packet ID. * @param type - packet type.
* @return Registered listeners. * @return Registered listeners.
*/ */
public Collection<PrioritizedListener<TListener>> getListener(int packetID) { public Collection<PrioritizedListener<TListener>> getListener(PacketType type) {
return arrayListeners.get(packetID); return mapListeners.get(type);
} }
/** /**
@ -134,10 +128,10 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
} }
/** /**
* Retrieve every registered packet ID: * Retrieve every registered packet type:
* @return Registered packet ID. * @return Registered packet type.
*/ */
public Set<Integer> keySet() { public Set<PacketType> keySet() {
return mapListeners.keySet(); return mapListeners.keySet();
} }
@ -145,8 +139,6 @@ public abstract class AbstractConcurrentListenerMultimap<TListener> {
* Remove all packet listeners. * Remove all packet listeners.
*/ */
protected void clearListeners() { protected void clearListeners() {
arrayListeners = new AtomicReferenceArray<
SortedCopyOnWriteArray<PrioritizedListener<TListener>>>(arrayListeners.length());
mapListeners.clear(); mapListeners.clear();
} }
} }

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -23,7 +23,9 @@ import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -40,74 +42,92 @@ public class ListeningWhitelist {
public static final ListeningWhitelist EMPTY_WHITELIST = new ListeningWhitelist(ListenerPriority.LOW); public static final ListeningWhitelist EMPTY_WHITELIST = new ListeningWhitelist(ListenerPriority.LOW);
private final ListenerPriority priority; private final ListenerPriority priority;
private final Set<Integer> whitelist;
private final GamePhase gamePhase; private final GamePhase gamePhase;
private final Set<ListenerOptions> options; private final Set<ListenerOptions> options;
private final Set<PacketType> types;
// Cache whitelist
private transient Set<Integer> intWhitelist;
private ListeningWhitelist(Builder builder) { private ListeningWhitelist(Builder builder) {
this.priority = builder.priority; this.priority = builder.priority;
this.whitelist = builder.whitelist; this.types = builder.types;
this.gamePhase = builder.gamePhase; this.gamePhase = builder.gamePhase;
this.options = builder.options; this.options = builder.options;
} }
/** /**
* Creates a packet whitelist for a given priority with a set of packet IDs. * 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 priority - the listener priority.
* @param whitelist - set of IDs to observe/enable. * @param whitelist - set of IDs to observe/enable.
*/ */
@Deprecated
public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist) { public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist) {
this(priority, whitelist, GamePhase.PLAYING); this(priority, whitelist, GamePhase.PLAYING);
} }
/** /**
* Creates a packet whitelist for a given priority with a set of packet IDs. * 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 priority - the listener priority.
* @param whitelist - set of IDs to observe/enable. * @param whitelist - set of IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on. * @param gamePhase - which game phase to receieve notifications on.
*/ */
@Deprecated
public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist, GamePhase gamePhase) { public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist, GamePhase gamePhase) {
this.priority = priority; this.priority = priority;
this.whitelist = safeSet(whitelist); this.types = PacketRegistry.toPacketTypes(safeSet(whitelist));
this.gamePhase = gamePhase; this.gamePhase = gamePhase;
this.options = EnumSet.noneOf(ListenerOptions.class); this.options = EnumSet.noneOf(ListenerOptions.class);
} }
/** /**
* Creates a packet whitelist of a given priority for a list of packets. * 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 priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable. * @param whitelist - list of packet IDs to observe/enable.
*/ */
@Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer... whitelist) { public ListeningWhitelist(ListenerPriority priority, Integer... whitelist) {
this.priority = priority; this.priority = priority;
this.whitelist = Sets.newHashSet(whitelist); this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = GamePhase.PLAYING; this.gamePhase = GamePhase.PLAYING;
this.options = EnumSet.noneOf(ListenerOptions.class); this.options = EnumSet.noneOf(ListenerOptions.class);
} }
/** /**
* Creates a packet whitelist for a given priority with a set of packet IDs. * 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 priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable. * @param whitelist - list of packet IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on. * @param gamePhase - which game phase to receieve notifications on.
*/ */
@Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase) { public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase) {
this.priority = priority; this.priority = priority;
this.whitelist = Sets.newHashSet(whitelist); this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = gamePhase; this.gamePhase = gamePhase;
this.options = EnumSet.noneOf(ListenerOptions.class); this.options = EnumSet.noneOf(ListenerOptions.class);
} }
/** /**
* Creates a packet whitelist for a given priority with a set of packet IDs and options. * 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 priority - the listener priority.
* @param whitelist - list of packet IDs to observe/enable. * @param whitelist - list of packet IDs to observe/enable.
* @param gamePhase - which game phase to receieve notifications on. * @param gamePhase - which game phase to receieve notifications on.
* @param options - every special option associated with this whitelist. * @param options - every special option associated with this whitelist.
*/ */
@Deprecated
public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase, ListenerOptions... options) { public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase, ListenerOptions... options) {
this.priority = priority; this.priority = priority;
this.whitelist = Sets.newHashSet(whitelist); this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
this.gamePhase = gamePhase; this.gamePhase = gamePhase;
this.options = safeEnumSet(Arrays.asList(options), ListenerOptions.class); this.options = safeEnumSet(Arrays.asList(options), ListenerOptions.class);
} }
@ -117,7 +137,7 @@ public class ListeningWhitelist {
* @return TRUE if there are any packets, FALSE otherwise. * @return TRUE if there are any packets, FALSE otherwise.
*/ */
public boolean isEnabled() { public boolean isEnabled() {
return whitelist != null && whitelist.size() > 0; return types != null && types.size() > 0;
} }
/** /**
@ -130,10 +150,23 @@ public class ListeningWhitelist {
/** /**
* Retrieves the list of packets that will be observed by the listeners. * Retrieves the list of packets that will be observed by the listeners.
* <p>
* Deprecated: Use {@link #getTypes()} instead.
* @return Packet whitelist. * @return Packet whitelist.
*/ */
@Deprecated
public Set<Integer> getWhitelist() { 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;
} }
/** /**
@ -154,7 +187,7 @@ public class ListeningWhitelist {
@Override @Override
public int hashCode() { 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) { if (obj instanceof ListeningWhitelist) {
final ListeningWhitelist other = (ListeningWhitelist) obj; final ListeningWhitelist other = (ListeningWhitelist) obj;
return Objects.equal(priority, other.priority) return Objects.equal(priority, other.priority)
&& Objects.equal(whitelist, other.whitelist) && Objects.equal(types, other.types)
&& Objects.equal(gamePhase, other.gamePhase) && Objects.equal(gamePhase, other.gamePhase)
&& Objects.equal(options, other.options); && Objects.equal(options, other.options);
} else { } else {
@ -208,7 +241,7 @@ public class ListeningWhitelist {
else else
return Objects.toStringHelper(this). return Objects.toStringHelper(this).
add("priority", priority). add("priority", priority).
add("packets", whitelist). add("packets", types).
add("gamephase", gamePhase). add("gamephase", gamePhase).
add("options", options). add("options", options).
toString(); toString();
@ -262,7 +295,7 @@ public class ListeningWhitelist {
*/ */
public static class Builder { public static class Builder {
private ListenerPriority priority; private ListenerPriority priority;
private Set<Integer> whitelist; private Set<PacketType> types;
private GamePhase gamePhase; private GamePhase gamePhase;
private Set<ListenerOptions> options; private Set<ListenerOptions> options;
@ -274,7 +307,7 @@ public class ListeningWhitelist {
if (template != null) { if (template != null) {
priority(template.getPriority()); priority(template.getPriority());
gamePhase(template.getGamePhase()); gamePhase(template.getGamePhase());
whitelist(template.getWhitelist()); types(template.getTypes());
options(template.getOptions()); options(template.getOptions());
} }
} }
@ -289,13 +322,84 @@ public class ListeningWhitelist {
return this; 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. * 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. * @param whitelist - the whitelist of packets.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
@Deprecated
public Builder whitelist(Collection<Integer> whitelist) { 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; return this;
} }
@ -309,6 +413,14 @@ public class ListeningWhitelist {
return this; 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. * Set the options to copy when constructing new whitelists.
* @param options - the options. * @param options - the options.
@ -319,6 +431,16 @@ public class ListeningWhitelist {
return this; 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. * Construct a new whitelist from the values in this builder.
* @return The new whitelist. * @return The new whitelist.

Datei anzeigen

@ -28,6 +28,7 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.ListeningWhitelist; import com.comphenix.protocol.events.ListeningWhitelist;
import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
/** /**
@ -49,15 +50,16 @@ public abstract class MonitorAdapter implements PacketListener {
initialize(plugin, side, logger); initialize(plugin, side, logger);
} }
@SuppressWarnings("deprecation")
private void initialize(Plugin plugin, ConnectionSide side, Logger logger) { private void initialize(Plugin plugin, ConnectionSide side, Logger logger) {
this.plugin = plugin; this.plugin = plugin;
// Recover in case something goes wrong // Recover in case something goes wrong
try { try {
if (side.isForServer()) 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()) 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) { } catch (FieldAccessException e) {
if (side.isForServer()) if (side.isForServer())
this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getRegistry().values(), GamePhase.BOTH); this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getRegistry().values(), GamePhase.BOTH);

Datei anzeigen

@ -22,9 +22,13 @@ import java.util.Set;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -53,21 +57,27 @@ public abstract class PacketAdapter implements PacketListener {
/** /**
* Initialize a packet listener with default priority. * Initialize a packet listener with default priority.
* <p>
* Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener. * @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, Integer... packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, packets); this(plugin, connectionSide, ListenerPriority.NORMAL, packets);
} }
/** /**
* Initialize a packet listener for a single connection side. * Initialize a packet listener for a single connection side.
* <p>
* Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener. * @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority. * @param listenerPriority - the event priority.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Set<Integer> packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Set<Integer> packets) {
this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets.toArray(new Integer[0])); 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. * Initialize a packet listener for a single connection side.
* <p> * <p>
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary. * 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 plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param gamePhase - which game phase this listener is active under. * @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Set<Integer> packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Set<Integer> packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, packets.toArray(new Integer[0])); 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. * Initialize a packet listener for a single connection side.
* <p> * <p>
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary. * 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 plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority. * @param listenerPriority - the event priority.
* @param gamePhase - which game phase this listener is active under. * @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Set<Integer> packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Set<Integer> packets) {
this(plugin, connectionSide, listenerPriority, gamePhase, packets.toArray(new Integer[0])); this(plugin, connectionSide, listenerPriority, gamePhase, packets.toArray(new Integer[0]));
} }
/** /**
* Initialize a packet listener for a single connection side. * Initialize a packet listener for a single connection side.
* <p>
* Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener. * @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority. * @param listenerPriority - the event priority.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Integer... packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Integer... packets) {
this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets); this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets);
} }
/** /**
* Initialize a packet listener for a single connection side. * Initialize a packet listener for a single connection side.
* <p>
* Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener. * @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param options - which listener options to use. * @param options - which listener options to use.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerOptions[] options, Integer... packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerOptions[] options, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, GamePhase.PLAYING, options, packets); this(plugin, connectionSide, ListenerPriority.NORMAL, GamePhase.PLAYING, options, packets);
} }
/** /**
* Initialize a packet listener for a single connection side. * Initialize a packet listener for a single connection side.
* <p>
* Deprecated: Use {@link #params()} instead.
* @param plugin - the plugin that spawned this listener. * @param plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param gamePhase - which game phase this listener is active under. * @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Integer... packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Integer... packets) {
this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, 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. * Initialize a packet listener for a single connection side.
* <p> * <p>
* The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary. * 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 plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority. * @param listenerPriority - the event priority.
* @param gamePhase - which game phase this listener is active under. * @param gamePhase - which game phase this listener is active under.
* @param packets - the packet IDs the listener is looking for. * @param packets - the packet IDs the listener is looking for.
*/ */
@Deprecated
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Integer... packets) { public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Integer... packets) {
this(plugin, connectionSide, listenerPriority, gamePhase, new ListenerOptions[0], 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. * The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
* <p> * <p>
* Listener options must be specified in order for {@link NetworkMarker#getInputBuffer()} to function correctly. * 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 plugin - the plugin that spawned this listener.
* @param connectionSide - the packet type the listener is looking for. * @param connectionSide - the packet type the listener is looking for.
* @param listenerPriority - the event priority. * @param listenerPriority - the event priority.
@ -159,7 +189,21 @@ public abstract class PacketAdapter implements PacketListener {
* @param options - which listener options to use. * @param options - which listener options to use.
* @param packets - the packet IDs the listener is looking for. * @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) if (plugin == null)
throw new IllegalArgumentException("plugin cannot be null"); throw new IllegalArgumentException("plugin cannot be null");
if (connectionSide == null) if (connectionSide == null)
@ -184,9 +228,20 @@ public abstract class PacketAdapter implements PacketListener {
// Add whitelists // Add whitelists
if (connectionSide.isForServer()) 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()) 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.plugin = plugin;
this.connectionSide = connectionSide; this.connectionSide = connectionSide;
@ -292,7 +347,7 @@ public abstract class PacketAdapter implements PacketListener {
public static class AdapterParameteters { public static class AdapterParameteters {
private Plugin plugin; private Plugin plugin;
private ConnectionSide connectionSide; private ConnectionSide connectionSide;
private Integer[] packets; private PacketType[] packets;
// Parameters with default values // Parameters with default values
private GamePhase gamePhase = GamePhase.PLAYING; 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. * Set the packet IDs of the packets the listener is looking for.
* <p> * <p>
* This parameter is required. * This parameter is required.
* <p>
* Deprecated: Use {@link #types(PacketType...)} instead.
* @param packets - the packet IDs to look for. * @param packets - the packet IDs to look for.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
@Deprecated
public AdapterParameteters packets(@Nonnull Integer... packets) { 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; return this;
} }
@ -406,9 +470,33 @@ public abstract class PacketAdapter implements PacketListener {
* @param packets - a set of the packet IDs to look for. * @param packets - a set of the packet IDs to look for.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
@Deprecated
public AdapterParameteters packets(@Nonnull Set<Integer> packets) { public AdapterParameteters packets(@Nonnull Set<Integer> packets) {
return packets(packets.toArray(new Integer[0])); 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]));
}
} }
/** /**

Datei anzeigen

@ -25,6 +25,7 @@ import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -293,6 +294,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
} }
@Override @Override
@Deprecated
public PacketContainer createPacket(int id) { public PacketContainer createPacket(int id) {
if (delegate != null) if (delegate != null)
return delegate.createPacket(id); return delegate.createPacket(id);
@ -300,6 +302,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
} }
@Override @Override
@Deprecated
public PacketContainer createPacket(int id, boolean forceDefaults) { public PacketContainer createPacket(int id, boolean forceDefaults) {
if (delegate != null) { if (delegate != null) {
return delegate.createPacket(id); return delegate.createPacket(id);
@ -337,6 +340,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
} }
@Override @Override
@Deprecated
public Set<Integer> getSendingFilters() { public Set<Integer> getSendingFilters() {
if (delegate != null) { if (delegate != null) {
return delegate.getSendingFilters(); return delegate.getSendingFilters();
@ -352,6 +356,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
} }
@Override @Override
@Deprecated
public Set<Integer> getReceivingFilters() { public Set<Integer> getReceivingFilters() {
if (delegate != null) { if (delegate != null) {
return delegate.getReceivingFilters(); 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 @Override
public void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException { public void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException {
if (delegate != null) if (delegate != null)
@ -426,6 +451,4 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
delegate.close(); delegate.close();
closed = true; closed = true;
} }
} }

Datei anzeigen

@ -17,6 +17,7 @@
package com.comphenix.protocol.injector; package com.comphenix.protocol.injector;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.packet.InterceptWritePacket; import com.comphenix.protocol.injector.packet.InterceptWritePacket;
@ -47,6 +48,13 @@ public interface ListenerInvoker {
@Deprecated @Deprecated
public abstract int getPacketID(Object packet); 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. * Retrieve the object responsible for intercepting write packets.
* @return Object that intercepts write packets. * @return Object that intercepts write packets.
@ -58,6 +66,7 @@ public interface ListenerInvoker {
* @param packetId - the packet to check. * @param packetId - the packet to check.
* @return TRUE if it does, FALSE otherwise. * @return TRUE if it does, FALSE otherwise.
*/ */
@Deprecated
public boolean requireInputBuffer(int packetId); public boolean requireInputBuffer(int packetId);
/** /**
@ -71,6 +80,7 @@ public interface ListenerInvoker {
* @param clazz - class to register. * @param clazz - class to register.
* @param packetID - the the new associated packet ID. * @param packetID - the the new associated packet ID.
*/ */
@Deprecated
public abstract void registerPacketClass(Class<?> clazz, int packetID); 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. * @param forceVanilla - whether or not to look for vanilla classes, not injected classes.
* @return The associated class. * @return The associated class.
*/ */
@Deprecated
public abstract Class<?> getPacketClassFromID(int packetID, boolean forceVanilla); public abstract Class<?> getPacketClassFromID(int packetID, boolean forceVanilla);
} }

Datei anzeigen

@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.util.com.google.common.collect.Sets;
import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.MethodProxy;
@ -49,11 +50,9 @@ import org.bukkit.plugin.PluginManager;
import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.async.AsyncFilterManager; import com.comphenix.protocol.async.AsyncFilterManager;
import com.comphenix.protocol.async.AsyncMarker; import com.comphenix.protocol.async.AsyncMarker;
import com.comphenix.protocol.concurrency.IntegerSet;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.error.ReportType;
@ -148,7 +147,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
private InterceptWritePacket interceptWritePacket; private InterceptWritePacket interceptWritePacket;
// Whether or not a packet must be input buffered // 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 // The two listener containers
private SortedPacketListenerList recievedListeners; private SortedPacketListenerList recievedListeners;
@ -278,8 +277,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Attempt to load the list of server and client packets // Attempt to load the list of server and client packets
try { try {
knowsServerPackets = PacketRegistry.getServerPackets() != null; knowsServerPackets = PacketRegistry.getClientPacketTypes() != null;
knowsClientPackets = PacketRegistry.getClientPackets() != null; knowsClientPackets = PacketRegistry.getServerPacketTypes() != null;
} catch (FieldAccessException e) { } catch (FieldAccessException e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_LOAD_PACKET_LIST).error(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); verifyWhitelist(listener, sending);
sendingListeners.addListener(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 // Make sure this is possible
playerInjection.checkListener(listener); playerInjection.checkListener(listener);
@ -387,7 +386,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (hasReceiving) { if (hasReceiving) {
verifyWhitelist(listener, receiving); verifyWhitelist(listener, receiving);
recievedListeners.addListener(listener, receiving); recievedListeners.addListener(listener, receiving);
enablePacketFilters(listener, ConnectionSide.CLIENT_SIDE, receiving.getWhitelist()); enablePacketFilters(listener, ConnectionSide.CLIENT_SIDE, receiving.getTypes());
} }
if (hasReceiving) if (hasReceiving)
incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE)); incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE));
@ -403,8 +402,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (!whitelist.getGamePhase().hasLogin() && if (!whitelist.getGamePhase().hasLogin() &&
!whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) { !whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) {
for (int id : whitelist.getWhitelist()) { for (PacketType type : whitelist.getTypes()) {
if (loginPackets.isLoginPacket(id, side)) { if (loginPackets.isLoginPacket(type)) {
return GamePhase.BOTH; return GamePhase.BOTH;
} }
} }
@ -416,21 +415,21 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* Invoked when we need to update the input buffer set. * Invoked when we need to update the input buffer set.
*/ */
private void updateRequireInputBuffers() { private void updateRequireInputBuffers() {
IntegerSet updated = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); Set<PacketType> updated = Sets.newHashSet();
for (PacketListener listener : packetListeners) { for (PacketListener listener : packetListeners) {
ListeningWhitelist whitelist = listener.getReceivingWhitelist(); ListeningWhitelist whitelist = listener.getReceivingWhitelist();
// We only check the recieving whitelist // We only check the recieving whitelist
if (whitelist.getOptions().contains(ListenerOptions.INTERCEPT_INPUT_BUFFER)) { if (whitelist.getOptions().contains(ListenerOptions.INTERCEPT_INPUT_BUFFER)) {
for (int id : whitelist.getWhitelist()) { for (PacketType type : whitelist.getTypes()) {
updated.add(id); updated.add(type);
} }
} }
} }
// Update it // Update it
this.inputBufferedPackets = updated; 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. * @throws IllegalArgumentException If the whitelist is illegal.
*/ */
public static void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist) { public static void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist) {
for (Integer id : whitelist.getWhitelist()) { for (PacketType type : whitelist.getTypes()) {
if (id >= 256 || id < 0) { if (type == null) {
throw new IllegalArgumentException(String.format("Invalid packet id %s in listener %s.", throw new IllegalArgumentException(String.format("Packet type in in listener %s was NULL.",
id, PacketAdapter.getPluginName(listener)) PacketAdapter.getPluginName(listener))
); );
} }
} }
@ -498,8 +497,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
if (listener == null) if (listener == null)
throw new IllegalArgumentException("listener cannot be NULL"); throw new IllegalArgumentException("listener cannot be NULL");
List<Integer> sendingRemoved = null; List<PacketType> sendingRemoved = null;
List<Integer> receivingRemoved = null; List<PacketType> receivingRemoved = null;
ListeningWhitelist sending = listener.getSendingWhitelist(); ListeningWhitelist sending = listener.getSendingWhitelist();
ListeningWhitelist receiving = listener.getReceivingWhitelist(); ListeningWhitelist receiving = listener.getReceivingWhitelist();
@ -556,7 +555,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
@Override @Override
public boolean requireInputBuffer(int packetId) { 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. * @param event - the evnet to broadcast.
*/ */
private void handlePacket(SortedPacketListenerList packetListeners, PacketEvent event, boolean sending) { private void handlePacket(SortedPacketListenerList packetListeners, PacketEvent event, boolean sending) {
// By default, asynchronous packets are queued for processing // By default, asynchronous packets are queued for processing
if (asyncFilterManager.hasAsynchronousListeners(event)) { if (asyncFilterManager.hasAsynchronousListeners(event)) {
event.setAsyncMarker(asyncFilterManager.createAsyncMarker()); 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 side - which side the event will arrive from.
* @param packets - the packet id(s). * @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) if (side == null)
throw new IllegalArgumentException("side cannot be NULL."); throw new IllegalArgumentException("side cannot be NULL.");
// Note the difference between unsupported and valid. // Note the difference between unsupported and valid.
// Every packet ID between and including 0 - 255 is valid, but only a subset is supported. // 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 // Only register server packets that are actually supported by Minecraft
if (side.isForServer()) { if (side.isForServer()) {
// Note that we may update the packet list here // Note that we may update the packet list here
if (!knowsServerPackets || PacketRegistry.getServerPackets().contains(packetID)) if (!knowsServerPackets || PacketRegistry.getServerPacketTypes().contains(type))
playerInjection.addPacketHandler(packetID); playerInjection.addPacketHandler(type);
else else
reporter.reportWarning(this, 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 // As above, only for client packets
if (side.isForClient() && packetInjector != null) { if (side.isForClient() && packetInjector != null) {
if (!knowsClientPackets || PacketRegistry.getClientPackets().contains(packetID)) if (!knowsClientPackets || PacketRegistry.getClientPacketTypes().contains(type))
packetInjector.addPacketHandler(packetID); packetInjector.addPacketHandler(type);
else else
reporter.reportWarning(this, 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 packets - the packet id(s).
* @param side - which side the event no longer should arrive from. * @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) if (side == null)
throw new IllegalArgumentException("side cannot be NULL."); throw new IllegalArgumentException("side cannot be NULL.");
for (int packetID : packets) { for (PacketType type : packets) {
if (side.isForServer()) if (side.isForServer())
playerInjection.removePacketHandler(packetID); playerInjection.removePacketHandler(type);
if (side.isForClient() && packetInjector != null) if (side.isForClient() && packetInjector != null)
packetInjector.removePacketHandler(packetID); packetInjector.removePacketHandler(type);
} }
} }
@ -814,13 +812,25 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
} }
@Override @Override
@Deprecated
public PacketContainer createPacket(int id) { public PacketContainer createPacket(int id) {
return createPacket(id, true); return createPacket(PacketType.findLegacy(id), true);
} }
@Override @Override
public PacketContainer createPacket(PacketType type) {
return createPacket(type, true);
}
@Override
@Deprecated
public PacketContainer createPacket(int id, boolean forceDefaults) { 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 // Use any default values if possible
if (forceDefaults) { if (forceDefaults) {
@ -846,13 +856,23 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
} }
@Override @Override
@Deprecated
public Set<Integer> getSendingFilters() { public Set<Integer> getSendingFilters() {
return playerInjection.getSendingFilters(); return PacketRegistry.toLegacy(playerInjection.getSendingFilters());
} }
@Override @Override
public Set<Integer> getReceivingFilters() { 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 @Override
@ -993,16 +1013,22 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
} }
@Override @Override
@Deprecated
public int getPacketID(Object packet) { public int getPacketID(Object packet) {
return getPacketType(packet).getLegacyId();
}
@Override
public PacketType getPacketType(Object packet) {
if (packet == null) if (packet == null)
throw new IllegalArgumentException("Packet cannot be NULL."); throw new IllegalArgumentException("Packet cannot be NULL.");
if (!MinecraftReflection.isPacketClass(packet)) if (!MinecraftReflection.isPacketClass(packet))
throw new IllegalArgumentException("The given object " + packet + " is not a 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) { if (type != null) {
return id; return type;
} else { } else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Unable to find associated packet of " + packet + ": Lookup returned NULL."); "Unable to find associated packet of " + packet + ": Lookup returned NULL.");
@ -1010,16 +1036,19 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
} }
@Override @Override
@Deprecated
public void registerPacketClass(Class<?> clazz, int packetID) { public void registerPacketClass(Class<?> clazz, int packetID) {
PacketRegistry.getPacketToID().put(clazz, packetID); PacketRegistry.getPacketToID().put(clazz, packetID);
} }
@Override @Override
@Deprecated
public void unregisterPacketClass(Class<?> clazz) { public void unregisterPacketClass(Class<?> clazz) {
PacketRegistry.getPacketToID().remove(clazz); PacketRegistry.getPacketToID().remove(clazz);
} }
@Override @Override
@Deprecated
public Class<?> getPacketClassFromID(int packetID, boolean forceVanilla) { public Class<?> getPacketClassFromID(int packetID, boolean forceVanilla) {
return PacketRegistry.getPacketClassFromID(packetID, 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. * @return An immutable set of every known server packet.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft. * @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
*/ */
@Deprecated
public static Set<Integer> getServerPackets() throws FieldAccessException { public static Set<Integer> getServerPackets() throws FieldAccessException {
return PacketRegistry.getServerPackets(); return PacketRegistry.getServerPackets();
} }
@ -1124,6 +1154,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @return An immutable set of every known client packet. * @return An immutable set of every known client packet.
* @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft. * @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft.
*/ */
@Deprecated
public static Set<Integer> getClientPackets() throws FieldAccessException { public static Set<Integer> getClientPackets() throws FieldAccessException {
return PacketRegistry.getClientPackets(); return PacketRegistry.getClientPackets();
} }

Datei anzeigen

@ -19,7 +19,6 @@ package com.comphenix.protocol.injector;
import java.util.Collection; import java.util.Collection;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap; import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.ListenerPriority;
@ -39,7 +38,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
private TimedListenerManager timedManager = TimedListenerManager.getInstance(); private TimedListenerManager timedManager = TimedListenerManager.getInstance();
public SortedPacketListenerList() { 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. * @param event - the packet event to invoke.
*/ */
public void invokePacketRecieving(ErrorReporter reporter, PacketEvent event) { public void invokePacketRecieving(ErrorReporter reporter, PacketEvent event) {
Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID()); Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketType());
if (list == null) if (list == null)
return; return;
@ -77,7 +76,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param priorityFilter - the required priority for a listener to be invoked. * @param priorityFilter - the required priority for a listener to be invoked.
*/ */
public void invokePacketRecieving(ErrorReporter reporter, PacketEvent event, ListenerPriority priorityFilter) { 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) if (list == null)
return; return;
@ -131,7 +130,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param event - the packet event to invoke. * @param event - the packet event to invoke.
*/ */
public void invokePacketSending(ErrorReporter reporter, PacketEvent event) { public void invokePacketSending(ErrorReporter reporter, PacketEvent event) {
Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID()); Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketType());
if (list == null) if (list == null)
return; return;
@ -159,7 +158,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
* @param priorityFilter - the required priority for a listener to be invoked. * @param priorityFilter - the required priority for a listener to be invoked.
*/ */
public void invokePacketSending(ErrorReporter reporter, PacketEvent event, ListenerPriority priorityFilter) { 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) if (list == null)
return; return;

Datei anzeigen

@ -10,7 +10,6 @@ import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; 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.buffer.ByteBuf;
import net.minecraft.util.io.netty.channel.Channel; import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelHandler; 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.NetworkMarker;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketOutputHandler; 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.SocketInjector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.FuzzyReflection; 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. * 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. * @return TRUE if we do, FALSE otherwise.
*/ */
public boolean includeBuffer(int packetId); public boolean includeBuffer(Class<?> packetClass);
/** /**
* Retrieve the current error reporter. * Retrieve the current error reporter.
@ -326,10 +324,10 @@ class ChannelInjector extends ByteToMessageDecoder {
if (packets.size() > 0) { if (packets.size() > 0) {
Object input = packets.get(0); Object input = packets.get(0);
int id = PacketRegistry.getPacketID(input.getClass()); Class<?> packetClass = input.getClass();
NetworkMarker marker = null; NetworkMarker marker = null;
if (channelListener.includeBuffer(id)) { if (channelListener.includeBuffer(packetClass)) {
byteBuffer.resetReaderIndex(); byteBuffer.resetReaderIndex();
marker = new NetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer)); marker = new NetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer));
} }

Datei anzeigen

@ -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.ChannelInboundHandlerAdapter;
import net.minecraft.util.io.netty.channel.ChannelInitializer; import net.minecraft.util.io.netty.channel.ChannelInitializer;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.concurrency.PacketTypeSet;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker; 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.ListenerInvoker;
import com.comphenix.protocol.injector.netty.ChannelInjector.ChannelListener; import com.comphenix.protocol.injector.netty.ChannelInjector.ChannelListener;
import com.comphenix.protocol.injector.packet.PacketInjector; 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.player.PlayerInjectionHandler;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.injector.spigot.AbstractPacketInjector; import com.comphenix.protocol.injector.spigot.AbstractPacketInjector;
@ -46,11 +47,11 @@ public class NettyProtocolInjector implements ChannelListener {
private List<VolatileField> bootstrapFields = Lists.newArrayList(); private List<VolatileField> bootstrapFields = Lists.newArrayList();
// Different sending filters // Different sending filters
private IntegerSet queuedFilters = new IntegerSet(Packets.PACKET_COUNT); private PacketTypeSet queuedFilters = new PacketTypeSet();
private IntegerSet reveivedFilters = new IntegerSet(Packets.PACKET_COUNT); private PacketTypeSet reveivedFilters = new PacketTypeSet();
// Which packets are buffered // Which packets are buffered
private Set<Integer> bufferedPackets; private PacketTypeSet bufferedPackets;
private ListenerInvoker invoker; private ListenerInvoker invoker;
// Handle errors // Handle errors
@ -172,14 +173,14 @@ public class NettyProtocolInjector implements ChannelListener {
@Override @Override
public Object onPacketSending(ChannelInjector injector, Object packet, NetworkMarker marker) { 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 // Check for ignored packets
if (injector.unignorePacket(packet)) { if (injector.unignorePacket(packet)) {
return packet; return packet;
} }
PacketContainer container = new PacketContainer(id, packet); PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet);
PacketEvent event = packetQueued(container, injector.getPlayer()); PacketEvent event = packetQueued(container, injector.getPlayer());
if (!event.isCancelled()) { if (!event.isCancelled()) {
@ -195,14 +196,14 @@ public class NettyProtocolInjector implements ChannelListener {
@Override @Override
public Object onPacketReceiving(ChannelInjector injector, Object packet, NetworkMarker marker) { 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 // Check for ignored packets
if (injector.unignorePacket(packet)) { if (injector.unignorePacket(packet)) {
return packet; return packet;
} }
PacketContainer container = new PacketContainer(id, packet); PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet);
PacketEvent event = packetReceived(container, injector.getPlayer(), marker); PacketEvent event = packetReceived(container, injector.getPlayer(), marker);
if (!event.isCancelled()) { if (!event.isCancelled()) {
@ -216,8 +217,8 @@ public class NettyProtocolInjector implements ChannelListener {
} }
@Override @Override
public boolean includeBuffer(int packetId) { public boolean includeBuffer(Class<?> packetClass) {
return bufferedPackets.contains(packetId); return bufferedPackets.contains(packetClass);
} }
/** /**
@ -313,8 +314,8 @@ public class NettyProtocolInjector implements ChannelListener {
} }
@Override @Override
public void inputBuffersChanged(Set<Integer> set) { public void inputBuffersChanged(Set<PacketType> set) {
bufferedPackets = set; bufferedPackets = new PacketTypeSet(set);
} }
}; };
} }

Datei anzeigen

@ -98,6 +98,7 @@ public class InterceptWritePacket {
return proxyClass; return proxyClass;
} }
@SuppressWarnings("deprecation")
private Class<?> getProxyClass(int packetId) { private Class<?> getProxyClass(int packetId) {
Class<?> stored = proxyClasses.get(packetId); Class<?> stored = proxyClasses.get(packetId);
@ -119,6 +120,7 @@ public class InterceptWritePacket {
* Construct a new instance of the proxy object. * Construct a new instance of the proxy object.
* @return New instance of proxy, or NULL if we failed. * @return New instance of proxy, or NULL if we failed.
*/ */
@SuppressWarnings("deprecation")
public Object constructProxy(Object proxyObject, PacketEvent event, NetworkMarker marker) { public Object constructProxy(Object proxyObject, PacketEvent event, NetworkMarker marker) {
Class<?> proxyClass = null; Class<?> proxyClass = null;
@ -141,6 +143,7 @@ public class InterceptWritePacket {
/** /**
* Invoked when the write packet proxy class should be removed. * Invoked when the write packet proxy class should be removed.
*/ */
@SuppressWarnings("deprecation")
public void cleanup() { public void cleanup() {
// Remove all proxy classes from the registry // Remove all proxy classes from the registry
for (Class<?> stored : proxyClasses.values()) { for (Class<?> stored : proxyClasses.values()) {

Datei anzeigen

@ -4,6 +4,7 @@ import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
@ -28,37 +29,37 @@ public interface PacketInjector {
public abstract void setCancelled(Object packet, boolean cancelled); public abstract void setCancelled(Object packet, boolean cancelled);
/** /**
* Start intercepting packets with the given packet ID. * Start intercepting packets with the given packet type.
* @param packetID - the ID of the packets to start intercepting. * @param type - the type of the packets to start intercepting.
* @return TRUE if we didn't already intercept these packets, FALSE otherwise. * @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. * Stop intercepting packets with the given packet type.
* @param packetID - the ID of the packets to stop intercepting. * @param type - the type of the packets to stop intercepting.
* @return TRUE if we successfuly stopped intercepting a given packet ID, FALSE otherwise. * @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. * Determine if packets with the given packet type is being intercepted.
* @param packetID - the packet ID to lookup. * @param type - the packet type to lookup.
* @return TRUE if we do, FALSE otherwise. * @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. * Invoked when input buffers have changed.
* @param set - the new set of packets that require the read buffer. * @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. * Retrieve every intercepted packet type.
* @return Every intercepted packet ID. * @return Every intercepted packet type.
*/ */
public abstract Set<Integer> getPacketHandlers(); public abstract Set<PacketType> getPacketHandlers();
/** /**
* Let the packet listeners process the given packet. * Let the packet listeners process the given packet.

Datei anzeigen

@ -283,7 +283,7 @@ public class PacketRegistry {
* @param types - packet type. * @param types - packet type.
* @return Set of integers. * @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(); Set<Integer> result = Sets.newHashSet();
for (PacketType type : types) for (PacketType type : types)
@ -296,7 +296,7 @@ public class PacketRegistry {
* @param types - legacy packet IDs. * @param types - legacy packet IDs.
* @return Set of packet types. * @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(); Set<PacketType> result = Sets.newHashSet();
for (int id : ids) for (int id : ids)

Datei anzeigen

@ -32,6 +32,7 @@ import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.CallbackFilter; import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.NoOp; import net.sf.cglib.proxy.NoOp;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.error.ReportType;
@ -196,14 +197,16 @@ class ProxyPacketInjector implements PacketInjector {
} }
@Override @Override
public void inputBuffersChanged(Set<Integer> set) { public void inputBuffersChanged(Set<PacketType> set) {
// No need to do anything // No need to do anything
} }
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings({"rawtypes", "deprecation"})
public boolean addPacketHandler(int packetID) { public boolean addPacketHandler(PacketType type) {
if (hasPacketHandler(packetID)) final int packetID = type.getLegacyId();
if (hasPacketHandler(type))
return false; return false;
Enhancer ex = new Enhancer(); Enhancer ex = new Enhancer();
@ -216,15 +219,15 @@ class ProxyPacketInjector implements PacketInjector {
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets(); Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets(); Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
Map<Class, Integer> registry = PacketRegistry.getPacketToID(); Map<Class, Integer> registry = PacketRegistry.getPacketToID();
Class old = PacketRegistry.getPacketClassFromID(packetID); Class old = PacketRegistry.getPacketClassFromType(type);
// If this packet is not known // If this packet is not known
if (old == null) { 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 // Check for previous injections
if (Factory.class.isAssignableFrom(old)) { 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) { if (filter == null) {
@ -275,9 +278,11 @@ class ProxyPacketInjector implements PacketInjector {
} }
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings({"rawtypes", "deprecation"})
public boolean removePacketHandler(int packetID) { public boolean removePacketHandler(PacketType type) {
if (!hasPacketHandler(packetID)) final int packetID = type.getLegacyId();
if (!hasPacketHandler(type))
return false; return false;
Map<Class, Integer> registry = PacketRegistry.getPacketToID(); Map<Class, Integer> registry = PacketRegistry.getPacketToID();
@ -285,7 +290,7 @@ class ProxyPacketInjector implements PacketInjector {
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets(); Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
Class old = previous.get(packetID); Class old = previous.get(packetID);
Class proxy = PacketRegistry.getPacketClassFromID(packetID); Class proxy = PacketRegistry.getPacketClassFromType(type);
lookup.setLookup(packetID, old); lookup.setLookup(packetID, old);
previous.remove(packetID); previous.remove(packetID);
@ -299,18 +304,21 @@ class ProxyPacketInjector implements PacketInjector {
* @param packetId - the packet to check. * @param packetId - the packet to check.
* @return TRUE if it does, FALSE otherwise. * @return TRUE if it does, FALSE otherwise.
*/ */
@Deprecated
public boolean requireInputBuffers(int packetId) { public boolean requireInputBuffers(int packetId) {
return manager.requireInputBuffer(packetId); return manager.requireInputBuffer(packetId);
} }
@SuppressWarnings("deprecation")
@Override @Override
public boolean hasPacketHandler(int packetID) { public boolean hasPacketHandler(PacketType type) {
return PacketRegistry.getPreviousPackets().containsKey(packetID); return PacketRegistry.getPreviousPackets().containsKey(type.getLegacyId());
} }
@SuppressWarnings("deprecation")
@Override @Override
public Set<Integer> getPacketHandlers() { public Set<PacketType> getPacketHandlers() {
return PacketRegistry.getPreviousPackets().keySet(); return PacketRegistry.toPacketTypes(PacketRegistry.getPreviousPackets().keySet());
} }
// Called from the ReadPacketModified monitor // Called from the ReadPacketModified monitor
@ -327,7 +335,7 @@ class ProxyPacketInjector implements PacketInjector {
return packetRecieved(packet, client, buffered); return packetRecieved(packet, client, buffered);
} else { } else {
// The timeout elapsed! // 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; return null;
} }
@ -348,14 +356,14 @@ class ProxyPacketInjector implements PacketInjector {
} }
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings({"rawtypes", "deprecation"})
public synchronized void cleanupAll() { public synchronized void cleanupAll() {
Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets(); Map<Integer, Class> overwritten = PacketRegistry.getOverwrittenPackets();
Map<Integer, Class> previous = PacketRegistry.getPreviousPackets(); Map<Integer, Class> previous = PacketRegistry.getPreviousPackets();
// Remove every packet handler // Remove every packet handler
for (Integer id : previous.keySet().toArray(new Integer[0])) { for (Integer id : previous.keySet().toArray(new Integer[0])) {
removePacketHandler(id); removePacketHandler(PacketType.findLegacy(id));
} }
overwritten.clear(); overwritten.clear();

Datei anzeigen

@ -96,6 +96,7 @@ class ReadPacketModifier implements MethodInterceptor {
return getOverride(packet) == CANCEL_MARKER; return getOverride(packet) == CANCEL_MARKER;
} }
@SuppressWarnings("deprecation")
@Override @Override
public Object intercept(Object thisObj, Method method, Object[] args, MethodProxy proxy) throws Throwable { public Object intercept(Object thisObj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
// Atomic retrieval // Atomic retrieval

Datei anzeigen

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.error.ReportType;
@ -110,10 +111,11 @@ class InjectedArrayList extends ArrayList<Object> {
* @param source - packet to invert. * @param source - packet to invert.
* @return The inverted packet. * @return The inverted packet.
*/ */
@SuppressWarnings("deprecation")
Object createNegativePacket(Object source) { Object createNegativePacket(Object source) {
ListenerInvoker invoker = injector.getInvoker(); 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 // We want to subtract the byte amount that were added to the running
// total of outstanding packets. Otherwise, cancelling too many packets // total of outstanding packets. Otherwise, cancelling too many packets
@ -145,7 +147,7 @@ class InjectedArrayList extends ArrayList<Object> {
try { try {
// Temporarily associate the fake packet class // Temporarily associate the fake packet class
invoker.registerPacketClass(proxyClass, packetID); invoker.registerPacketClass(proxyClass, type.getLegacyId());
Object proxy = proxyClass.newInstance(); Object proxy = proxyClass.newInstance();
InjectedArrayList.registerDelegate(proxy, source); InjectedArrayList.registerDelegate(proxy, source);

Datei anzeigen

@ -133,6 +133,7 @@ class NetworkFieldInjector extends PlayerInjector {
return null; return null;
} else { } else {
@SuppressWarnings("deprecation")
int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK }; int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK };
// Unfortunately, we don't support chunk packets // Unfortunately, we don't support chunk packets

Datei anzeigen

@ -130,6 +130,7 @@ public class NetworkObjectInjector extends PlayerInjector {
return null; return null;
} else { } else {
@SuppressWarnings("deprecation")
int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK }; int[] unsupported = { Packets.Server.MAP_CHUNK, Packets.Server.MAP_CHUNK_BULK };
// Unfortunately, we don't support chunk packets // Unfortunately, we don't support chunk packets

Datei anzeigen

@ -7,6 +7,7 @@ import java.net.InetSocketAddress;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.NetworkMarker; import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
@ -59,16 +60,16 @@ public interface PlayerInjectionHandler {
public abstract void setPlayerHook(GamePhase phase, PlayerInjectHooks playerHook); public abstract void setPlayerHook(GamePhase phase, PlayerInjectHooks playerHook);
/** /**
* Add an underlying packet handler of the given ID. * Add an underlying packet handler of the given type.
* @param packetID - packet ID to register. * @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. * Remove an underlying packet handler of this type.
* @param packetID - packet ID to unregister. * @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. * Retrieve a player by its DataInput connection.
@ -157,7 +158,7 @@ public interface PlayerInjectionHandler {
* Retrieve the current list of registered sending listeners. * Retrieve the current list of registered sending listeners.
* @return List of the sending listeners's packet IDs. * @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. * Whether or not this player injection handler can also recieve packets.

Datei anzeigen

@ -581,6 +581,7 @@ public abstract class PlayerInjector implements SocketInjector {
* @param packet - packet to sent. * @param packet - packet to sent.
* @return The given packet, or the packet replaced by the listeners. * @return The given packet, or the packet replaced by the listeners.
*/ */
@SuppressWarnings("deprecation")
public Object handlePacketSending(Object packet) { public Object handlePacketSending(Object packet) {
try { try {
// Get the packet ID too // Get the packet ID too

Datei anzeigen

@ -34,6 +34,7 @@ import net.sf.cglib.proxy.Factory;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.Packets;
import com.comphenix.protocol.concurrency.BlockingHashMap; import com.comphenix.protocol.concurrency.BlockingHashMap;
import com.comphenix.protocol.concurrency.IntegerSet; 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.ListenerInvoker;
import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.PlayerLoggedOutException;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; 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.AbstractInputStreamLookup;
import com.comphenix.protocol.injector.server.BukkitSocketInjector; import com.comphenix.protocol.injector.server.BukkitSocketInjector;
import com.comphenix.protocol.injector.server.InputStreamLookupBuilder; import com.comphenix.protocol.injector.server.InputStreamLookupBuilder;
@ -199,22 +201,14 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
checkListener(packetListeners); checkListener(packetListeners);
} }
/**
* Add an underlying packet handler of the given ID.
* @param packetID - packet ID to register.
*/
@Override @Override
public void addPacketHandler(int packetID) { public void addPacketHandler(PacketType type) {
sendingFilters.add(packetID); sendingFilters.add(type.getLegacyId());
} }
/**
* Remove an underlying packet handler of ths ID.
* @param packetID - packet ID to unregister.
*/
@Override @Override
public void removePacketHandler(int packetID) { public void removePacketHandler(PacketType type) {
sendingFilters.remove(packetID); sendingFilters.remove(type.getLegacyId());
} }
/** /**
@ -545,7 +539,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
} else { } else {
throw new PlayerLoggedOutException(String.format( throw new PlayerLoggedOutException(String.format(
"Unable to send packet %s (%s): Player %s has logged out.", "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 // These are illegal
for (int packetID : result.getPackets()) 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. * @return List of the sending listeners's packet IDs.
*/ */
@Override @Override
public Set<Integer> getSendingFilters() { public Set<PacketType> getSendingFilters() {
return sendingFilters.toSet(); return PacketRegistry.toPacketTypes(sendingFilters.toSet());
} }
@Override @Override

Datei anzeigen

@ -2,13 +2,14 @@ package com.comphenix.protocol.injector.spigot;
import java.util.Set; 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; import com.comphenix.protocol.injector.packet.PacketInjector;
public abstract class AbstractPacketInjector implements PacketInjector { public abstract class AbstractPacketInjector implements PacketInjector {
private IntegerSet reveivedFilters; private PacketTypeSet reveivedFilters;
public AbstractPacketInjector(IntegerSet reveivedFilters) { public AbstractPacketInjector(PacketTypeSet reveivedFilters) {
this.reveivedFilters = reveivedFilters; this.reveivedFilters = reveivedFilters;
} }
@ -24,25 +25,25 @@ public abstract class AbstractPacketInjector implements PacketInjector {
} }
@Override @Override
public boolean addPacketHandler(int packetID) { public boolean addPacketHandler(PacketType type) {
reveivedFilters.add(packetID); reveivedFilters.addType(type);
return true; return true;
} }
@Override @Override
public boolean removePacketHandler(int packetID) { public boolean removePacketHandler(PacketType type) {
reveivedFilters.remove(packetID); reveivedFilters.removeType(type);
return true; return true;
} }
@Override @Override
public boolean hasPacketHandler(int packetID) { public boolean hasPacketHandler(PacketType type) {
return reveivedFilters.contains(packetID); return reveivedFilters.contains(type);
} }
@Override @Override
public Set<Integer> getPacketHandlers() { public Set<PacketType> getPacketHandlers() {
return reveivedFilters.toSet(); return reveivedFilters.values();
} }
@Override @Override

Datei anzeigen

@ -5,16 +5,17 @@ import java.util.Set;
import org.bukkit.entity.Player; 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.events.PacketListener;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler; import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
public abstract class AbstractPlayerHandler implements PlayerInjectionHandler { public abstract class AbstractPlayerHandler implements PlayerInjectionHandler {
protected IntegerSet sendingFilters; protected PacketTypeSet sendingFilters;
public AbstractPlayerHandler(IntegerSet sendingFilters) { public AbstractPlayerHandler(PacketTypeSet sendingFilters) {
this.sendingFilters = sendingFilters; this.sendingFilters = sendingFilters;
} }
@ -29,18 +30,18 @@ public abstract class AbstractPlayerHandler implements PlayerInjectionHandler {
} }
@Override @Override
public void addPacketHandler(int packetID) { public void addPacketHandler(PacketType type) {
sendingFilters.add(packetID); sendingFilters.addType(type);
} }
@Override @Override
public void removePacketHandler(int packetID) { public void removePacketHandler(PacketType type) {
sendingFilters.remove(packetID); sendingFilters.removeType(type);
} }
@Override @Override
public Set<Integer> getSendingFilters() { public Set<PacketType> getSendingFilters() {
return sendingFilters.toSet(); return sendingFilters.values();
} }
@Override @Override

Datei anzeigen

@ -4,8 +4,8 @@ import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.concurrency.PacketTypeSet;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.packet.PacketInjector; import com.comphenix.protocol.injector.packet.PacketInjector;
@ -18,23 +18,23 @@ import com.google.common.collect.Sets;
*/ */
class DummyPacketInjector extends AbstractPacketInjector implements PacketInjector { class DummyPacketInjector extends AbstractPacketInjector implements PacketInjector {
private SpigotPacketInjector injector; 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); super(reveivedFilters);
this.injector = injector; this.injector = injector;
} }
@Override @Override
public void inputBuffersChanged(Set<Integer> set) { public void inputBuffersChanged(Set<PacketType> set) {
Set<Integer> removed = Sets.difference(lastBufferedPackets.toSet(), set); Set<PacketType> removed = Sets.difference(lastBufferedPackets.values(), set);
Set<Integer> added = Sets.difference(set, lastBufferedPackets.toSet()); Set<PacketType> added = Sets.difference(set, lastBufferedPackets.values());
// Update the proxy packet injector // Update the proxy packet injector
for (int packet : removed) { for (PacketType packet : removed) {
injector.getProxyPacketInjector().removePacketHandler(packet); injector.getProxyPacketInjector().removePacketHandler(packet);
} }
for (int packet : added) { for (PacketType packet : added) {
injector.getProxyPacketInjector().addPacketHandler(packet); injector.getProxyPacketInjector().addPacketHandler(packet);
} }
} }

Datei anzeigen

@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.bukkit.entity.Player; 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.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
@ -17,7 +17,8 @@ import com.comphenix.protocol.events.PacketEvent;
*/ */
class DummyPlayerHandler extends AbstractPlayerHandler { class DummyPlayerHandler extends AbstractPlayerHandler {
private SpigotPacketInjector injector; private SpigotPacketInjector injector;
public DummyPlayerHandler(SpigotPacketInjector injector, IntegerSet sendingFilters) {
public DummyPlayerHandler(SpigotPacketInjector injector, PacketTypeSet sendingFilters) {
super(sendingFilters); super(sendingFilters);
this.injector = injector; this.injector = injector;
} }

Datei anzeigen

@ -22,8 +22,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.NoOp; import net.sf.cglib.proxy.NoOp;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.concurrency.PacketTypeSet;
import com.comphenix.protocol.concurrency.IntegerSet;
import com.comphenix.protocol.error.DelegatedErrorReporter; import com.comphenix.protocol.error.DelegatedErrorReporter;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.Report;
@ -80,8 +79,8 @@ public class SpigotPacketInjector implements SpigotPacketListener {
private Plugin plugin; private Plugin plugin;
// Different sending filters // Different sending filters
private IntegerSet queuedFilters; private PacketTypeSet queuedFilters;
private IntegerSet reveivedFilters; private PacketTypeSet reveivedFilters;
// NetworkManager to injector and player // NetworkManager to injector and player
private ConcurrentMap<Object, NetworkObjectInjector> networkManagerInjector = Maps.newConcurrentMap(); private ConcurrentMap<Object, NetworkObjectInjector> networkManagerInjector = Maps.newConcurrentMap();
@ -109,8 +108,8 @@ public class SpigotPacketInjector implements SpigotPacketListener {
this.reporter = reporter; this.reporter = reporter;
this.invoker = invoker; this.invoker = invoker;
this.server = server; this.server = server;
this.queuedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); this.queuedFilters = new PacketTypeSet();
this.reveivedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); this.reveivedFilters = new PacketTypeSet();
} }
/** /**
@ -417,9 +416,10 @@ public class SpigotPacketInjector implements SpigotPacketListener {
@Override @Override
public Object packetReceived(Object networkManager, Object connection, Object packet) { public Object packetReceived(Object networkManager, Object connection, Object packet) {
Integer id = invoker.getPacketID(packet); if (reveivedFilters.contains(packet.getClass())) {
@SuppressWarnings("deprecation")
Integer id = invoker.getPacketID(packet);
if (id != null && reveivedFilters.contains(id)) {
// Check for ignored packets // Check for ignored packets
if (ignoredPackets.remove(packet)) { if (ignoredPackets.remove(packet)) {
return packet; return packet;
@ -440,9 +440,10 @@ public class SpigotPacketInjector implements SpigotPacketListener {
@Override @Override
public Object packetQueued(Object networkManager, Object connection, Object packet) { public Object packetQueued(Object networkManager, Object connection, Object packet) {
Integer id = invoker.getPacketID(packet); if (queuedFilters.contains(packet.getClass())) {
@SuppressWarnings("deprecation")
Integer id = invoker.getPacketID(packet);
if (id != null && queuedFilters.contains(id)) {
// Check for ignored packets // Check for ignored packets
if (ignoredPackets.remove(packet)) { if (ignoredPackets.remove(packet)) {
return packet; return packet;

Datei anzeigen

@ -383,7 +383,7 @@ public class BukkitConverters {
@Override @Override
protected NbtBase<?> getSpecificValue(Object generic) { protected NbtBase<?> getSpecificValue(Object generic) {
return NbtFactory.fromNMS(generic); return NbtFactory.fromNMS(generic, null);
} }
@Override @Override

Datei anzeigen

@ -8,7 +8,7 @@ import java.util.UUID;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
@ -132,7 +132,7 @@ public class WrappedAttribute {
*/ */
public PacketContainer getParentPacket() { public PacketContainer getParentPacket() {
return new PacketContainer( return new PacketContainer(
Packets.Server.UPDATE_ATTRIBUTES, PacketType.Play.Server.UPDATE_ATTRIBUTES,
modifier.withType(MinecraftReflection.getPacketClass()).read(0) modifier.withType(MinecraftReflection.getPacketClass()).read(0)
); );
} }
@ -351,7 +351,7 @@ public class WrappedAttribute {
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder packet(PacketContainer packet) { 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)"); throw new IllegalArgumentException("Packet must be UPDATE_ATTRIBUTES (44)");
} }
this.packet = packet; this.packet = packet;