Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void saveGenericInventory(Inventory inv, File f) throws IOException {
- FileConfiguration c = YamlConfiguration.loadConfiguration(f);
- for(int i = 0; i < inv.getSize(); i++){
- if(inv.getItem(i) == null){
- inv.setItem(i, new ItemStack(Material.AIR));
- }
- }
- c.set("inventory.content", inv.getContents());
- c.set("inventory.size", inv.getSize());
- c.save(f);
- }
- @SuppressWarnings("unchecked")
- public static Inventory restoreGenericInventory(File f) throws IOException {
- Inventory inv = Bukkit.createInventory(null, 9, "");
- if(f.exists()){
- FileConfiguration c = YamlConfiguration.loadConfiguration(f);
- inv = Bukkit.createInventory(null, c.getInt("inventory.size"), "");
- ItemStack[] content = ((List<ItemStack>) c.get("inventory.content")).toArray(new ItemStack[0]);
- inv.setContents(content);
- }
- return inv;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement