Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function to clear gui items #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Osanchez
Copy link

@Osanchez Osanchez commented Jan 7, 2023

No description provided.

@Osanchez Osanchez mentioned this pull request Jan 7, 2023
@zrdzn
Copy link
Contributor

zrdzn commented Jan 7, 2023

By looking at other methods that remove single items, I guess you are missing item removal from inventory.

/**
* Removes the given {@link ItemStack} from the GUI.
*
* @param item The item to remove.
*/
public void removeItem(@NotNull final ItemStack item) {
final Optional<Map.Entry<Integer, GuiItem>> entry = guiItems.entrySet()
.stream()
.filter(it -> it.getValue().getItemStack().equals(item))
.findFirst();
entry.ifPresent(it -> {
guiItems.remove(it.getKey());
inventory.remove(item);
});
}
/**
* Removes the {@link GuiItem} in the specific slot.
*
* @param slot The GUI slot.
*/
public void removeItem(final int slot) {
validateSlot(slot);
guiItems.remove(slot);
inventory.setItem(slot, null);
}

@Osanchez
Copy link
Author

Osanchez commented Jan 7, 2023

@zrdzn yea, you can itterate the map and remove items one by one. I just thought a clear would be cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants