How could I make it so that players can create a private chest using a command such as /storage to make it so a 9 item chest pops up? Thanks
kyle7273 I wont give you a full code example because that will take a while to do, but basically you have to listen to the command /storage, then I would find a way to serialise an inventory into a string, like so (note this currently doesnt store things like enchantments, content in written books, renamed items, e.t.c), then open the inventory by reading it from the string, then once they close the inventory (theres an event for that), put the new inventory into the config.
Code:java import java.util.Map;import java.util.Map.Entry; import org.bukkit.Bukkit;import org.bukkit.Material;import org.bukkit.enchantments.Enchantment;import org.bukkit.inventory.Inventory;import org.bukkit.inventory.ItemStack; public class InventoryStringDeSerializer { public static String InventoryToString (Inventory invInventory) { String serialization = invInventory.getSize() + ";"; for (int i = 0; i < invInventory.getSize(); i++) { ItemStack is = invInventory.getItem(i); if (is != null) { String serializedItemStack = new String(); String isType = String.valueOf(is.getType().getId()); serializedItemStack += "t@" + isType; if (is.getDurability() != 0) { String isDurability = String.valueOf(is.getDurability()); serializedItemStack += ":d@" + isDurability; } if (is.getAmount() != 1) { String isAmount = String.valueOf(is.getAmount()); serializedItemStack += ":a@" + isAmount; } Map<Enchantment,Integer> isEnch = is.getEnchantments(); if (isEnch.size() > 0) { for (Entry<Enchantment,Integer> ench : isEnch.entrySet()) { serializedItemStack += ":e@" + ench.getKey().getId() + "@" + ench.getValue(); } } serialization += i + "#" + serializedItemStack + ";"; } } return serialization; } public static Inventory StringToInventory (String invString) { String[] serializedBlocks = invString.split(";"); String invInfo = serializedBlocks[0]; Inventory deserializedInventory = Bukkit.getServer().createInventory(null, Integer.valueOf(invInfo)); for (int i = 1; i < serializedBlocks.length; i++) { String[] serializedBlock = serializedBlocks[i].split("#"); int stackPosition = Integer.valueOf(serializedBlock[0]); if (stackPosition >= deserializedInventory.getSize()) { continue; } ItemStack is = null; Boolean createdItemStack = false; String[] serializedItemStack = serializedBlock[1].split(":"); for (String itemInfo : serializedItemStack) { String[] itemAttribute = itemInfo.split("@"); if (itemAttribute[0].equals("t")) { is = new ItemStack(Material.getMaterial(Integer.valueOf(itemAttribute[1]))); createdItemStack = true; } else if (itemAttribute[0].equals("d") && createdItemStack) { is.setDurability(Short.valueOf(itemAttribute[1])); } else if (itemAttribute[0].equals("a") && createdItemStack) { is.setAmount(Integer.valueOf(itemAttribute[1])); } else if (itemAttribute[0].equals("e") && createdItemStack) { is.addEnchantment(Enchantment.getById(Integer.valueOf(itemAttribute[1])), Integer.valueOf(itemAttribute[2])); } } deserializedInventory.setItem(stackPosition, is); } return deserializedInventory; }}[/i] Code:java HashMap<String, Inventory> playerChests = new HashMap<String, Inventory>();public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ if(sender instanceof Player){ Player p = (Player) sender; if(commandLabel.equalsIgnoreCase("storage"){ if(args.length==0){ if(playerChests.containsKey(p.getName())){ p.openInventory(playerChests.get(p.getName())); }else{ playerChests.put(p.getName(), createChest(p)); p.openInventory(playerChests.get(p.getName())); } } } }} Code:java public Inventory createChest(Player p){ //Code for creating inventory with 9 spots here Inventory inv = Bukkit.getServer().createInventory(null, 9, p.getName()); return inv;} Code:java public void onDisable(){ List<String> list = new ArrayList<String>(); for(Player p : playerChests.keySet()){ list.add(p.getName()+":"+InventoryStringDeSerializer.InventoryToString(playerChests.get(p.getName()))); } getConfig().set("chests",list); saveConfig();}public void onEnable(){ saveDefaultConfig(); List<String> list = getConfig().getStringList("chests"); for(String str : list){ playerChests.put(str.split(":")[0], InventoryStringDeSerializer.StringToInventory(str.split(":")[1])); }} Well, it took me a while, but... Ta da.
kyle7273 No prob, if theres an error tell me, it could be stupid because I didnt write this in Eclipse