Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.leluckyyde.test.utils;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import java.io.File;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.List;
- public class Inventory {
- private static HashMap<String, ItemStack[]> contents = new HashMap<>();
- private static HashMap<String, ItemStack[]> armorcontents = new HashMap<>();
- public static void saveInventoryByLeave(Player player, File file) throws IOException {
- if (file.exists()) {
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- contents.put(player.getName(), player.getInventory().getContents());
- armorcontents.put(player.getName(), player.getInventory().getArmorContents());
- cfg.set("Items", contents.get(player.getName()));
- cfg.set("Armor", armorcontents.get(player.getName()));
- cfg.save(file);
- player.getInventory().clear();
- player.getInventory().setArmorContents(null);
- contents.remove(player.getName());
- armorcontents.remove(player.getName());
- }
- }
- public static void getInventoryByJoin(Player player, File file) {
- if (file.exists()) {
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<ItemStack> contents = (List<ItemStack>) cfg.getList("Items");
- List<ItemStack> armorcontents = (List<ItemStack>) cfg.getList("Armor");
- player.getInventory().setContents(contents.toArray(new ItemStack[contents.size()]));
- player.getInventory().setArmorContents(armorcontents.toArray(new ItemStack[armorcontents.size()]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement