From 7ff586e3b372be0a95fed9351b9b13d937b56f49 Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 10 Jul 2020 19:01:47 +0200 Subject: [PATCH] Add method to refresh all open inventories of a menu --- .../java/me/filoghost/chestcommands/api/IconMenu.java | 2 ++ .../me/filoghost/chestcommands/menu/BaseIconMenu.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java index cb13596..06f18c7 100644 --- a/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java +++ b/API/src/main/java/me/filoghost/chestcommands/api/IconMenu.java @@ -42,4 +42,6 @@ public interface IconMenu { */ ItemInventory open(Player player); + void refreshOpenInventories(); + } \ No newline at end of file diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 7d0ce59..4b24ad7 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -21,6 +21,7 @@ import me.filoghost.chestcommands.inventory.DefaultItemInventory; import me.filoghost.chestcommands.util.Preconditions; import me.filoghost.chestcommands.util.collection.ArrayGrid; import me.filoghost.chestcommands.util.collection.Grid; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; public abstract class BaseIconMenu implements IconMenu { @@ -73,4 +74,13 @@ public abstract class BaseIconMenu implements IconMenu { return itemInventory; } + @Override + public void refreshOpenInventories() { + for (Player player : Bukkit.getOnlinePlayers()) { + DefaultItemInventory itemInventory = MenuManager.getOpenItemInventory(player); + if (itemInventory.getIconMenu() == this) { + itemInventory.refresh(); + } + } + } }