Exemplo n.º 1
0
  public static void registerModInJar(String modid, File jar) {
    try {
      ZipFile zipfile = new ZipFile(jar);
      Enumeration enumeration = zipfile.entries();
      while (enumeration.hasMoreElements()) {
        ZipEntry zipentry = (ZipEntry) enumeration.nextElement();
        String fileName = zipentry.getName();
        Path path1 = Paths.get(fileName);
        Path path2 = Paths.get("assets", modid, "books");

        if (path1.startsWith(path2)) {
          try {
            String json = IOUtils.toString(zipfile.getInputStream(zipentry));
            BookData data =
                BookRegistry.register(GsonClientHelper.getGson().fromJson(json, BookData.class));
            ELogger.log(
                Level.INFO,
                "Successfully loaded in the book with the unique identifier: "
                    + data.uniqueName
                    + " for the language: "
                    + data.language);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

      zipfile.close();
    } catch (Exception e) {
    }
  }
Exemplo n.º 2
0
  // Loads in all the books from the config directory
  public static void init() {
    File directory = new File(Enchiridion.root, "books");
    if (!directory.exists() && !directory.mkdirs()) {
      throw new IllegalStateException("Couldn't create dir: " + directory);
    }

    Collection<File> files = FileUtils.listFiles(directory, new String[] {"json"}, true);
    for (File file : files) {
      // Read all the json books from this directory
      try {
        BookRegistry.register(
            GsonClientHelper.getGson().fromJson(FileUtils.readFileToString(file), BookData.class));
      } catch (Exception e) {
        BookRegistry.register(new BookData(file.getName().replace(".json", "")));
      }
    }
  }
Exemplo n.º 3
0
  public static void registerModInDev(String modid, File source) {
    File path = FileHelper.getDevAssetsForModPath(source.getParentFile(), modid, "books");
    if (!path.exists()) {
      path.mkdir();
    }

    Collection<File> files = FileUtils.listFiles(path, new String[] {"json"}, true);
    for (File file : files) {
      try {
        String json = FileUtils.readFileToString(file);
        BookData data =
            BookRegistry.register(GsonClientHelper.getGson().fromJson(json, BookData.class));
        ELogger.log(
            Level.INFO,
            "Successfully loaded in the book with the unique identifier: "
                + data.uniqueName
                + " for the language: "
                + data.language);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }