Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 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. import java.util.Iterator;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Material;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.bukkit.inventory.ShapelessRecipe;
  12. import org.json.simple.JSONArray;
  13. import org.json.simple.JSONObject;
  14. import org.json.simple.parser.JSONParser;
  15. import org.json.simple.parser.ParseException;
  16.  
  17. import us.austinstech.core.Main;
  18.  
  19. public class Recipes {
  20.  
  21. static File file = Main.recipefile;
  22.  
  23. public static void addRecipes() {
  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:", "").toUpperCase();
  30. int ramount = (int) jsonObject.get("result.count");
  31. ItemStack ris = new ItemStack(Material.getMaterial(ritem), ramount);
  32.  
  33. @SuppressWarnings("unchecked")
  34. Iterator<String> keys = jsonObject.keySet().iterator();
  35.  
  36. while (keys.hasNext()) {
  37. // String key = keys.next();
  38.  
  39. if (type.equals("crafting_shapeless")) {
  40. @SuppressWarnings("deprecation")
  41. ShapelessRecipe recipe = new ShapelessRecipe(ris);
  42. JSONArray itemss = (JSONArray) jsonObject.get("ingredients");
  43. for (Object o : itemss) {
  44. JSONObject idata = (JSONObject) o;
  45. String itemm = (String) idata.get("item").toString().replaceAll("minecraft:", "").toUpperCase();
  46. recipe.addIngredient(Material.getMaterial(itemm));
  47. }
  48. Bukkit.addRecipe(recipe);
  49. } else if (type.equals("crafting_shaped")) {
  50. return;
  51. }
  52.  
  53. }
  54. } catch (IOException | ParseException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement