Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static ArrayList<ItemStack> list = new ArrayList();
- public static void saveInventory(UUID uuid, Player p) {
- String id = uuid.toString();
- File file = new File("plugins//BuildFFA//Inventories//" + id + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- if (!file.exists()) {
- try {
- file.createNewFile();
- } catch (IOException error) {
- return;
- }
- } else {
- cfg.set("Inventory", null);
- try {
- cfg.save(file);
- } catch (IOException e) {
- return;
- }
- }
- ItemStack[] contents = p.getInventory().getContents();
- for (int i = 0; i < contents.length; i++) {
- ItemStack item = contents[i];
- if (item != null) {
- list.add(item);
- }
- }
- cfg.set("Inventory", list);
- try {
- cfg.save(file);
- } catch (IOException e) {
- if (p != null) {
- }
- }
- }
- public static ItemStack[] loadInventory(UUID uuid, Player p) {
- String id = uuid.toString();
- File file = new File("plugins//BuildFFA//Inventories//" + id + ".yml");
- if (file.exists()) {
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- ItemStack[] contents = p.getInventory().getContents();
- List<?> list = cfg.getList("Inventory");
- for (int i = 0; i < list.size(); i++) {
- contents[i] = ((ItemStack)list.get(i));
- }
- return contents;
- }
- return null;
- }
- public static void checkOrdner() {
- final File file = new File("plugins//BuildFFA//Inventories//");
- if (!file.exists()) {
- file.mkdir();
- }
- }
- public static boolean checkOrdner(final UUID uuid) {
- File file;
- try {
- file = new File("plugins//BuildFFA//Inventories//" + uuid.toString() + ".yml");
- }
- catch (NullPointerException | IllegalArgumentException ex2) {
- return false;
- }
- return file.exists();
- }
- public static void save(UUID uuid, ItemStack[] itemstack)
- {
- File file = new File("plugins//BuildFFA//Inventories//" + uuid.toString() + ".yml");
- new YamlConfiguration();YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set("Inventory", itemstack);
- try {
- cfg.save(file);
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void restore(Player p)
- {
- YamlConfiguration c = YamlConfiguration.loadConfiguration(new File("plugins//BuildFFA//Inventories//" + p.getUniqueId().toString() + ".yml"));
- ItemStack[] content = (ItemStack[])((List)c.get("Inventory")).toArray(new ItemStack[0]);
- p.getInventory().setContents(content);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement