Skip to content

ItemStack remains visible after being removed from logic #61

@FaMa91

Description

@FaMa91

What is happening?

Initially, the GUI looks like this — you can see a green book in the third row, and the first row is empty:
Image

When I click on the green book, it moves to the first row and is removed both from the GUI and from the player’s inventory:
Image

Clicking the green book in the first row should give it back to the player and move it to the third row again, returning the GUI to its original state.

The logic behind this is slightly more complex, the third row is dynamically built from the player’s inventory, which is why the green book appears and disappears from that row.

What did you expect to happen?

When I click the green book in the first row, the underlying logic executes correctly, logs confirm that the Set used to populate the first row is properly cleared.

However, the GUI is then redrawn with the green book still visible in the first row. Clicking it again keeps giving new green books to the player’s inventory, even though the internal data structure is empty:
Image
Image

Version

1.6.5-SNAPSHOT

Config

setup:
  - "  12345  "
  - "         "
  - " iiiiiii "
  - " iiiiiii "
  - "         "

Server/system Version

Paper 1.21.1

Log

This is the output of the .size() on the set before and after having applied the logic.
[21:39:02 INFO]: [TEST-core] SIZE:1
[21:39:02 INFO]: [TEST-core] SIZE:0

What other programs/plugins are you running?

I tried with no other plugins

Additional context

This is how I'm creating the GUI's elements:

GuiElementGroup group = new GuiElementGroup('i');
HashMap<Integer, ? extends ItemStack> inv = viewer.getInventory().all(Material.KNOWLEDGE_BOOK);
for(Integer slot : inv.keySet()) {
    ItemStack item = inv.get(slot).clone();
    if(!item.getItemMeta().hasCustomModelData() || !ItemStorage.getRunes().containsKey(item.getItemMeta().getCustomModelData()))
        continue;
    WearableItem rune = ItemStorage.getRunes().get(item.getItemMeta().getCustomModelData());
    if(rune.cannotBeUsed(target))
        continue;
    StaticGuiElement element = new StaticGuiElement(
        'i',
        item,
        1,
        click -> {
            selectRuneLogic(item, false);
            return true;
        }
    );
    group.addElement(element);
}
addElement(group);

int i = 1;
Log.debug("SIZE2:{0}", RuneStorage.getEquippedRunes(target.getUniqueId()).size());
for(ItemStack item : RuneStorage.getEquippedRunes(target.getUniqueId())) {
    int finalI = i;
    DynamicGuiElement element = new DynamicGuiElement(
        Character.forDigit(i, 10),
        v -> new StaticGuiElement(
            Character.forDigit(finalI, 10),
            item,
            1,
            click -> {
                selectRuneLogic(item, true);
                return true;
            }
        )
    );
    addElement(element);
    i++;
}
show(viewer);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions