Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package us.austinstech.core.Utils;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Iterator;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.ShapelessRecipe;
- import org.json.simple.JSONArray;
- import org.json.simple.JSONObject;
- import org.json.simple.parser.JSONParser;
- import org.json.simple.parser.ParseException;
- import us.austinstech.core.Main;
- public class Recipes {
- static File file = Main.recipefile;
- public static void addRecipes() {
- try {
- JSONParser jsonParser = new JSONParser();
- Object parsed = jsonParser.parse(new FileReader(file.getPath()));
- JSONObject jsonObject = (JSONObject) parsed;
- String type = (String) jsonObject.get("type");
- String ritem = (String) jsonObject.get("result.item").toString().replaceAll("minecraft:", "").toUpperCase();
- int ramount = (int) jsonObject.get("result.count");
- ItemStack ris = new ItemStack(Material.getMaterial(ritem), ramount);
- @SuppressWarnings("unchecked")
- Iterator<String> keys = jsonObject.keySet().iterator();
- while (keys.hasNext()) {
- // String key = keys.next();
- if (type.equals("crafting_shapeless")) {
- @SuppressWarnings("deprecation")
- ShapelessRecipe recipe = new ShapelessRecipe(ris);
- JSONArray itemss = (JSONArray) jsonObject.get("ingredients");
- for (Object o : itemss) {
- JSONObject idata = (JSONObject) o;
- String itemm = (String) idata.get("item").toString().replaceAll("minecraft:", "").toUpperCase();
- recipe.addIngredient(Material.getMaterial(itemm));
- }
- Bukkit.addRecipe(recipe);
- } else if (type.equals("crafting_shaped")) {
- return;
- }
- }
- } catch (IOException | ParseException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement