Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package us.austinstech.core.Utils;
  2.  
  3. import java.io.File;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.Material;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.inventory.ShapelessRecipe;
  11. import org.json.simple.JSONArray;
  12. import org.json.simple.JSONObject;
  13. import org.json.simple.parser.JSONParser;
  14. import org.json.simple.parser.ParseException;
  15.  
  16. import us.austinstech.core.Main;
  17.  
  18. public class Recipes {
  19.  
  20. static File path = Main.recipefile;
  21.  
  22. public static void addRecipes() {
  23. for (File file : path.listFiles()) {
  24. try {
  25. JSONParser jsonParser = new JSONParser();
  26. Object parsed = jsonParser.parse(new FileReader(file.getPath()));
  27. JSONObject jsonObject = (JSONObject) parsed;
  28. String type = (String) jsonObject.get("type");
  29. String ritem = (String) jsonObject.get("result.item").toString().replaceAll("minecraft:", "")
  30. .toUpperCase();
  31. int ramount = (int) jsonObject.get("result.count");
  32. ItemStack ris = new ItemStack(Material.getMaterial(ritem), ramount);
  33. if (type.equals("crafting_shapeless")) {
  34. @SuppressWarnings("deprecation")
  35. ShapelessRecipe recipe = new ShapelessRecipe(ris);
  36. JSONArray itemss = (JSONArray) jsonObject.get("ingredients");
  37. for (Object o : itemss) {
  38. JSONObject idata = (JSONObject) o;
  39. String itemm = (String) idata.get("item").toString().replaceAll("minecraft:", "").toUpperCase();
  40. recipe.addIngredient(Material.getMaterial(itemm));
  41. }
  42. Bukkit.addRecipe(recipe);
  43. } else if (type.equals("crafting_shaped")) {
  44. return;
  45. }
  46. } catch (ParseException | IOException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement