From ce99c3eec48614a8f987b2ea4eea7c40bf30c0e3 Mon Sep 17 00:00:00 2001 From: DragonsAscent Date: Sun, 23 Aug 2026 14:57:00 -0400 Subject: [PATCH] Added `valid-slots` which sorts items into selected slots as long as one of those slots is empty. --- .../nisovin/magicspells/spells/MenuSpell.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java b/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java index d2683161e..139f02d6f 100644 --- a/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java +++ b/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java @@ -71,19 +71,31 @@ public MenuSpell(MagicConfig config, String spellName) { for (String optionName : optionKeys) { String path = "options." + optionName + "."; - List slots = getConfigIntList(path + "slots", new ArrayList<>()); - if (slots.isEmpty()) slots.add(getConfigInt(path + "slot", -1)); + List configuredSlots = getConfigIntList(path + "slots", new ArrayList<>()); + if (configuredSlots.isEmpty()) configuredSlots.add(getConfigInt(path + "slot", -1)); + List configuredValidSlots = getConfigIntList(path + "valid-slots", new ArrayList<>()); - List validSlots = new ArrayList<>(); - for (int slot : slots) { + List slots = new ArrayList<>(); + for (int slot : configuredSlots) { if (slot < 0 || slot > 53) { MagicSpells.error("MenuSpell '" + internalName + "' a slot defined which is out of bounds for '" + optionName + "': " + slot); continue; } + slots.add(slot); + if (slot > maxSlot) maxSlot = slot; + } + + List validSlots = new ArrayList<>(); + for (int slot : configuredValidSlots) { + if (slot < 0 || slot > 53) { + MagicSpells.error("MenuSpell '" + internalName + "' has a valid-slots entry out of bounds for '" + optionName + "': " + slot); + continue; + } validSlots.add(slot); if (slot > maxSlot) maxSlot = slot; } - if (validSlots.isEmpty()) { + + if (slots.isEmpty() && validSlots.isEmpty()) { MagicSpells.error("MenuSpell '" + internalName + "' has no slots defined for: " + optionName); continue; } @@ -120,7 +132,8 @@ public MenuSpell(MagicConfig config, String spellName) { MenuOption option = new MenuOption(); option.menuOptionName = optionName; - option.slots = validSlots; + option.slots = slots; + option.validSlots = validSlots; option.item = item; option.items = items; option.quantity = getConfigString(path + "quantity", ""); @@ -297,6 +310,12 @@ private void applyOptionsToInventory(Player opener, MenuInventory menu) { for (int slot : option.slots) { if (inv.getItem(slot) == null) inv.setItem(slot, item); } + + for (int slot : option.validSlots) { + if (inv.getItem(slot) != null) continue; + inv.setItem(slot, item); + break; + } } // Fill inventory. if (filler == null) return; @@ -438,6 +457,7 @@ private static class MenuOption { private String menuOptionName; private List slots; + private List validSlots; private ItemStack item; private List items; private String quantity;