Storing certain slots in inventory

Discussion in 'Spigot Plugin Development' started by Stevie212, Apr 18, 2017.

  1. How do i store certain slots in inventory to a hashmap? I already know how to store the entire inventory to a hashmap but I would like to know how to store certain slots. For example I want to store slot 3 4 and 5 to the hashmap. If slot 4 and 5 is empty then only store slot 3 to the hashmap. How do I do that? Then afterwards return slot 3 to the any slot that is empty
  2. You could make a HashMap with <Integer, ItemStack> where you store the itemstack inside
  3. Like for some period of in game time? Or across reboots?

    If you're keeping up with them just while the server is running,

    Do something like this
    In your class variables.
    HashMap<ItemStack,Player> storage = new HashMap<ItemStack,Player>();

    Then in your code that takes the item just write in storage.put(is,plr);

    Then remove them from the inventory or what not.

    When you want to put them back, iterate over the hash map and if the player in question == the one linked in the map give back the item and remove it from the map.

    You'll also need to write some code that checks if the player has 3 items in the map already don't add anymore otherwise they could continue adding them indefinitely

    Another route would be to make your hashmap use <Player, ItemStack[]>

    Where the player object would be the key and the array be their items.

    The second method would be a lot cleaner imo

    Sent from my iPhone using Tapatalk
  4. Also its actually a created inventory. And its not a player inventory