Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,31 @@ public MenuSpell(MagicConfig config, String spellName) {
for (String optionName : optionKeys) {
String path = "options." + optionName + ".";

List<Integer> slots = getConfigIntList(path + "slots", new ArrayList<>());
if (slots.isEmpty()) slots.add(getConfigInt(path + "slot", -1));
List<Integer> configuredSlots = getConfigIntList(path + "slots", new ArrayList<>());
if (configuredSlots.isEmpty()) configuredSlots.add(getConfigInt(path + "slot", -1));
List<Integer> configuredValidSlots = getConfigIntList(path + "valid-slots", new ArrayList<>());
Comment on lines +74 to +76

List<Integer> validSlots = new ArrayList<>();
for (int slot : slots) {
List<Integer> 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<Integer> 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;
}
Expand Down Expand Up @@ -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", "");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -438,6 +457,7 @@ private static class MenuOption {

private String menuOptionName;
private List<Integer> slots;
private List<Integer> validSlots;
private ItemStack item;
private List<ItemStack> items;
private String quantity;
Expand Down
Loading