private static PacketType find(Map<String, PacketType> map, String clazz) { PacketType ret = map.get(clazz); if (ret != null) { return ret; } // Check any aliases for (PacketType check : map.values()) { String[] aliases = check.getClassNames(); if (aliases.length > 1) { for (String alias : aliases) { if (alias.equals(clazz)) { // We have a match! return check; } } } } return null; }
/** * Retrieves the correct packet class from a given type. * <p> * Note that forceVanillla will be ignored on MC 1.7.2 and later. * @param type - the packet type. * @param forceVanilla - whether or not to look for vanilla classes, not injected classes. * @return The associated class. */ public static Class getPacketClassFromType(PacketType type, boolean forceVanilla) { initialize(); // Try the lookup first Class<?> clazz = NETTY.getPacketTypeLookup().get(type); if (clazz != null) { return clazz; } // Then try looking up the class names for (String name : type.getClassNames()) { try { clazz = MinecraftReflection.getMinecraftClass(name); break; } catch (Exception ex) { } } // TODO Cache the result? return clazz; }
break; for (String className : packet.getClassNames()) { if (className.equalsIgnoreCase(name)) { type = packet;
/** * 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; }