From 76f2b7436c13d50d83cb30591e4667608e875da4 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Tue, 22 Jul 2025 11:02:27 +0200 Subject: Refactor paginated quest menu code a bit --- .../quests/bukkit/menu/PaginatedQMenu.java | 52 ++++++++++++---------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'bukkit/src/main') diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/PaginatedQMenu.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/PaginatedQMenu.java index 39adf59a..f886c9ae 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/PaginatedQMenu.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/PaginatedQMenu.java @@ -85,30 +85,34 @@ public abstract class PaginatedQMenu extends QMenu { SpacerMenuElement spacer = new SpacerMenuElement(); // populate custom elements first - if (customElementsPath != null) { - if (plugin.getConfig().isConfigurationSection(customElementsPath)) { - for (String s : plugin.getConfig().getConfigurationSection(customElementsPath).getKeys(false)) { - if (!StringUtils.isNumeric(s)) continue; - int slot = Integer.parseInt(s); - int repeat = plugin.getConfig().getInt(customElementsPath + "." + s + ".repeat"); - boolean staticElement = plugin.getConfig().getBoolean(customElementsPath + "." + s + ".static", false); - MenuElement menuElement; - if (plugin.getConfig().contains(customElementsPath + "." + s + ".display")) { - ItemStack is = plugin.getConfiguredItemStack(customElementsPath + "." + s + ".display", plugin.getConfig()); - List commands = plugin.getQuestsConfig().getStringList(customElementsPath + "." + s + ".commands"); - menuElement = new CustomMenuElement(plugin, owner.getPlayerUUID(), player.getName(), is, commands); - } else if (plugin.getConfig().getBoolean(customElementsPath + "." + s + ".spacer", false)) { - menuElement = spacer; - } else continue; // user = idiot - - for (int i = 0; i <= repeat; i++) { - if (staticElement) { - int boundedSlot = slot + i % pageSize; - staticMenuElements[boundedSlot] = menuElement; - customStaticElements++; - } else { - menuElements.put(slot + i, menuElement); - } + if (customElementsPath != null && plugin.getConfig().isConfigurationSection(customElementsPath)) { + for (String s : plugin.getConfig().getConfigurationSection(customElementsPath).getKeys(false)) { + if (!StringUtils.isNumeric(s)) { + continue; + } + + int slot = Integer.parseInt(s); + int repeat = plugin.getConfig().getInt(customElementsPath + "." + s + ".repeat"); + boolean staticElement = plugin.getConfig().getBoolean(customElementsPath + "." + s + ".static", false); + + MenuElement menuElement; + if (plugin.getConfig().contains(customElementsPath + "." + s + ".display")) { + ItemStack is = plugin.getConfiguredItemStack(customElementsPath + "." + s + ".display", plugin.getConfig()); + List commands = plugin.getQuestsConfig().getStringList(customElementsPath + "." + s + ".commands"); + menuElement = new CustomMenuElement(plugin, owner.getPlayerUUID(), player.getName(), is, commands); + } else if (plugin.getConfig().getBoolean(customElementsPath + "." + s + ".spacer", false)) { + menuElement = spacer; + } else { + continue; // user = idiot + } + + for (int i = 0; i <= repeat; i++) { + if (staticElement) { + int boundedSlot = slot + i % pageSize; + staticMenuElements[boundedSlot] = menuElement; + customStaticElements++; + } else { + menuElements.put(slot + i, menuElement); } } } -- cgit v1.2.3-70-g09d2