/** * Construct a legacy packet type. * @param sender - client or server. * @param legacyId - the legacy packet ID. * @return Legacy packet type */ public static PacketType newLegacy(Sender sender, int legacyId) { return new PacketType(Protocol.LEGACY, sender, PacketType.UNKNOWN_PACKET, legacyId, MinecraftVersion.WORLD_UPDATE); }
/** * 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; }