From 5fb844f4b7fccf80d347542d99806e3b28fe2625 Mon Sep 17 00:00:00 2001 From: Leandro Date: Sun, 4 Jul 2021 22:11:23 -0300 Subject: [PATCH] Make it possible to change the item used to fill the categories menu. --- .../java/tsp/headdb/inventory/InventoryUtils.java | 13 +++++++++---- src/main/resources/config.yml | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index 032e5fa..0f0de21 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -56,7 +56,9 @@ public class InventoryUtils { if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".item")) { String cfg = HeadDB.getInstance().getCfg().getString("ui.category." + category + ".item"); Material mat = Material.matchMaterial(cfg); - if (mat != null && mat != Material.AIR) { + + // AIR is allowed as the fill material for the menu, but not as a category item. + if (mat != null && (category.equals("fill") || mat != Material.AIR)) { uiItem.put(category, new ItemStack(mat)); return uiItem.get(category); } @@ -226,14 +228,17 @@ public class InventoryUtils { )); } - fill(inventory, new ItemStack(Material.BLACK_STAINED_GLASS_PANE)); + fill(inventory); player.openInventory(inventory); } - public static void fill(Inventory inv, ItemStack item) { - int size = inv.getSize(); + public static void fill(Inventory inv) { + ItemStack item = uiGetItem("fill", new ItemStack(Material.BLACK_STAINED_GLASS_PANE)); + // Do not bother filling the inventory if item to fill it with is AIR. + if (item == null || item.getType() == Material.AIR) return; // Fill any non-empty inventory slots with the given item. + int size = inv.getSize(); for (int i = 0; i < size; i++) { ItemStack slotItem = inv.getItem(i); if (slotItem == null || slotItem.getType() == Material.AIR) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 13f9721..4f33ee5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -26,7 +26,7 @@ economy: # UI customization options. ui: category: - # Head categories. + # Head categories. You can use item: instead of head: here, but AIR is not supported. alphabet: location: 20 head: 1788 @@ -57,7 +57,7 @@ ui: plants: location: 33 head: 37278 - # Meta categories, used for UI elements. + # Meta categories, used for UI elements. AIR is not supported. You can use head: instead of item: here. favorites: location: 39 item: BOOK @@ -67,6 +67,9 @@ ui: local: location: 41 item: COMPASS + # Item used to fill unused slots in the categories menu. AIR is supported. You can use head: instead of item: here. + fill: + item: BLACK_STAINED_GLASS_PANE # Debug Mode debug: false