GUI#closeForAllViewers

This commit is contained in:
NichtStudioCode 2021-05-11 19:03:07 +02:00
parent 640cdef177
commit d42c242947
2 changed files with 15 additions and 0 deletions

@ -12,6 +12,7 @@ import de.studiocode.invui.window.Window;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -267,6 +268,15 @@ public interface GUI extends GUIParent {
*/
Set<Player> findAllCurrentViewers();
/**
* Closes the open {@link Inventory} for all viewers of {@link Window}s
* where this {@link GUI} is displayed.
* Does not actually call the {@link Window#close(boolean)} method, which will
* be indirectly invoked by the {@link InventoryCloseEvent} if the {@link Window}
* is set to close on that event.
*/
void closeForAllViewers();
/**
* Plays an {@link Animation}.
*

@ -288,6 +288,11 @@ abstract class IndexedGUI implements GUI {
.collect(Collectors.toSet());
}
@Override
public void closeForAllViewers() {
findAllCurrentViewers().forEach(Player::closeInventory);
}
@Override
public void playAnimation(@NotNull Animation animation, @Nullable Predicate<SlotElement> filter) {
if (animation != null) cancelAnimation();