Advertisement
Guest User

addRecipes()

a guest
Jul 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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.  
  24. for (File file : path.listFiles()) {
  25. try {
  26. JSONParser jsonParser = new JSONParser();
  27. Object parsed = jsonParser.parse(new FileReader(file.getPath()));
  28. JSONObject jsonObject = (JSONObject) parsed;
  29. String type = (String) jsonObject.get("type");
  30. String ritem = (String) jsonObject.get("result.item").toString().replaceAll("minecraft:", "")
  31. .toUpperCase();
  32. int ramount = (int) jsonObject.get("result.count");
  33. ItemStack ris = new ItemStack(Material.getMaterial(ritem), ramount);
  34. if (type.equals("crafting_shapeless")) {
  35.  
  36. @SuppressWarnings("deprecation")
  37. ShapelessRecipe recipe = new ShapelessRecipe(ris);
  38. JSONArray itemss = (JSONArray) jsonObject.get("ingredients");
  39. for (Object o : itemss) {
  40. JSONObject idata = (JSONObject) o;
  41. String itemm = (String) idata.get("item").toString().replaceAll("minecraft:", "").toUpperCase();
  42. recipe.addIngredient(Material.getMaterial(itemm));
  43. }
  44. Bukkit.addRecipe(recipe);
  45. } else if (type.equals("crafting_shaped")) {
  46. return;
  47. }
  48. } catch (ParseException | IOException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement