Saving players items & separate items

Discussion in 'Plugin Development' started by M0R3TANK1NG, Apr 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    M0R3TANK1NG

    I have finally managed to create a chest with different ids to a normal one, and only donors can access it however I now need the chest to save and load separate player's items.

    How would I do this?
     
  2. Offline

    Austy

    I'm not sure if it is possible to display different inventories for one chest to different players. Maybe You should try this with Ender Chests.
     
  3. Offline

    MadArkael

    write a wrapper object for a player. and create a private inventory in that wrapper for said player.
     
  4. Offline

    stuntguy3000

  5. Offline

    MadArkael

    Code:
    public class wrapper{
     
        private Player p;
        private Inventory i;
     
        public wrapper(Player player){
     
            this.p = player;
        }
     
        public Inventory getInv(){
     
        return this.i;
        }
    }
     
  6. Offline

    M0R3TANK1NG

    where would I put this wrapper?
     
  7. Offline

    MadArkael

    As to how exactly you might code it to update whats in that inventory, I cant tell you offhand, but as far as when you do figure out how to get items to go into the private inventory ingame you can store these inventories in a hash with the player name as the key. This might not be the best way, but to save it to the disk, you could then iterate over every item stack in the inventory and add them to one string to place in a yml file somewhere. Then write a reverse method to get those items and amounts and store them into the hash when a player logs on. I've done similar things to that last part with item ids and amounts. <id>:<amount> was the format i used.

    PrivateInventory: '1:5 2:5 3:5'

    So you get that string from the yml file and split it into an array firstly using the space (" ") as your split regex. Then for every position in that array you split it with ":" into a temporary string array and add [0] to an item id array and [1] to an amount array.

    Code:
    String inv = config.getString("Players.<playerName>.PrivateInventory");
     
    int[] inventoryArray = inv.split(" ");
     
    int[] itemIDArray = new int[inventoryArray.length];
    int[] itemAmountArray = new int[inventoryArray.length];
     
    for (int i = 0; i < inventoryArray.length; i++){
     
        int[] tempArray = inventoryArray[i].split(":");
        itemIDArray[i] = tempArray[0];
        itemAmountArray[i] = tempArray[1];
    }
     
Thread Status:
Not open for further replies.

Share This Page