Add method to refresh all open inventories of a menu

This commit is contained in:
filoghost 2020-07-10 19:01:47 +02:00
parent 73ae9b45c0
commit 7ff586e3b3
2 changed files with 12 additions and 0 deletions

View File

@ -42,4 +42,6 @@ public interface IconMenu {
*/
ItemInventory open(Player player);
void refreshOpenInventories();
}

View File

@ -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();
}
}
}
}