Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.aragone.framecraft;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- public class InventorySerializer {
- private Main main;
- private ArrayList<ItemStack> inventory = new ArrayList<>();
- public InventorySerializer(Main main) {
- this.main = main;
- }
- public void serializeInventory(Player p) {
- File playerInventory = new File(main.getDataFolder() + File.separator + "InventorySerializer" + File.separator + p.getDisplayName() + ".inventory.yml");
- if(!playerInventory.exists()) {
- try {
- playerInventory.createNewFile();
- FileConfiguration configfile = YamlConfiguration.loadConfiguration(playerInventory);
- for(ItemStack i : p.getInventory().getContents()) {
- inventory.add(i);
- }
- configfile.set("inv.inv", inventory);
- configfile.save(playerInventory);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public void deserializeInventory(Player p) {
- File playerInventory = new File(main.getDataFolder() + File.separator + "InventorySerializer" + File.separator + p.getDisplayName() + ".inventory.yml");
- if(playerInventory.exists()) {
- FileConfiguration configfile = YamlConfiguration.loadConfiguration(playerInventory);
- for(ItemStack i : p.getInventory().getContents()) {
- i = configfile.getItemStack("inv.inv", i);
- p.getInventory().addItem(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement