public static void saveInventory(String name, PInv pinv) { BaseSerializer serializer = getSerializer(name); Date now = new Date(); String date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(now); System.out.println("10. " + date); int curSection = serializer.config.getInt("curSection", 0); serializer.config.set("curSection", (curSection + 1) % 3); ConfigurationSection pcs = serializer.config.createSection(curSection + ""); pcs.set("storedDate", date); List<String> stritems = new ArrayList<String>(); for (ItemStack is : pinv.armor) { if (is == null || is.getType() == Material.AIR) continue; stritems.add(InventoryUtil.getItemString(is)); } pcs.set("armor", stritems); stritems = new ArrayList<String>(); for (ItemStack is : pinv.contents) { if (is == null || is.getType() == Material.AIR) continue; stritems.add(InventoryUtil.getItemString(is)); } pcs.set("contents", stritems); serializer.save(); }
@SuppressWarnings("deprecation") public static boolean restoreInventory(ArenaPlayer player, Integer index) { PInv pinv = getInventory(player.getName(), index); if (pinv == null) return false; Player p = player.getPlayer(); for (ItemStack is : pinv.armor) { InventoryUtil.addItemToInventory(p, is); } for (ItemStack is : pinv.contents) { InventoryUtil.addItemToInventory(p, is); } try { p.updateInventory(); } catch (Exception e) { // / yes this has thrown errors on me before return false; /// do I really want to return false? do I care if this doesnt go through? } return true; }