saving invs

Discussion in 'Plugin Development' started by ImRayz66, May 30, 2015.

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

    ImRayz66

    I have seen a billion threads on this before.. All i need is for a kit plugin. It saves a players armor and items in exact order in a file, the file is called args[1] (from the /kit create {NAME} command). and then when a player does /kit {NAME} it swaps inventory, so it puts on the armor, and swaps items! Thanks guys!

    -Rayz
     
  2. Offline

    jebbo

    And what is your problem? What have you tried?
     
  3. Offline

    glory_fades

    @ImRayz66
    get the players inventory contents and the players armor contents and put it into a hashmap
    then load it when the player selects his kit
     
  4. There is config.getItemStack()
    You can set the itemstack like this for example:
    config.set("kits." + name + "." + slot", itemstack);

    Just loop through all items and do this
     
  5. Offline

    ImRayz66

    do you mean config.set("kits." + name + "." + slot, ItemStack); ? Because itemstack isn't a variable/item.
     
  6. @ImRayz66
    Do it like this for saving items:
    1. Loop through all items in the player's inventory:
    Code:
    for (int i = 0; i < inventory.getSize(); i++) {
    
    2. Set them to the config (i is the slot)
    Code:
    getConfig().set("kits." + kitName + "." + i, inventory.getItem(i));
    3. After the for-loop, save the config:
    Code:
    saveConfig();


    Do it like this for loading items:
    1. Loop through all childnodes under "kits.kitName":
    Code:
    for (String slot : getConfig().getConfigurationSection("kits." + kitName).getKeys(false)) {
    
    2. Get the item:
    Code:
    ItemStack item = getConfig().getItemStack("kits." + kitName + "." + slot);
    3. Do stuff with the item such as adding it to an Array or directly to an inventory
     
  7. Offline

    ImRayz66

    thanks bro, however one thing. I see it saves enchants on the config. But when i do the kit command. It displays an error along the lines of enchants, and null enchants. So how can i tell it to load enchants with armor when it puts in inv

    I got
    Code:
    p.getInventory().clear();
                    p.getInventory().setHelmet(getConfig().getItemStack("kits." + "member" + "." + "Helmet"));
                    p.getInventory().setChestplate(getConfig().getItemStack("kits." + "member" + "." + "Chest"));
                    p.getInventory().setLeggings(getConfig().getItemStack("kits." + "member" + "." + "Legs"));
                    p.getInventory().setBoots(getConfig().getItemStack("kits." + "member" + "." + "Boots"));
    @FisheyLP ^^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  8. Show the code where you're loading and saving it
     
Thread Status:
Not open for further replies.

Share This Page