Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.styxl.slimefuncalculator;
- import org.yaml.snakeyaml.Yaml;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.Writer;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.nio.file.StandardCopyOption;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- public final class ItemDict {
- static String url = "https://gist.githack.com/NihilistBrew/16cb075dc74a042cd539497085294f5c/raw/fdfb0ae796c29e091ee06a29e868d37d1c6ca175/items.yaml";
- static String folderPath = "plugins/sfc";
- static String itemDictFile = "itemDict.yaml";
- static String itemDictPath = folderPath + "/" + itemDictFile;
- public static void downloadItems() throws IOException {
- List<String> missingRaw = new ArrayList<String>();
- try (InputStream inputStream = new URL(url).openStream()){
- new File(folderPath).mkdir();
- Files.copy(inputStream, Paths.get(itemDictPath), StandardCopyOption.REPLACE_EXISTING);
- Map<String, Map<String, String>> itemDict = getItemDict();
- for (Map<String, String> recipe : itemDict.values()) {
- for (String material : recipe.keySet()) {
- if (!itemDict.containsKey(material)) {
- missingRaw.add(material);
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- Writer writer = new FileWriter(itemDictPath, true);
- writer.write("\n");
- for (String item : missingRaw) {
- writer.write(item + ": null");
- writer.write("\n");
- }
- writer.close();
- }
- public static String getVersion() throws IOException {
- String version = Files.readAllLines(Paths.get(itemDictPath)).get(0);
- return version;
- }
- public static Map<String, Map<String, String>> getItemDict() throws IOException {
- Yaml yaml = new Yaml();
- Map<String, Map<String, String>> itemDict = null;
- try (InputStream inputStream = new FileInputStream(itemDictPath)) {
- itemDict = yaml.load(inputStream);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return itemDict;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement