EmilHernvall/tregmine — pull request #217 by lDiverse (2013-12-12 14:37:59+00:00)
Title: Multiple Inventory Handling, Saving and Loading from DB, InventoryCommand changes. (desc)

So this has been something I have been meaning to do for quite some time now. The ability to handle more than one inventory with some simple methods. With what I have done in these commits you are able to load and save using simple strings as inventory names (as they are stored in the inventory). We can technically handle infinite inventories per person and toggle between them if we were to have a command which allowed us to loadInventory("name", true);

I will now quickly briefly go through the new methods and such.

player.loadInventory(string, boolean);
The string is the name of the new inventory.
The boolean is whether you want to save the current inventory before changing.

player.saveInventory(string);
saves the inventory under the name provided.
Passing null will save it as the current name.

player.getCurrentInventory() returns the current inventory as a string - I use this rather than null as it looks neater.

I am setting the current inventory on loading the player to ensure it is set - If its not set a lot of spam occurs. It was an easy fix just to set it to some generic value like survival but if you had a different inventory open and this problem occurred - Your inventory would be reset and problems would happen.

I missed in the inventory schema the modifications to player.
Simply add "player_inventory" - Varchat(255) default NULL

Inventories save at different events such as respawning (after death), logging out, inventory close and onDisable
and is loaded when joining the server.

I have done some basic testing consisting of two people doing various things - reloading at random times and didn't experience any issues. Obviously we could do with more testing.

Feel free to ask questions.