So I am making a chest: Code:java Inventory fbank = this.getServer().createInventory(null, 9, ChatColor.BLUE + f.getName() + "'s Faction Bank"); And opening it for the player after adding the chests contents: Code:java p.openInventory(fbank); (This is all on a Player Interact event, checks for the rightclick on a ender chest then cancels the normal event and lets this custom code run through). But what I want is it to work like a normal chest (more then 1 person can use it without items being duplicated or deleted). Any ideas/suggestions?
you are creating a new Inventory on every PlayerInteractEvent, so the previous contents are lost.. just create and save the inventory and show the same one to anyone who clicks that enderchest.
Sorry I didn't make myself very clear apparently. The point of this plugin is to make it so a faction shares an enderchest instead of player based enderchests. The contents will probably have to be saved in a flatfile.
TomShar I'm not sure if I understand your question correctly, but let's say two players have the chest open, one player interacts with it (clicks an item), another player will see this action aswell.. ? There's no good way of doing this, but save everyone who opens the inventory to a list, then on InventoryInteractEvent, save the contents, then loop through the player list, and re-open the inventory for every player.
I understand the question... what I'm addressing is that you said "This is all on a PlayerInteractEvent"... if you're creating a new Inventory for every PlayerInteractEvent, then players will never have the chance to share the same inventory.. you'll need to create those inventories (and store/load them to disk like you said, but that's out of scope for this question) ahead of time, and when a player clicks trhe enderchest, you have to check what faction they belong to, and display the appropriate Inventory to them
so what you're saying is, if i make all the inventories onEnable then on the interact I just open the correct inventory, that would solve the multiple use issue??
I don't know exactly what you mean by "The multiple use issue." I've never really investigated what happens when 2 users have the same inventory open, but I can't imagine it would cause any strange behaviour.
So i'm loading up the data and creating the inventories on start up and storing them in a hasmap: Code: HashMap<Faction, Inventory> banks = new HashMap<Faction, Inventory>(); but this is causing a massive memory leak (which I expected). I thought I could just make it String, String (Faction name, then a string of the item data which I could .split) but that means I am back to making the inventories per person which is a problem. I need a way to store the inventory without creating a memory leak?
you can create the inventories on-demand, just make sure you store them in that hashmap at least temporarily, and then open the same inventory for another user from the same faction. HOWEVER... There is no reason that storing an inventory in a hashmap would cause a memory leak... it may USE a lot of memory if you have a lot of factions, but its not leaking any memory unless you're doing something else wrong along the way.