Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package de.leluckyyde.test.utils;
  2.  
  3. import org.bukkit.configuration.file.YamlConfiguration;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.inventory.ItemStack;
  6.  
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.HashMap;
  10. import java.util.List;
  11.  
  12. public class Inventory {
  13.  
  14. private static HashMap<String, ItemStack[]> contents = new HashMap<>();
  15. private static HashMap<String, ItemStack[]> armorcontents = new HashMap<>();
  16.  
  17. public static void saveInventoryByLeave(Player player, File file) throws IOException {
  18. if (file.exists()) {
  19. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  20. contents.put(player.getName(), player.getInventory().getContents());
  21. armorcontents.put(player.getName(), player.getInventory().getArmorContents());
  22. cfg.set("Items", contents.get(player.getName()));
  23. cfg.set("Armor", armorcontents.get(player.getName()));
  24. cfg.save(file);
  25. player.getInventory().clear();
  26. player.getInventory().setArmorContents(null);
  27. contents.remove(player.getName());
  28. armorcontents.remove(player.getName());
  29. }
  30. }
  31.  
  32. public static void getInventoryByJoin(Player player, File file) {
  33. if (file.exists()) {
  34. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  35. List<ItemStack> contents = (List<ItemStack>) cfg.getList("Items");
  36. List<ItemStack> armorcontents = (List<ItemStack>) cfg.getList("Armor");
  37. player.getInventory().setContents(contents.toArray(new ItemStack[contents.size()]));
  38. player.getInventory().setArmorContents(armorcontents.toArray(new ItemStack[armorcontents.size()]));
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement