List of usage examples for java.util Map.Entry containsKey
boolean containsKey(Object key);
From source file:org.granitemc.granite.utils.Mappings.java
public static void load() { try {//from w w w . ja v a 2 s . c o m File mappingsFile = new File(Granite.getServerConfig().getMappingsFile().getAbsolutePath()); String url = "https://raw.githubusercontent.com/GraniteTeam/GraniteMappings/master/1.8.1.json"; if (Granite.getServerConfig().getAutomaticMappingsUpdating()) { Granite.getLogger().info("Querying " + url + " for updates"); HttpRequest req = HttpRequest.get(url); if (!mappingsFile.exists() || !Objects.equals(req.eTag(), Granite.getServerConfig().getLatestMappingsEtag())) { Granite.getLogger().info("Could not find mappings.json (or etag didn't match)"); Granite.getLogger().info("Downloading from " + url); if (req.code() == 404) { throw new RuntimeException( "Cannot find mappings file on either the local system or on GitHub. Try placing a mappings.json file in the root server directory."); } else if (req.code() == 200) { req.receive(mappingsFile); ((GraniteServerConfig) Granite.getServerConfig()).file.put("latest-mappings-etag", req.eTag()); ((GraniteServerConfig) Granite.getServerConfig()).file.save(); } } } file = ConfigFactory.parseReader(new InputStreamReader(new FileInputStream(mappingsFile)), ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON)); } catch (java.io.IOException e) { e.printStackTrace(); } classes = HashBiMap.create(); ctClasses = HashBiMap.create(); methods = new HashMap<>(); ctMethods = new HashMap<>(); fields = new HashMap<>(); ctFields = new HashMap<>(); pool = new ClassPool(true); try { for (Map.Entry<String, ConfigValue> classObject : file.getObject("classes").entrySet()) { String className = (String) ((ConfigObject) classObject.getValue()).get("name").unwrapped(); ctClasses.put(classObject.getKey(), pool.get(className)); ctClasses.put(classObject.getKey() + "[]", pool.get(className + "[]")); } for (Map.Entry<String, CtClass> entry : ctClasses.entrySet()) { CtClass ctClass = entry.getValue(); if (!entry.getKey().endsWith("[]")) { ConfigObject classObject = file .getObject("classes." + entry.getKey().replaceAll("\\$", "\"\\$\"")); methods.put(ctClass, HashBiMap.<String, MethodHandle>create()); ctMethods.put(ctClass, HashBiMap.<String, CtMethod>create()); if (classObject.containsKey("methods")) { for (Map.Entry<String, ConfigValue> methodEntry : ((ConfigObject) classObject .get("methods")).entrySet()) { String methodSignature = methodEntry.getKey(); String methodName = (String) methodEntry.getValue().unwrapped(); SignatureParser.MethodSignature obfSig = SignatureParser.parseJvm(methodSignature); /*MethodHandle mh = null; try { mh = MethodHandles.lookup().findVirtual(clazz.getValue(), methodSignature.split("\\(")[0], MethodType.methodType(obfSig.getReturnType(), obfSig.getParamTypes())); } catch (NoSuchMethodException | IllegalAccessException e) { if (e.getMessage().startsWith("no such method")) { try { Method m = clazz.getValue().getDeclaredMethod(methodSignature.split("\\(")[0], obfSig.getParamTypes()); m.setAccessible(true); mh = MethodHandles.lookup().unreflect(m); } catch (NoSuchMethodException | IllegalAccessException e1) { e1.printStackTrace(); } } } if (mh == null) { mh = mh; }*/ CtMethod method = ctClass.getMethod(methodSignature.split("\\(")[0], "(" + methodSignature.split("\\(")[1]); ctMethods.get(method.getDeclaringClass()).put(methodName, method); } } fields.put(ctClass, HashBiMap.<String, Field>create()); ctFields.put(ctClass, HashBiMap.<String, CtField>create()); if (classObject.containsKey("fields")) { for (Map.Entry<String, ConfigValue> fieldEntry : ((ConfigObject) classObject.get("fields")) .entrySet()) { String obfuscatedFieldName = fieldEntry.getKey(); String fieldName = (String) fieldEntry.getValue().unwrapped(); ctFields.get(ctClass).put(fieldName, ctClass.getDeclaredField(obfuscatedFieldName)); } } } } } catch (NotFoundException e) { e.printStackTrace(); } }