Solved Inventory loading and "cleaning"

Discussion in 'Plugin Development' started by KyllianGamer, Dec 2, 2018.

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


    Hey I'm working on a plugin where I use the function of saving a custom inventory. But when the inventory is opened again it has to be "cleaned up". Like this:





    So I'm pretty much looking for a system that's looping trough the config where the custom inventory is saved and then places it item for item in a row like its kinda "cleaned".
  2. Offline

    timtower Administrator Administrator Moderator

    @KyllianGamer Get all items and save them in a list where you don't care about slot numbers.
    Then clear the inventory.
    Then loop over the list and add the items to the inventory again.
  3. Offline


    Yeah okay that's true though but that's not why I completely mean. But it's my fault I will complain it a littble bit more. So if a speficic person that's in a group it has to be cleaned if they are not in that group then not. I already made there are 2 different gui's for the groups but I just have to make it like "cleaned" for that speficic group.
    If you got what I mean xd
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline


    So this is what I tried. This is the else of "if player is in specific group". So if they are not in that group I'm trying to clean it up right. This is not working. So the reason that the slot number is 9 is because in the custom inventory there is a row of glass above so it starts on 9. Maybe you see the problem? If you want I can send you how the inventory is looking of the person in the specific group and how it's looking for the players that are not in that group (and in that inv it has to be "cleaned")

    else {
                    Inventory npcinvviewer = Bukkit.createInventory(null, 27, "┬žaBuy Items");
                    int slot = 9;
                    for(int item = 9; item <= 27; item++) {
                        if (plugin.getConfig().contains("NPC." + event.getNPC().getId() + "Inventory.Slot" + item)) {
                            ItemStack chosenitem = plugin.getConfig().getItemStack("NPC." + event.getNPC().getId() + ".Inventory.Slot." + item);
                            npcinvviewer.setItem(slot, chosenitem);
  6. Offline

    timtower Administrator Administrator Moderator

    @KyllianGamer You are using slot numbers, if you want to order things then you don't use slot numbers.
  7. Offline


    I am only using slot numbers to track the item out of the saved inventory. Then I set it to "slot" what is 0 unless it already has been up counted. Or do I understand it wrong?

    Bruh nevermind I just had to loop over every item and do inventory.addItem(ItemStack) instead of inventory.setItem(int, ItemStack) xd but thanks for trying to help me!

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

Share This Page