zItsRaul

Untitled

Jul 7th, 2021
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public void loadChest(Inventory inv){
  2. final File file = new File(ChestRefill.INSTANCE.getPlugin().getDataFolder(), "data.yml");
  3. final YamlConfiguration yaml = YamlConfiguration.loadConfiguration(file);
  4.  
  5. int id = 0;
  6.  
  7. if(yaml.getConfigurationSection("chests") != null) {
  8. for (String key : yaml.getConfigurationSection("chests").getKeys(false)) {
  9. id = Integer.parseInt(key);
  10. }
  11. }
  12.  
  13. int counter = 1;
  14. ItemStack[] contents;
  15. for (int length = (contents = inv.getContents()).length, i = 0; i < length; ++i) {
  16. final ItemStack is = contents[i];
  17. if (is != null) {
  18. yaml.set("chests." + id + ".inv.slot" + counter, is);
  19. ++counter;
  20. }
  21. }
  22. --counter;
  23.  
  24. try {
  25. yaml.save(file);
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment