/** * Determine if the given legacy packet exists. * @param packetId - the legacy packet ID. * @return TRUE if it does, FALSE otherwise. * @deprecated Legacy IDs haven't functioned properly for some time */ @Deprecated public static boolean hasLegacy(int packetId) { return getLookup().getFromLegacy(packetId) != null; }
/** * Retrieve every packet type with the given UPPER_CAMEL_CASE name. * <p> * Note that the collection is unmodiable. * @param name - the name. * @return Every packet type, or an empty collection. */ public static Collection<PacketType> fromName(String name) { return getLookup().getFromName(name); }
/** * Determine if the given packet exists. * @param protocol - the protocol. * @param sender - the sender. * @param packetId - the packet ID. * @return TRUE if it exists, FALSE otherwise. */ public static boolean hasCurrent(Protocol protocol, Sender sender, int packetId) { return getLookup().getFromCurrent(protocol, sender, packetId) != null; }
/** * Retrieve a packet type from a legacy (1.6.4 and below) packet ID. * @param packetId - the legacy packet ID. * @return The corresponding packet type. * @throws IllegalArgumentException If the legacy packet could not be found. * @deprecated Legacy IDs haven't functioned properly for some time */ @Deprecated public static PacketType findLegacy(int packetId) { PacketType type = getLookup().getFromLegacy(packetId); if (type != null) return type; throw new IllegalArgumentException("Cannot find legacy packet " + packetId); }
/** * Retrieve a packet type from a protocol, sender and packet ID. * <p> * It is almost always better to access the packet types statically, like so: * <ul> * <li>{@link PacketType.Play.Server#SPAWN_ENTITY} * </ul> * However there are some valid uses for packet IDs. Please note that IDs * change almost every Minecraft version. * * @param protocol - the current protocol. * @param sender - the sender. * @param packetId - the packet ID. * @return The corresponding packet type. * @throws IllegalArgumentException If the current packet could not be found. */ public static PacketType findCurrent(Protocol protocol, Sender sender, int packetId) { PacketType type = getLookup().getFromCurrent(protocol, sender, packetId); if (type != null) return type; throw new IllegalArgumentException("Cannot find packet " + packetId + "(Protocol: " + protocol + ", Sender: " + sender + ")"); }
public static PacketType findCurrent(Protocol protocol, Sender sender, String name) { name = format(protocol, sender, name); PacketType type = getLookup().getFromCurrent(protocol, sender, name); if (type != null) { return type; } else { throw new IllegalArgumentException("Cannot find packet " + name + "(Protocol: " + protocol + ", Sender: " + sender + ")"); } }
/** * Retrieve a packet type from a legacy (1.6.4 and below) packet ID. * @param packetId - the legacy packet ID. * @param preference - the preferred sender, or NULL for any arbitrary sender. * @return The corresponding packet type. * @throws IllegalArgumentException If the legacy packet could not be found. * @deprecated Legacy IDs haven't functioned properly for some time */ @Deprecated public static PacketType findLegacy(int packetId, Sender preference) { if (preference == null) return findLegacy(packetId); PacketType type = getLookup().getFromLegacy(packetId, preference); if (type != null) return type; throw new IllegalArgumentException("Cannot find legacy packet " + packetId); }
/** * Retrieve a packet type from a legacy ID. * <p> * If no associated packet type could be found, a new will be registered under LEGACY. * @param id - the legacy ID. * @param sender - the sender of the packet, or NULL if unknown. * @return The packet type. * @throws IllegalArgumentException If the sender is NULL and the packet doesn't exist. * @deprecated Legacy IDs haven't functioned properly for some time */ @Deprecated public static PacketType fromLegacy(int id, Sender sender) { PacketType type = getLookup().getFromLegacy(id, sender); if (type == null) { if (sender == null) throw new IllegalArgumentException("Cannot find legacy packet " + id); type = newLegacy(sender, id); // As below scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString()); } return type; }
/** * Retrieve a packet type from a protocol, sender and packet ID, for pre-1.8. * <p> * The packet will automatically be registered if its missing. * @param protocol - the current protocol. * @param sender - the sender. * @param packetId - the packet ID. Can be UNKNOWN_PACKET. * @param packetClass - the packet class * @return The corresponding packet type. */ public static PacketType fromID(Protocol protocol, Sender sender, int packetId, Class<?> packetClass) { PacketType type = getLookup().getFromCurrent(protocol, sender, packetId); if (type == null) { type = new PacketType(protocol, sender, packetId, -1, PROTOCOL_VERSION, packetClass.getName()); type.dynamic = true; // Many may be scheduled, but only the first will be executed scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString()); } return type; }
/** * Retrieve a packet type from a protocol, sender, ID, and class for 1.8+ * <p> * The packet will automatically be registered if its missing. * @param protocol - the current protocol. * @param sender - the sender. * @param packetId - the packet ID. Can be UNKNOWN_PACKET. * @param packetClass - the packet class. * @return The corresponding packet type. */ public static PacketType fromCurrent(Protocol protocol, Sender sender, int packetId, Class<?> packetClass) { ClassLookup lookup = getLookup().getClassLookup(); Map<String, PacketType> map = lookup.getMap(protocol, sender); // Check the map first String clazz = packetClass.getSimpleName(); PacketType type = find(map, clazz); if (type == null) { // Guess we don't support this packet :/ type = new PacketType(protocol, sender, packetId, -1, PROTOCOL_VERSION, clazz); type.dynamic = true; // Many may be scheduled, but only the first will be executed scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString()); } return type; }