Solved Saving enchants to a file

Discussion in 'Plugin Development' started by thechrisanator, Nov 14, 2018.

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

    thechrisanator

    How the heck do I even do this? where do I start?

    I've tried

    Section.set("enchants", itemstack.getEnchants());

    but that ends horribly
     
  2. Offline

    Zombie_Striker

    @thechrisanator
    Most likely you don't need to save the full enchantment instance to a file. What exactly are you trying to achieve?
     
  3. Offline

    thechrisanator

  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    thechrisanator

    @timtower

    so I dont need all this?

    Code:
            section.set("type", itemstack.getType().name());
           
            Map<Enchantment, Integer> enchants = itemstack.getEnchantments(); //create a map for the enchantments
            List<String> enchantList = new ArrayList<String>();
            for (Enchantment e : itemstack.getEnchantments().keySet()) { //loop through the itemstack's enchants
                int level = enchants.get(e); //get the level
                enchantList.add(e.getName()); //add the name to the list
                enchantList.add(Integer.toString(level)); //add the level to the list
            }
    
            section.set("enchants", enchantList);
            section.set("durability", itemstack.getDurability()); //write to the config file
            section.set("amount",  itemstack.getAmount());
     
  6. Offline

    timtower Administrator Administrator Moderator

    @thechrisanator You can save the entire ItemStack in one go.
    Then you can use section.getItemStack(path)
     
  7. Offline

    thechrisanator

    geez. wow... thats actually amazing

    it works beautifully!

    http://prntscr.com/lil8d0


    the only issue, is that when I remove an item from the inventory, and put it somewhere else, it stays there

    -- forget that

    is there any way to save which slots items are in an inventory? because currently, if I have a pick in slot 5, and a sword in slot 2, they all get shifted. so sword is in 1, and pick is in 2
     
  8. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page