Saving HashMap

Discussion in 'Spigot Plugin Development' started by Stevie212, Jun 5, 2017.

  1. I am having problems saving the HashMap public static HashMap<UUID, ItemStack[] Storage = new HashMap<UUID, ItemStack[]>(); on reload.

    Code (Text):
        public void save() {
             List<ItemStack> hashMap1 = new ArrayList<ItemStack>();
            List<String> hashmapData = getConfig().getStringList("ItemStack");
            for (UUID uuid : Storage.keySet()) {
                for(ItemStack h: .get(uuid)){
                    hashMap1.add(h);
                }
                String data = uuid.toString() + ":" + hashMap1;
                hashmapData.add(data);

                getConfig().set("ItemStack", hashmapData);
                saveConfig();
            }
        }


    public void load(){
        List<String> s= getConfig().getStringList("ItemStack");
        for(String rawData : s) {
             String[] raw = rawData.split(":");
             Storage.put(UUID.fromString(raw[0]), ItemStack.deserialize(raw[1]);
            }

    }
    Can someone tell me whats the problem?
     
  2. Mas

    Mas

    Does that map really need to be static? I'm guessing it doesn't.
    As for your problem, you just need to store the UUIDs of players and the serialized list of ItemStacks in your config.
    Eg:
    Code (YAML):

    players
    :
      <some_player_id>
    :
       - some_serialized_item
        - some_other_serialized_item
     
    • Agree Agree x 2