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.FileNotFoundException;
- import java.io.IOException;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- public class InventorySerializer {
- private Main main;
- 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);
- configfile.set("inv.inv", p.getInventory().getContents());
- configfile.set("inv.armor", p.getInventory().getArmorContents());
- 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()) {
- try {
- FileConfiguration configfile = YamlConfiguration.loadConfiguration(playerInventory);
- configfile.load(playerInventory);
- p.getInventory().addItem(configfile.getItemStack("inv.inv"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidConfigurationException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement