private final int _packetId;
private final Supplier<ClientPacket> _packetSupplier;
private final Set<ConnectionState> _connectionStates;
ExClientPackets(int packetId, Supplier<ClientPacket> packetSupplier, ConnectionState... connectionStates)
{
// Packet id is an unsigned short.
if (packetId > 0xFFFF)
{
throw new IllegalArgumentException("Packet id must not be bigger than 0xFFFF");
}
_packetId = packetId;
_packetSupplier = packetSupplier != null ? packetSupplier : () -> null;
_connectionStates = new HashSet<>(Arrays.asList(connectionStates));
}
public int getPacketId()
{
return _packetId;
}
public ClientPacket newPacket()
{
final ClientPacket packet = _packetSupplier.get();
if (Config.DEBUG_EX_CLIENT_PACKETS)
{
if (packet != null)
{
final String name = packet.getClass().getSimpleName();
if (!Config.ALT_DEV_EXCLUDED_PACKETS.contains(name))
{
PacketLogger.info("[C EX] " + name);
}
}
else if (Config.DEBUG_UNKNOWN_PACKETS)
{
PacketLogger.info("[C EX] 0x" + Integer.toHexString(_packetId).toUpperCase());
}
}
return packet;
}