private Set<PacketType> filterTypes(Set<PacketType> types, Sender sender) { Set<PacketType> result = Sets.newHashSet(); for (PacketType type : types) { if (type.getSender() == sender) { result.add(type); } } return result; }
/** * Retrieve the sender of this packet. * @return The sender. */ public Sender getSender() { return packet.getType().getSender(); }
@Override public int compareTo(PacketType other) { return ComparisonChain.start(). compare(protocol, other.getProtocol()). compare(sender, other.getSender()). compare(currentId, other.getCurrentId()). result(); }
/** * Set the packet types the listener is looking for. * <p> * This parameter is required. * @param packets - the packet types to look for. * @return This builder, for chaining. */ public AdapterParameteters types(@Nonnull PacketType... packets) { // Set the connection side as well if (connectionSide == null) { for (PacketType type : packets) { this.connectionSide = ConnectionSide.add(this.connectionSide, type.getSender().toSide()); } } this.packets = Preconditions.checkNotNull(packets, "packets cannot be NULL"); if (packets.length == 0) throw new IllegalArgumentException("Passed an empty packet type array."); return this; }
if (type.getProtocol() == protocol && type.getSender() == side) { result.add(type); it.remove();
String name = args[2]; for (PacketType packet : PacketType.values()) { if (packet.getProtocol() == protocol && packet.getSender() == pSender) { if (packet.name().equalsIgnoreCase(name)) { type = packet;
if (packet == null) throw new IllegalArgumentException("packet cannot be NULL."); if (packet.getType().getSender() == Sender.CLIENT) throw new IllegalArgumentException("Packet of sender CLIENT cannot be sent to a client.");
/** * Add a collection of packet types to the lookup. * @param types - the types to add. */ public PacketTypeLookup addPacketTypes(Iterable<? extends PacketType> types) { Preconditions.checkNotNull(types, "types cannot be NULL"); for (PacketType type : types) { int legacy = type.getLegacyId(); // Skip unknown legacy packets if (legacy != PacketType.UNKNOWN_PACKET) { if (type.isServer()) serverLookup.put(type.getLegacyId(), type); if (type.isClient()) clientLookup.put(type.getLegacyId(), type); legacyLookup.put(type.getLegacyId(), type); } // Skip unknown current packets if (type.getCurrentId() != PacketType.UNKNOWN_PACKET) { idLookup.getMap(type.getProtocol(), type.getSender()).put(type.getCurrentId(), type); classLookup.getMap(type.getProtocol(), type.getSender()).put(type.getClassNames()[0], type); } nameLookup.put(type.name(), type); } return this; }
if (packet == null) throw new IllegalArgumentException("packet cannot be NULL."); if (packet.getType().getSender() == Sender.SERVER) throw new IllegalArgumentException("Packet of sender SERVER cannot be sent to the server.");
/** * Determine if a given packet may be sent during login. * @param type - the packet type. * @return TRUE if it may, FALSE otherwise. */ public boolean isLoginPacket(PacketType type) { if (!MinecraftReflection.isUsingNetty()) return isLoginPacket(type.getLegacyId(), type.getSender().toSide()); return PacketType.Login.Client.getInstance().hasMember(type) || PacketType.Login.Server.getInstance().hasMember(type) || PacketType.Status.Client.getInstance().hasMember(type) || PacketType.Status.Server.getInstance().hasMember(type); } }