Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. private static ArrayList<ItemStack> list = new ArrayList();
  2.  
  3. public static void saveInventory(UUID uuid, Player p) {
  4. String id = uuid.toString();
  5.  
  6. File file = new File("plugins//BuildFFA//Inventories//" + id + ".yml");
  7. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  8.  
  9. if (!file.exists()) {
  10. try {
  11. file.createNewFile();
  12. } catch (IOException error) {
  13.  
  14. return;
  15. }
  16. } else {
  17. cfg.set("Inventory", null);
  18. try {
  19. cfg.save(file);
  20. } catch (IOException e) {
  21.  
  22. return;
  23. }
  24. }
  25. ItemStack[] contents = p.getInventory().getContents();
  26. for (int i = 0; i < contents.length; i++) {
  27. ItemStack item = contents[i];
  28. if (item != null) {
  29. list.add(item);
  30. }
  31. }
  32. cfg.set("Inventory", list);
  33. try {
  34. cfg.save(file);
  35. } catch (IOException e) {
  36. if (p != null) {
  37.  
  38. }
  39. }
  40. }
  41.  
  42. public static ItemStack[] loadInventory(UUID uuid, Player p) {
  43. String id = uuid.toString();
  44. File file = new File("plugins//BuildFFA//Inventories//" + id + ".yml");
  45.  
  46. if (file.exists()) {
  47. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  48. ItemStack[] contents = p.getInventory().getContents();
  49. List<?> list = cfg.getList("Inventory");
  50. for (int i = 0; i < list.size(); i++) {
  51. contents[i] = ((ItemStack)list.get(i));
  52. }
  53. return contents;
  54. }
  55. return null;
  56. }
  57.  
  58. public static void checkOrdner() {
  59. final File file = new File("plugins//BuildFFA//Inventories//");
  60. if (!file.exists()) {
  61. file.mkdir();
  62. }
  63. }
  64.  
  65. public static boolean checkOrdner(final UUID uuid) {
  66. File file;
  67. try {
  68. file = new File("plugins//BuildFFA//Inventories//" + uuid.toString() + ".yml");
  69. }
  70. catch (NullPointerException | IllegalArgumentException ex2) {
  71. return false;
  72. }
  73. return file.exists();
  74. }
  75.  
  76.  
  77. public static void save(UUID uuid, ItemStack[] itemstack)
  78. {
  79. File file = new File("plugins//BuildFFA//Inventories//" + uuid.toString() + ".yml");
  80. new YamlConfiguration();YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  81.  
  82. cfg.set("Inventory", itemstack);
  83. try {
  84. cfg.save(file);
  85. }
  86. catch (IOException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90.  
  91. public static void restore(Player p)
  92. {
  93. YamlConfiguration c = YamlConfiguration.loadConfiguration(new File("plugins//BuildFFA//Inventories//" + p.getUniqueId().toString() + ".yml"));
  94. ItemStack[] content = (ItemStack[])((List)c.get("Inventory")).toArray(new ItemStack[0]);
  95. p.getInventory().setContents(content);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement