Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public static void saveInventory(Inventory inv, File file, boolean override){
  2. if(inv == null || file == null) return;
  3. if(file.exists() && override) file.delete();
  4. FileConfiguration conf = YamlConfiguration.loadConfiguration(file);
  5.  
  6. ItemStack[] contents = inv.getContents();
  7.  
  8. for(int i = 0; i < contents.length; i++){
  9. ItemStack item = contents[i];
  10. if(item != null) if(item.getType() != Material.AIR) conf.set("Slot." + i, item);
  11. }
  12.  
  13. try {
  14. conf.save(file);
  15. }
  16. catch(IOException e){
  17. return;
  18. }
  19. }
  20.  
  21. public static List<ItemStack> getKit(String name){
  22. if(name == null) return null;
  23. ItemStack[] items = null;
  24.  
  25. FileConfiguration conf = YamlConfiguration.loadConfiguration(new File("plugins/BetterKits/" + getConfigName(name)));
  26.  
  27. if(conf.contains("Slot") && conf.isConfigurationSection("Slot")){
  28. int size = conf.getInt("Slot", 27);
  29.  
  30. items = new ItemStack[size];
  31.  
  32. for(int i = 0; i < size; i++){
  33. if(conf.contains("Slot." + i)) items[i] = conf.getItemStack("Slot." + i);
  34. else items[i] = new ItemStack(Material.AIR);
  35. }
  36. }
  37. List<ItemStack> kit = new ArrayList<ItemStack>();
  38. for(ItemStack i : items) {
  39. if(i != null) {
  40. kit.add(i);
  41. }
  42. }
  43. kit.removeAll(Collections.singleton(null));
  44. return kit;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement