Savings HashMaps with inventories

Discussion in 'Plugin Development' started by HCMatt, Nov 29, 2018.

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

    HCMatt

    I have made a Staff plugin where /staff enters you into Staff Mode. When you enter staff mode, your inventory is saved in a hashmap and then the staff inventory is given to you. Then when you leave staff mode your old inventory is given back to you. This all work exactly how I want it to... However.. If the server is reloaded whilst you are in staff mode, your old inventory is lost.

    Is there a way to be able to save the hashmap? Ive tried saving to a config but I ran into issues trying to convert the inventory back to items from the config?

    Thanks
     
  2. Offline

    The_Spaceman

    to safe
    file.getConfig().set(playerUUID, inventory.getContent());

    get:
    loop through uuid, get player from uuid and set the content to the players inventory
     
  3. Offline

    HCMatt

    I tried doing this with player name instead of UUID.. and it saves the inven contents... but then when i try to load it it throws an error. Something about not being able to cast ItemStack[] to a string.
     
  4. Offline

    The_Spaceman

    try:
    loop through the UUIDs,
    ItemStack[] content = file.getConfig().get(UUID);

    or better:

    Inventory inv = Bukkit.createInventory(null, size, name);
    List<?> content = getConfig().getList(path + ".content");
    inv.setContents(content.toArray(new ItemStack[]{}));

    this I use in one of my own plugins

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 29, 2018
Thread Status:
Not open for further replies.

Share This Page