Bläddra i källkod

Base Layout and helper classes

jan 1 månad sedan
förälder
incheckning
48b639be79
19 ändrade filer med 1706 tillägg och 2 borttagningar
  1. 2 2
      src/main/java/me/lethunderhawk/storeMore/StoreMore.java
  2. 4 0
      src/main/java/me/lethunderhawk/storeMore/abstraction/item/AbstractItemStorage.java
  3. 4 0
      src/main/java/me/lethunderhawk/storeMore/abstraction/storage/AbstractStorageContainer.java
  4. 71 0
      src/main/java/me/lethunderhawk/storeMore/command/CommandNode.java
  5. 156 0
      src/main/java/me/lethunderhawk/storeMore/command/CustomCommand.java
  6. 46 0
      src/main/java/me/lethunderhawk/storeMore/gui/ConfirmationMenu.java
  7. 28 0
      src/main/java/me/lethunderhawk/storeMore/gui/GoBackItem.java
  8. 353 0
      src/main/java/me/lethunderhawk/storeMore/gui/InventoryGUI.java
  9. 103 0
      src/main/java/me/lethunderhawk/storeMore/gui/InventoryManager.java
  10. 127 0
      src/main/java/me/lethunderhawk/storeMore/gui/PaginatedInventoryGUI.java
  11. 63 0
      src/main/java/me/lethunderhawk/storeMore/gui/PlayerHeadListGUI.java
  12. 50 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemData.java
  13. 49 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreRenderer.java
  14. 55 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreTemplate.java
  15. 17 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreUpdater.java
  16. 79 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemOptions.java
  17. 299 0
      src/main/java/me/lethunderhawk/storeMore/itemManipulation/LoreDesigner.java
  18. 196 0
      src/main/java/me/lethunderhawk/storeMore/persistence/ConfigLoader.java
  19. 4 0
      src/main/java/me/lethunderhawk/storeMore/persistence/ConfigSaver.java

+ 2 - 2
src/main/java/me/lethunderhawk/storeMore/StoreMore.java

@@ -6,11 +6,11 @@ public final class StoreMore extends JavaPlugin {
 
     @Override
     public void onEnable() {
-        // Plugin startup logic
+
     }
 
     @Override
     public void onDisable() {
-        // Plugin shutdown logic
+
     }
 }

+ 4 - 0
src/main/java/me/lethunderhawk/storeMore/abstraction/item/AbstractItemStorage.java

@@ -0,0 +1,4 @@
+package me.lethunderhawk.storeMore.abstraction.item;
+
+public class AbstractItemStorage {
+}

+ 4 - 0
src/main/java/me/lethunderhawk/storeMore/abstraction/storage/AbstractStorageContainer.java

@@ -0,0 +1,4 @@
+package me.lethunderhawk.storeMore.abstraction.storage;
+
+public class AbstractStorageContainer {
+}

+ 71 - 0
src/main/java/me/lethunderhawk/storeMore/command/CommandNode.java

@@ -0,0 +1,71 @@
+package me.lethunderhawk.storeMore.command;
+
+import org.bukkit.command.CommandSender;
+
+import java.util.*;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+
+public class CommandNode {
+    private final String name;
+    private final String description;
+    private BiConsumer<CommandSender, String[]> executor;
+    private BiFunction<CommandSender, String[], List<String>> tabCompleter;
+    private Map<String, CommandNode> subCommands = new HashMap<>();
+    private CommandNode parent;
+
+    public CommandNode(String name, String description, BiConsumer<CommandSender, String[]> executor) {
+        this.name = name;
+        this.description = description;
+        this.executor = executor;
+    }
+
+    public CommandNode registerSubCommand(String name, String description, BiConsumer<CommandSender, String[]> executor) {
+        CommandNode subCommand = new CommandNode(name, description, executor);
+        subCommand.parent = this;
+        subCommands.put(name.toLowerCase(), subCommand);
+        return subCommand;
+    }
+
+    public void addSubCommand(CommandNode subCommand) {
+        subCommand.parent = this;
+        subCommands.put(subCommand.getName().toLowerCase(), subCommand);
+    }
+    public void addSubCommands(CommandNode... subCommandNodes) {
+        for(CommandNode subCommand : subCommandNodes) {
+            subCommand.parent = this;
+            subCommands.put(subCommand.getName().toLowerCase(), subCommand);
+        }
+    }
+
+    public CommandNode getSubCommand(String name) {
+        return subCommands.get(name.toLowerCase());
+    }
+
+    public boolean hasSubCommand(String name) {
+        return subCommands.containsKey(name.toLowerCase());
+    }
+
+    public Collection<CommandNode> getSubCommands() {
+        return subCommands.values();
+    }
+
+    public List<String> getSubCommandNames() {
+        return new ArrayList<>(subCommands.keySet());
+    }
+
+    public void setTabCompleter(BiFunction<CommandSender, String[], List<String>> tabCompleter) {
+        this.tabCompleter = tabCompleter;
+    }
+
+    // Getters
+    public String getName() { return name; }
+    public String getDescription() { return description; }
+    public BiConsumer<CommandSender, String[]> getExecutor() { return executor; }
+    public BiFunction<CommandSender, String[], List<String>> getTabCompleter() { return tabCompleter; }
+    public CommandNode getParent() { return parent; }
+
+    public void setExecutor(BiConsumer<CommandSender, String[]> executor) {
+        this.executor = executor;
+    }
+}

+ 156 - 0
src/main/java/me/lethunderhawk/storeMore/command/CustomCommand.java

@@ -0,0 +1,156 @@
+package me.lethunderhawk.storeMore.command;
+
+import io.papermc.paper.command.brigadier.BasicCommand;
+import io.papermc.paper.command.brigadier.CommandSourceStack;
+import me.lethunderhawk.fluxapi.util.interfaces.FluxAPIModule;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.command.CommandSender;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NonNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+public abstract class CustomCommand implements BasicCommand {
+
+    protected CommandNode rootCommand;
+    protected final FluxAPIModule module;
+    public CustomCommand(FluxAPIModule module) {
+        this.module = module;
+        this.rootCommand = getRootCommand();
+        createHelpCommand();
+        createCommands();
+    }
+    public void execute(CommandSourceStack commandSourceStack, String[] args) {
+        CommandSender sender = commandSourceStack.getSender();
+        if (args.length == 0) {
+            if(rootCommand.getExecutor() != null) {
+                rootCommand.getExecutor().accept(sender, args);
+            }else{
+                sendHelp(sender);
+            }
+            return;
+        }
+
+        List<String> argList = new ArrayList<>(Arrays.asList(args));
+        CommandNode currentNode = rootCommand;
+        CommandNode targetNode = null;
+
+        // Traverse the command tree
+        while (!argList.isEmpty()) {
+            String nextArg = argList.get(0);
+            CommandNode nextNode = currentNode.getSubCommand(nextArg);
+
+            if (nextNode == null) {
+                // No matching subcommand found, use current node if it has an executor
+                targetNode = currentNode.getExecutor() != null ? currentNode : null;
+                break;
+            }
+
+            currentNode = nextNode;
+            argList.remove(0);
+
+            // If this is the last argument or node has no further subcommands
+            if (argList.isEmpty() || nextNode.getSubCommands().isEmpty()) {
+                targetNode = nextNode;
+                break;
+            }
+        }
+
+        if (targetNode == null) {
+            module.sendText(sender, Component.text("Unknown command. Use /" + rootCommand.getName() +" help for available commands.", NamedTextColor.RED));
+            return;
+        }
+
+        if (targetNode.getExecutor() == null) {
+            module.sendText(sender,Component.text("This command requires additional arguments.", NamedTextColor.RED));
+            sendSubCommands(sender, targetNode);
+            return;
+        }
+
+        // Execute the command with remaining arguments
+        String[] remainingArgs = argList.toArray(new String[0]);
+        targetNode.getExecutor().accept(sender, remainingArgs);
+    }
+    @ApiStatus.OverrideOnly
+    public @NonNull Collection<String> suggest(final CommandSourceStack commandSourceStack, final String[] args) {
+        List<String> suggestions = new ArrayList<>();
+
+        if (args.length == 0) {
+            CommandNode currentNode = rootCommand;
+            if (currentNode.getTabCompleter() != null) {
+                suggestions.addAll(currentNode.getTabCompleter().apply(commandSourceStack.getSender(), args));
+            } else {
+                // Suggest subcommands
+                suggestions.addAll(currentNode.getSubCommandNames());
+            }
+            return suggestions;
+        }
+
+        // Start at root and traverse
+        CommandNode currentNode = rootCommand;
+        List<String> argList = new ArrayList<>(Arrays.asList(args));
+        String lastArg = args[args.length - 1].toLowerCase();
+
+        // Try to traverse as far as possible
+        for (int i = 0; i < argList.size() - 1; i++) {
+            String arg = argList.get(i);
+            CommandNode nextNode = currentNode.getSubCommand(arg);
+            if (nextNode == null) {
+                break;
+            }
+            currentNode = nextNode;
+        }
+
+        // Get suggestions from current node
+        if (currentNode.getTabCompleter() != null) {
+            suggestions.addAll(currentNode.getTabCompleter().apply(commandSourceStack.getSender(), args));
+        } else {
+            // Suggest subcommands
+            suggestions.addAll(currentNode.getSubCommandNames().stream()
+                    .filter(name -> name.toLowerCase().startsWith(lastArg))
+                    .collect(Collectors.toList()));
+        }
+
+        return suggestions;
+    }
+
+    @ApiStatus.OverrideOnly
+    public abstract CommandNode getRootCommand();
+
+    private void createHelpCommand() {
+        rootCommand.addSubCommand(new CommandNode("help", "Displays this help menu", this::sendHelp));
+    }
+    @ApiStatus.OverrideOnly
+    public abstract void createCommands();
+
+    protected void sendHelp(CommandSender sender, String[] strings) {
+        sendHelp(sender);
+    }
+    protected void sendHelp(CommandSender sender) {
+        sender.sendMessage("§6=== Available Commands ===");
+        for (CommandNode cmd : rootCommand.getSubCommands()) {
+            sender.sendMessage("/" + rootCommand.getName() + " " + cmd.getName() + " §7- " + cmd.getDescription());
+        }
+    }
+
+    private void sendSubCommands(CommandSender sender, CommandNode node) {
+        sender.sendMessage("§6Available subcommands:");
+        for (CommandNode subCmd : node.getSubCommands()) {
+            sender.sendMessage("§e" + subCmd.getName() + " §7- " + subCmd.getDescription());
+        }
+    }
+
+    public CommandNode registerSubCommand(String name, String description, BiConsumer<CommandSender, String[]> executor) {
+        return rootCommand.registerSubCommand(name, description, executor);
+    }
+
+    public void reload(){
+        createCommands();
+    }
+}

+ 46 - 0
src/main/java/me/lethunderhawk/storeMore/gui/ConfirmationMenu.java

@@ -0,0 +1,46 @@
+package me.lethunderhawk.storeMore.gui;
+
+import me.lethunderhawk.fluxapi.util.UnItalic;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.function.Consumer;
+
+public class ConfirmationMenu extends InventoryGUI {
+    private final Consumer<Player> callback;
+
+    public ConfirmationMenu(String title, Consumer<Player> callback ) {
+        super(title, 27);
+        this.callback = callback;
+    }
+
+    @Override
+    public void buildContent() {
+        fillGlassPaneBackground();
+
+        ItemStack IAmSure = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
+        ItemMeta meta = IAmSure.getItemMeta();
+        meta.displayName(Component.text("Yes, i am sure", NamedTextColor.GREEN));
+        IAmSure.setItemMeta(UnItalic.removeItalicFromMeta(meta));
+        setItemWithClickAction(11, IAmSure, (p, type)->{
+            callback.accept(p);
+            openPrevious(p);
+        });
+        ItemStack NoPleaseNot = new ItemStack(Material.BARRIER);
+        ItemMeta noMeta = NoPleaseNot.getItemMeta();
+        noMeta.displayName(Component.text("No, i changed my mind", NamedTextColor.RED));
+        NoPleaseNot.setItemMeta(UnItalic.removeItalicFromMeta(noMeta));
+        setItemWithClickAction(15, NoPleaseNot, (p, type)->{
+            openPrevious(p);
+        });
+    }
+
+    @Override
+    public void update() {
+
+    }
+}

+ 28 - 0
src/main/java/me/lethunderhawk/storeMore/gui/GoBackItem.java

@@ -0,0 +1,28 @@
+package me.lethunderhawk.storeMore.gui;
+
+import me.lethunderhawk.fluxapi.util.UnItalic;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.List;
+
+public class GoBackItem extends ItemStack {
+    public GoBackItem() {
+        super(Material.ARROW);
+
+        setItemMeta(buildItemMeta());
+    }
+
+    private ItemMeta buildItemMeta() {
+        ItemMeta meta = getItemMeta();
+        meta.displayName(Component.text("Go back", NamedTextColor.RED));
+        meta.lore(List.of(
+                Component.text("Go back to the previous menu!", NamedTextColor.GRAY)
+        ));
+        UnItalic.removeItalicFromMeta(meta);
+        return meta;
+    }
+}

+ 353 - 0
src/main/java/me/lethunderhawk/storeMore/gui/InventoryGUI.java

@@ -0,0 +1,353 @@
+package me.lethunderhawk.storeMore.gui;
+
+import me.lethunderhawk.fluxapi.util.UnItalic;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.ClickType;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.*;
+import java.util.function.BiConsumer;
+
+/**
+ * Generic, reusable Inventory GUI.
+ */
+public abstract class InventoryGUI implements InventoryHolder {
+
+    private final String title;
+    private final int size;
+    private final Inventory inventory;
+    /**
+     * Slots with the action to trigger upon clicking
+     */
+    private final Map<Integer, BiConsumer<Player, ClickType>> slotActions = new HashMap<>();
+
+    private final Stack<InventoryGUI> previousGuis = new Stack<>();
+    /** Slots that the player may edit (drag‑and‑drop, shift‑click, etc.) */
+    private final Set<Integer> editableSlots = new HashSet<>();
+
+    /** Register a slot as editable – call this from the subclass before the GUI opens */
+    protected final void setEditable(int... slots) {
+        for (int s : slots) editableSlots.add(s);
+    }
+
+    /** Helper to check whether a slot is editable */
+    protected final boolean isEditable(int slot) {
+        return editableSlots.contains(slot);
+    }
+
+    public InventoryGUI(String title, int size, Player p) {
+        this.title = title;
+        this.size = size;
+        this.inventory = Bukkit.createInventory(this, size, title);
+        performAdditionalComputationOnPlayer(p);
+    }
+
+    public InventoryGUI(String title, int size) {
+        this.title = title;
+        this.size = size;
+        this.inventory = Bukkit.createInventory(this, size, title);
+    }
+
+    /**
+     * Can be overwritten by subclasses
+     * @param p The Player for whom the GUI is for. May not exist if the super didn't specify a player
+     */
+    public void performAdditionalComputationOnPlayer(Player p) {
+    }
+
+    public void handleClick(Player player, InventoryClickEvent event) {
+        int rawSlot = event.getRawSlot();
+            // If the click is inside the top inventory (our GUI)
+            if (rawSlot < inventory.getSize()) {
+                // Editable slots: let Minecraft handle the action (no cancel)
+                if (isEditable(rawSlot)) {
+                    // Do NOT cancel – the player can move items freely.
+                    // However we still want to run any custom click‑action that
+                    // might be attached (e.g. a “clear slot” button).  The
+                    // default implementation in your base class usually stores
+                    // a map of slot → Consumer<Player,ClickType>.  If you have
+                    // that, call it here *after* the normal behaviour.
+                    runClickActionIfPresent(player, rawSlot, event.getClick());
+                    return;
+                }
+
+                // Non‑editable slots – keep the GUI read‑only
+                event.setCancelled(true);
+                runClickActionIfPresent(player, rawSlot, event.getClick());
+            } else {
+                onPlayerInventoryClick(player, event);
+            }
+    }
+    @ApiStatus.OverrideOnly
+    public void onPlayerInventoryClick(Player player, InventoryClickEvent event){}
+
+    private void runClickActionIfPresent(Player player, int rawSlot, ClickType click) {
+        BiConsumer<Player, ClickType> action = slotActions.get(rawSlot);
+        if (action != null) {
+            action.accept(player, click);
+        }
+    }
+    /**
+     * Sets an item in a specific slot.
+     */
+    public void setItem(int slot, ItemStack item) {
+        inventory.setItem(slot, item);
+    }
+
+    /**
+     * Helper method
+     * @param slot The slot Number
+     * @return The row this slot is in
+     */
+    protected int getRow(int slot) {
+        return slot / 9;
+    }
+
+    /**
+     * Helper method
+     * @param slot The slot Number
+     * @return The column this slot is in
+     */
+    protected int getColumn(int slot) {
+        return slot % 9;
+    }
+
+    /**
+     * Helper method
+     * @param row The row Number
+     * @param column The column Number
+     * @return The slot this corresponds to
+     */
+    protected int getSlot(int row, int column) {
+        return row * 9 + column;
+    }
+
+    /**
+     * Helper method
+     * @param startSlot The start slot of the Rectangle (top-left)
+     * @param endSlot The end slot of the Rectangle (bottom-right)
+     */
+    protected List<Integer> computeRectangleSlots(int startSlot, int endSlot) {
+
+        List<Integer> slots = new ArrayList<>();
+
+        int startRow = startSlot / 9;
+        int startCol = startSlot % 9;
+
+        int endRow = endSlot / 9;
+        int endCol = endSlot % 9;
+
+        for (int row = startRow; row <= endRow; row++) {
+            for (int col = startCol; col <= endCol; col++) {
+
+                slots.add(row * 9 + col);
+
+            }
+        }
+
+        return slots;
+    }
+
+    /**
+     * Copies the same Click Action onto multiple slots
+     * @param startSlot The start slot of the Rectangle (top-left)
+     * @param endSlot The end slot of the Rectangle (bottom-right)
+     * @param item The items to fill this Rectangle with
+     * @param action The action to perform upon clicking any of these slots
+     */
+    public void fillRectangleWithClickAction(int startSlot, int endSlot, ItemStack item, BiConsumer<Player, ClickType> action) {
+        int startRow = getRow(startSlot);
+        int startCol = getColumn(startSlot);
+
+        int endRow = getRow(endSlot);
+        int endCol = getColumn(endSlot);
+
+        for (int row = startRow; row <= endRow; row++) {
+            for (int col = startCol; col <= endCol; col++) {
+                int slot = getSlot(row, col);
+                setItemWithClickAction(slot, item, action);
+            }
+        }
+    }
+    /**
+     * Copies the same {@link ItemStack} onto multiple slots
+     * @param startSlot The start slot of the Rectangle (top-left)
+     * @param endSlot The end slot of the Rectangle (bottom-right)
+     * @param item The items to fill this Rectangle with
+     */
+    public void fillRectangle(int startSlot, int endSlot, ItemStack item) {
+        int startRow = getRow(startSlot);
+        int startCol = getColumn(startSlot);
+
+        int endRow = getRow(endSlot);
+        int endCol = getColumn(endSlot);
+
+        for (int row = startRow; row <= endRow; row++) {
+            for (int col = startCol; col <= endCol; col++) {
+                int slot = getSlot(row, col);
+                setItem(slot, item);
+            }
+        }
+    }
+    /**
+     * Sets a full Rectangle to be editable
+     * @param startSlot The start slot of the Rectangle (top-left)
+     * @param endSlot The end slot of the Rectangle (bottom-right)
+     */
+    public void setRectangleEditable(int startSlot, int endSlot) {
+        int startRow = getRow(startSlot);
+        int startCol = getColumn(startSlot);
+
+        int endRow = getRow(endSlot);
+        int endCol = getColumn(endSlot);
+
+        for (int row = startRow; row <= endRow; row++) {
+            for (int col = startCol; col <= endCol; col++) {
+                int slot = getSlot(row, col);
+                setEditable(slot);
+            }
+        }
+    }
+
+    /**
+     * Sets an item and assigns a click action for that slot.
+     */
+    public void setItemWithClickAction(int slot, ItemStack item, BiConsumer<Player, ClickType> action) {
+        inventory.setItem(slot, item);
+        slotActions.put(slot, action);
+    }
+
+    /**
+     * Fills all empty slots with a background item.
+     */
+    public void fillGlassPaneBackground(){
+        ItemStack background = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
+        ItemMeta meta = background.getItemMeta();
+        meta.displayName(Component.text(" "));
+        meta.setHideTooltip(true);
+        background.setItemMeta(meta);
+        for (int i = 0; i < size; i++) {
+            if (inventory.getItem(i) == null) {
+                inventory.setItem(i, background);
+            }
+        }
+    }
+    public void fillBackground(Material material, String displayName) {
+        ItemStack background = new ItemStack(material);
+        ItemMeta meta = background.getItemMeta();
+        meta.displayName(Component.text(displayName));
+        background.setItemMeta(meta);
+        for (int i = 0; i < size; i++) {
+            if (inventory.getItem(i) == null) {
+                inventory.setItem(i, background);
+            }
+        }
+    }
+
+    /**
+     * Quick way to open this GUI with the correct Listeners, so it actually works
+     * @param player The player to open the Inventory for
+     */
+    public void openWithListener(Player player){
+        InventoryManager.openFor(player, this);
+    }
+    /**
+     * Opens this GUI for a player.
+     * <br>NOTE: This doesn't make the Inventory responsive by itself, since it only displays the container to the player.
+     * <br>for that, use {@code openWithListener(player);}
+     */
+    public void open(Player player) {
+        buildContent();
+        player.openInventory(inventory);
+    }
+
+    /**
+     * Opens another GUI and remembers this one for navigation.
+     */
+    public void openNext(Player player, InventoryGUI nextGui) {
+        nextGui.previousGuis.push(this);
+        InventoryManager.openFor(player, nextGui);
+    }
+    public boolean hasPreviousGUI() {
+        return !previousGuis.isEmpty();
+    }
+
+    /**
+     * Opens the previous GUI if available.
+     */
+    public void openPrevious(Player player) {
+        if (hasPreviousGUI()) {
+            InventoryGUI previousGui = previousGuis.pop();
+            previousGui.update();
+            InventoryManager.openFor(player, previousGui);
+        }
+    }
+    public void setNextPageButton(int slot, InventoryGUI gui){
+        ItemStack item = new ItemStack(Material.ARROW);
+        ItemMeta meta = item.getItemMeta();
+        meta.displayName(Component.text("Next Page", NamedTextColor.GREEN));
+        item.setItemMeta(UnItalic.removeItalicFromMeta(meta));
+        setItemWithClickAction(slot, item, (p, type) -> {
+            openNext(p, gui);
+        });
+    }
+
+    public void setBackButton(int slot){
+        ItemStack item = new ItemStack(Material.ARROW);
+        ItemMeta meta = item.getItemMeta();
+        meta.displayName(Component.text("Go Back", NamedTextColor.GREEN));
+        item.setItemMeta(UnItalic.removeItalicFromMeta(meta));
+        setItemWithClickAction(slot, item, (p, type) -> {
+            openPrevious(p);
+        });
+    }
+    public void setCloseButton(int slot){
+        ItemStack item = new ItemStack(Material.BARRIER);
+        ItemMeta meta = item.getItemMeta();
+        meta.displayName(Component.text("Close", NamedTextColor.RED));
+        item.setItemMeta(UnItalic.removeItalicFromMeta(meta));
+        setItemWithClickAction(slot, item, (p, type) -> {
+            InventoryManager.close(p.getUniqueId());
+        });
+    }
+
+    public void openPrevious(Player player, ClickType type) {
+        openPrevious(player);
+    }
+
+    @Override
+    public @NotNull Inventory getInventory() {
+        return inventory;
+    }
+
+    /**
+     * Builds the Content of the Inventory, called everytime a player is shown the GUI
+     */
+    @ApiStatus.OverrideOnly
+    public abstract void buildContent();
+
+    /**
+     * Usually only called when traversing through multiple GUIs
+     */
+    @ApiStatus.OverrideOnly
+    public abstract void update();
+
+    /**
+     * This interface can be implemented as well to handle cases where the player closes the inventory
+     * <br>You can e.g. stop this behavior etc.
+     */
+    @FunctionalInterface
+    public interface AutoCloseHandler {
+        void onClosedByPlayer(Player player);
+    }
+}

+ 103 - 0
src/main/java/me/lethunderhawk/storeMore/gui/InventoryManager.java

@@ -0,0 +1,103 @@
+package me.lethunderhawk.storeMore.gui;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Central registry & listener for open InventoryGUI instances.
+ * Register once: InventoryManager.register(plugin);
+ */
+public final class InventoryManager implements Listener {
+    private static final Map<UUID, InventoryGUI> openGuis = new ConcurrentHashMap<>();
+    private static volatile boolean registered = false;
+    private static Plugin providerPlugin;
+
+    public static void register(Plugin plugin) {
+        if (registered) return;
+        providerPlugin = plugin;
+        Bukkit.getPluginManager().registerEvents(new InventoryManager(), plugin);
+        registered = true;
+    }
+
+    public static void openFor(Player player, InventoryGUI gui) {
+
+        // ensure main thread
+        if (!Bukkit.isPrimaryThread()) {
+            Bukkit.getScheduler().runTask(providerPlugin, () -> openFor(player, gui));
+            return;
+        }
+
+        // Close current inventory if open
+        InventoryGUI current = openGuis.get(player.getUniqueId());
+        if (current != null) {
+            openGuis.remove(player.getUniqueId());
+        }
+
+        // Open new GUI
+        openGuis.put(player.getUniqueId(), gui);
+        gui.open(player);
+    }
+
+    public static InventoryGUI getOpen(UUID playerId) {
+        return openGuis.get(playerId);
+    }
+
+    public static void close(@NotNull UUID playerId) {
+        InventoryGUI gui = openGuis.remove(playerId);
+        if (gui != null) {
+            Player p = Bukkit.getPlayer(playerId);
+            if(p!= null) p.closeInventory();
+        }
+    }
+
+    @EventHandler
+    public void onInventoryClick(InventoryClickEvent event) {
+        if (!(event.getWhoClicked() instanceof Player player)) return;
+        if (!(event.getView().getTopInventory().getHolder() instanceof InventoryGUI gui)) return;
+
+        // ignore clicks outside top inventory
+        if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) return;
+
+        InventoryGUI open = openGuis.get(player.getUniqueId());
+        if (open == null || open != gui) return; // ensure it's the tracked instance
+
+        gui.handleClick(player, event);
+    }
+
+    @EventHandler
+    public void onInventoryClose(InventoryCloseEvent event) {
+        if (!(event.getPlayer() instanceof Player player)) return;
+        InventoryGUI gui = openGuis.get(player.getUniqueId());
+        if (gui == null) return;
+
+        // If the closed inventory is the tracked GUI
+        if (event.getView().getTopInventory().getHolder() == gui) {
+            // Check if this is an intentional navigation (opening a new GUI)
+            // If the player is opening a new GUI, it will be handled by openFor
+            // We should only treat it as accidental if reason is not OPEN_NEW
+            // and the player doesn't have another GUI queued up
+            if (event.getReason() != InventoryCloseEvent.Reason.OPEN_NEW) {
+                // Small delay to check if another GUI is being opened
+                Bukkit.getScheduler().runTask(providerPlugin, () -> {
+                    // If still the same GUI (no new GUI was opened), treat as accidental close
+                    if (openGuis.get(player.getUniqueId()) == gui) {
+                        if (gui instanceof InventoryGUI.AutoCloseHandler handler) {
+                            handler.onClosedByPlayer(player);
+                        }
+                        openGuis.remove(player.getUniqueId());
+                    }
+                });
+            }
+        }
+    }
+}

+ 127 - 0
src/main/java/me/lethunderhawk/storeMore/gui/PaginatedInventoryGUI.java

@@ -0,0 +1,127 @@
+package me.lethunderhawk.storeMore.gui;
+
+import me.lethunderhawk.fluxapi.util.itemdesign.ItemOptions;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.ClickType;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+
+public abstract class PaginatedInventoryGUI<T> extends InventoryGUI {
+
+    protected int currentPage = 0;
+    protected int maxPage;
+
+    protected List<T> elements = new ArrayList<>();
+    protected List<Integer> contentSlots = new ArrayList<>();
+
+    public PaginatedInventoryGUI(String title, int size, Player player) {
+        super(title, size, player);
+    }
+
+    /**
+     * Setup for Pagination Logic
+     * @param elements The Collection of things to display as paginated if necessary
+     * @param slots The slots the Collection should cover (use helper methods like {@code computeRectangleSlots()})
+     */
+    protected void setupPagination(Collection<T> elements, List<Integer> slots) {
+
+        this.elements = new ArrayList<>(elements);
+        this.contentSlots = slots;
+
+        int itemsPerPage = slots.size();
+        this.maxPage = (this.elements.size() - 1) / itemsPerPage;
+    }
+
+    /**
+     * Sorts the elements
+     * @param comparator The {@link Comparator} used to compare elements
+     */
+    protected void sortElements(Comparator<T> comparator) {
+        elements.sort(comparator);
+    }
+
+    /**
+     * renders the paginated Page (defined previously)
+     */
+    protected void renderPage() {
+
+        int itemsPerPage = contentSlots.size();
+        int startIndex = currentPage * itemsPerPage;
+
+        for (int i = 0; i < itemsPerPage; i++) {
+
+            int elementIndex = startIndex + i;
+
+            if (elementIndex >= elements.size()) return;
+
+            T element = elements.get(elementIndex);
+
+            int slot = contentSlots.get(i);
+
+            setItemWithClickAction(slot, createItem(element), (p, click) -> onClick(element, p, click));
+        }
+    }
+
+    protected void nextPage() {
+        if (currentPage < maxPage) {
+            currentPage++;
+            update();
+        }
+    }
+
+    protected void previousPage() {
+        if (currentPage > 0) {
+            currentPage--;
+            update();
+        }
+    }
+
+    /**
+     * Adds Navigation Buttons on the bottom left and bottom right of the Page whenever necessary
+     */
+    protected void addNavigationButtons() {
+
+        int size = getInventory().getSize();
+
+        if (currentPage > 0) {
+            setItemWithClickAction(size - 9,
+                    new ItemOptions(Material.ARROW)
+                            .setName(Component.text("Previous Page", NamedTextColor.YELLOW))
+                            .buildItemStack(),
+                    (p, t) -> previousPage());
+        }
+
+        if (currentPage < maxPage) {
+            setItemWithClickAction(size - 1,
+                    new ItemOptions(Material.ARROW)
+                            .setName(Component.text("Next Page", NamedTextColor.YELLOW))
+                            .buildItemStack(),
+                    (p, t) -> nextPage());
+        }
+    }
+
+    /**
+     * Used for pagination, creates the Item you want using the elements Specified
+     * @param element The individual element passed through at rendering time
+     * @return The {@link ItemStack} you want to build
+     */
+    protected abstract ItemStack createItem(T element);
+
+    /**
+     * What should happen on Click of an element
+     * @param element The element being clicked
+     * @param player The player clicking
+     * @param type The {@link ClickType} of the click
+     */
+    @ApiStatus.OverrideOnly
+    protected void onClick(T element, Player player, ClickType type) {
+    }
+}

+ 63 - 0
src/main/java/me/lethunderhawk/storeMore/gui/PlayerHeadListGUI.java

@@ -0,0 +1,63 @@
+package me.lethunderhawk.storeMore.gui;
+
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+
+import java.util.List;
+import java.util.function.BiConsumer;
+
+/**
+ * GUI displaying a list of players as clickable heads.
+ */
+public class PlayerHeadListGUI extends InventoryGUI {
+
+    private final List<Player> players;
+    private final BiConsumer<Player, Player> onHeadClick;
+
+    public PlayerHeadListGUI(
+            String title,
+            int size,
+            List<Player> players,
+            BiConsumer<Player, Player> onHeadClick
+    ) {
+        super(title, size);
+        this.players = players;
+        this.onHeadClick = onHeadClick;
+    }
+
+
+    private ItemStack createPlayerHead(Player player) {
+        ItemStack head = new ItemStack(Material.PLAYER_HEAD);
+        SkullMeta meta = (SkullMeta) head.getItemMeta();
+        meta.setOwningPlayer(player);
+        meta.setDisplayName(player.getName());
+        head.setItemMeta(meta);
+        return head;
+    }
+
+    @Override
+    public void buildContent() {
+        int slot = 0;
+        for (Player target : players) {
+            if (slot >= this.getInventory().getSize()) break;
+
+            ItemStack head = createPlayerHead(target);
+            int finalSlot = slot;
+
+            setItemWithClickAction(finalSlot, head, (clickingPlayer, type) ->
+                    onHeadClick.accept(clickingPlayer, target)
+            );
+
+            slot++;
+        }
+
+        fillBackground(Material.GRAY_STAINED_GLASS_PANE, " ");
+    }
+
+    @Override
+    public void update() {
+
+    }
+}

+ 50 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemData.java

@@ -0,0 +1,50 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import org.bukkit.NamespacedKey;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataType;
+import org.bukkit.plugin.Plugin;
+
+public class ItemData {
+
+    private static Plugin plugin;
+
+    public static void init(Plugin pl) {
+        plugin = pl;
+    }
+
+    private static NamespacedKey key(String name) {
+        return new NamespacedKey(plugin, name);
+    }
+
+    public static void setInt(ItemStack item, String id, int value) {
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null) return;
+
+        meta.getPersistentDataContainer()
+                .set(key(id), PersistentDataType.INTEGER, value);
+
+        item.setItemMeta(meta);
+
+        ItemLoreRenderer.render(item); // auto refresh
+    }
+
+    public static int getInt(ItemStack item, String id, int def) {
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null) return def;
+
+        Integer value = meta.getPersistentDataContainer()
+                .get(key(id), PersistentDataType.INTEGER);
+
+        return value == null ? def : value;
+    }
+
+    public static boolean has(ItemStack item, String id) {
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null) return false;
+
+        return meta.getPersistentDataContainer()
+                .has(key(id), PersistentDataType.INTEGER);
+    }
+}

+ 49 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreRenderer.java

@@ -0,0 +1,49 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import net.kyori.adventure.text.Component;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ItemLoreRenderer {
+
+    private static final Pattern PLACEHOLDER =
+            Pattern.compile("\\{([a-zA-Z0-9_]+)}");
+
+    public static void render(ItemStack item) {
+
+        List<String> template = ItemLoreTemplate.getTemplate(item);
+        if (template == null) return;
+
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null) return;
+
+        List<Component> newLore = new ArrayList<>();
+
+        for (String line : template) {
+
+            Matcher matcher = PLACEHOLDER.matcher(line);
+            StringBuffer buffer = new StringBuffer();
+
+            while (matcher.find()) {
+
+                String key = matcher.group(1);
+
+                int value = ItemData.getInt(item, key, 0);
+
+                matcher.appendReplacement(buffer, String.valueOf(value));
+            }
+
+            matcher.appendTail(buffer);
+
+            newLore.add(Component.text(buffer.toString()));
+        }
+
+        meta.lore(newLore);
+        item.setItemMeta(meta);
+    }
+}

+ 55 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreTemplate.java

@@ -0,0 +1,55 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import me.lethunderhawk.fluxapi.FluxService;
+import me.lethunderhawk.fluxapi.main.FluxAPI;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import org.bukkit.NamespacedKey;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ItemLoreTemplate {
+
+    private static final String KEY = "lore_template";
+
+    public static void storeTemplate(ItemStack item) {
+
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null || !meta.hasLore()) return;
+
+        List<String> template = new ArrayList<>();
+
+        PlainTextComponentSerializer plain = PlainTextComponentSerializer.plainText();
+        for (Component c : meta.lore()) {
+            template.add(plain.serialize(c));
+        }
+
+        meta.getPersistentDataContainer().set(
+                new NamespacedKey(FluxService.get(FluxAPI.class), KEY),
+                PersistentDataType.STRING,
+                String.join("\n", template)
+        );
+
+        item.setItemMeta(meta);
+    }
+
+    public static List<String> getTemplate(ItemStack item) {
+
+        ItemMeta meta = item.getItemMeta();
+        if (meta == null) return null;
+
+        String raw = meta.getPersistentDataContainer().get(
+                new NamespacedKey(FluxService.get(FluxAPI.class), KEY),
+                PersistentDataType.STRING
+        );
+
+        if (raw == null) return null;
+
+        return Arrays.asList(raw.split("\n"));
+    }
+}

+ 17 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemLoreUpdater.java

@@ -0,0 +1,17 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+public class ItemLoreUpdater {
+    private ItemLoreUpdater() {}
+    public static void updateIntegersInLore(ItemStack item, String unformatted, String... fields) {
+        for(String field : fields) {
+            unformatted = unformatted.replace("{" + field + "}", String.valueOf(ItemData.getInt(item, field, 0)));
+        }
+
+        ItemMeta meta = item.getItemMeta();
+        meta.lore(LoreDesigner.createLore(unformatted));
+        item.setItemMeta(meta);
+    }
+}

+ 79 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/ItemOptions.java

@@ -0,0 +1,79 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import me.lethunderhawk.fluxapi.util.UnItalic;
+import net.kyori.adventure.text.Component;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.List;
+
+public class ItemOptions {
+
+
+    private Component name;
+    private List<Component> lore;
+    private int amount = 1;
+    private Material material;
+
+    /**
+     * Simple way to customize Items
+     * @param material The Base material
+     */
+    public ItemOptions(Material material){
+        this.material = material;
+    }
+
+    /**
+     * Creates the {@link ItemStack} from Scratch
+     * @return The {@link ItemStack} with the Properties specified
+     */
+    public ItemStack buildItemStack(){
+        ItemStack item = new ItemStack(material);
+        item.setAmount(amount);
+        ItemMeta meta = item.getItemMeta();
+        meta.lore(lore);
+        meta.displayName(name);
+        item.setItemMeta(UnItalic.removeItalicFromMeta(meta));
+
+        return item;
+    }
+
+    // ====== Getters and Setters ======
+
+    public Component getName() {
+        return name;
+    }
+
+    public ItemOptions setName(Component name) {
+        this.name = name;
+        return this;
+    }
+
+    public List<Component> getLore() {
+        return lore;
+    }
+
+    public ItemOptions setLore(List<Component> lore) {
+        this.lore = lore;
+        return this;
+    }
+
+    public int getAmount() {
+        return amount;
+    }
+
+    public ItemOptions setAmount(int amount) {
+        this.amount = amount;
+        return this;
+    }
+
+    public Material getMaterial() {
+        return material;
+    }
+
+    public ItemOptions setMaterial(Material material) {
+        this.material = material;
+        return this;
+    }
+}

+ 299 - 0
src/main/java/me/lethunderhawk/storeMore/itemManipulation/LoreDesigner.java

@@ -0,0 +1,299 @@
+package me.lethunderhawk.storeMore.itemManipulation;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.ComponentBuilder;
+import net.kyori.adventure.text.TextComponent;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.TextDecoration;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+
+public final class LoreDesigner {
+    public static String defaultWidthReference = "The default width reference";
+    private LoreDesigner() {}
+
+    /**
+     * Create a single {@link Component} with additional Regex like {@literal <red> or <blue>}
+     * @param text The Text to display
+     * @return a new {@link Component}
+     */
+    public static Component createSingle(String text) {
+        if (text == null || text.isBlank()) {
+            return Component.empty();
+        }
+
+        StyleState style = new StyleState();
+        ComponentBuilder<TextComponent, TextComponent.Builder> builder = Component.text();
+
+        int i = 0;
+        while (i < text.length()) {
+            if (text.charAt(i) == '<') {
+                int end = text.indexOf('>', i);
+                if (end != -1) {
+                    String token = text.substring(i + 1, end).toLowerCase();
+                    applyToken(style, token);
+                    i = end + 1;
+                    continue;
+                }
+            }
+
+            char c = text.charAt(i);
+            builder.append(Component.text(String.valueOf(c), style.toStyle()));
+            i++;
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Create a List of {@link Component}s with additional Regex like {@literal <red> or <blue>}
+     * @param text The Text to display
+     * @param widthReference The reference used for line-wrapping
+     * @param color The base Color to use (<-- Not quite sure lol)
+     * @return A new List of {@link Component}
+     */
+    public static List<Component> createLore(String text, String widthReference, NamedTextColor color) {
+        List<Component> lore = createLore(text, widthReference);
+        for(Component component : lore) {
+            component.color(color);
+        }
+        return lore;
+    }
+    /**
+     * Create a List of {@link Component}s with additional Regex like {@literal <red> or <blue>} and the {@code defaultWidthReference}
+     * @param text The Text to display
+     * @param color The base Color to use (<-- Not quite sure lol)
+     * @return A new List of {@link Component}
+     */
+    public static List<Component> createLore(String text, NamedTextColor color) {
+        return createLore(text, defaultWidthReference, color);
+    }
+
+    /**
+     * Create a List of {@link Component}s with additional Regex like {@literal <red> or <blue>} and the {@code defaultWidthReference}
+     * @param text The Text to display
+     * @return A new List of {@link Component}
+     */
+    public static List<Component> createLore(String text){
+        return createLore(text, defaultWidthReference);
+    }
+    /**
+     * Create a List of {@link Component}s with additional Regex like {@literal <red> or <blue>}
+     * @param text The Text to display
+     * @param widthReference The Reference for how wide it should be
+     * @return A new List of {@link Component}
+     */
+    public static List<Component> createLore(String text, String widthReference) {
+        int maxLength = widthReference.length();
+        if (text == null || text.isBlank() || maxLength <= 0) {
+            return List.of();
+        }
+
+        List<Component> lore = new ArrayList<>();
+
+        StyleState style = new StyleState();
+        ComponentBuilder<TextComponent, TextComponent.Builder> lineBuilder = Component.text();
+        int currentLength = 0;
+
+        String[] lines = text.split("<br>", -1);
+
+        for (int i = 0; i < lines.length; i++) {
+
+            String[] wrapParts = lines[i].split(" ");
+
+            for (int p = 0; p < wrapParts.length; p++) {
+
+                ParsedWord parsed = parseWord(wrapParts[p], style);
+                appendWord(
+                        lore,
+                        parsed,
+                        maxLength,
+                        style,
+                        Holder.of(lineBuilder, currentLength)
+                );
+
+                currentLength = Holder.length;
+                lineBuilder = Holder.builder;
+
+                // add space between parts
+                if (p < wrapParts.length - 1) {
+                    lineBuilder.append(Component.space());
+                    currentLength++;
+                }
+            }
+
+            currentLength = Holder.length;
+            lineBuilder = Holder.builder;
+
+            // force line break if <br> occurred
+            if (i < lines.length - 1) {
+                lore.add(lineBuilder.build());
+                lineBuilder = Component.text().style(style.toStyle());
+                currentLength = 0;
+            }
+        }
+
+        if (currentLength > 0) {
+            lore.add(lineBuilder.build());
+        }
+
+        return lore;
+    }
+
+    // -------------------- Append Logic --------------------
+
+    private static void appendWord(
+            List<Component> lore,
+            ParsedWord parsed,
+            int maxLength,
+            StyleState style,
+            Holder holder
+    ) {
+        int wordLength = parsed.visibleLength();
+
+        if (holder.length > 0 && holder.length + 1 + wordLength > maxLength) {
+            lore.add(holder.builder.build());
+            holder.builder = Component.text().style(style.toStyle());
+            holder.length = 0;
+        }
+
+        holder.builder.append(parsed.component());
+        holder.length += wordLength;
+    }
+
+    // -------------------- Parsing --------------------
+
+    private static ParsedWord parseWord(String raw, StyleState style) {
+        ComponentBuilder<TextComponent, TextComponent.Builder> builder = Component.text();
+        int visibleLength = 0;
+
+        int i = 0;
+        while (i < raw.length()) {
+            if (raw.charAt(i) == '<') {
+                int end = raw.indexOf('>', i);
+                if (end != -1) {
+                    String token = raw.substring(i + 1, end).toLowerCase();
+                    applyToken(style, token);
+                    i = end + 1;
+                    continue;
+                }
+            }
+
+            char c = raw.charAt(i);
+            builder.append(Component.text(String.valueOf(c), style.toStyle()));
+            visibleLength++;
+            i++;
+        }
+
+        return new ParsedWord(builder.build(), visibleLength);
+    }
+
+    private static void applyToken(StyleState style, String token) {
+
+        if (token.startsWith("/")) {
+            String closing = token.substring(1);
+
+            switch (closing) {
+                case "bold" -> style.undecorate(TextDecoration.BOLD);
+                case "italic" -> style.undecorate(TextDecoration.ITALIC);
+                case "underlined" -> style.undecorate(TextDecoration.UNDERLINED);
+                case "strikethrough" -> style.undecorate(TextDecoration.STRIKETHROUGH);
+                case "obfuscated" -> style.undecorate(TextDecoration.OBFUSCATED);
+                default -> {
+                    // closing color tag like </red>
+                    if (NAMED_COLORS.containsKey(closing)) {
+                        style.color(style.defaultColor);
+                    }
+                }
+            }
+            return;
+        }
+
+        switch (token) {
+            case "reset" -> style.reset();
+
+            case "bold" -> style.decorate(TextDecoration.BOLD);
+            case "italic" -> style.decorate(TextDecoration.ITALIC);
+            case "underlined" -> style.decorate(TextDecoration.UNDERLINED);
+            case "strikethrough" -> style.decorate(TextDecoration.STRIKETHROUGH);
+            case "obfuscated" -> style.decorate(TextDecoration.OBFUSCATED);
+
+            default -> {
+                NamedTextColor color = NAMED_COLORS.get(token);
+                if (color != null) {
+                    style.color(color);
+                }
+            }
+        }
+    }
+
+    // -------------------- Helpers --------------------
+
+    private static final Map<String, NamedTextColor> NAMED_COLORS = Map.ofEntries(
+            Map.entry("black", NamedTextColor.BLACK),
+            Map.entry("dark_blue", NamedTextColor.DARK_BLUE),
+            Map.entry("dark_green", NamedTextColor.DARK_GREEN),
+            Map.entry("dark_aqua", NamedTextColor.DARK_AQUA),
+            Map.entry("dark_red", NamedTextColor.DARK_RED),
+            Map.entry("dark_purple", NamedTextColor.DARK_PURPLE),
+            Map.entry("gold", NamedTextColor.GOLD),
+            Map.entry("gray", NamedTextColor.GRAY),
+            Map.entry("dark_gray", NamedTextColor.DARK_GRAY),
+            Map.entry("blue", NamedTextColor.BLUE),
+            Map.entry("green", NamedTextColor.GREEN),
+            Map.entry("aqua", NamedTextColor.AQUA),
+            Map.entry("red", NamedTextColor.RED),
+            Map.entry("light_purple", NamedTextColor.LIGHT_PURPLE),
+            Map.entry("yellow", NamedTextColor.YELLOW),
+            Map.entry("white", NamedTextColor.WHITE)
+    );
+
+    private record ParsedWord(Component component, int visibleLength) {}
+
+    private static final class StyleState {
+        private final NamedTextColor defaultColor = NamedTextColor.GRAY;
+
+        private NamedTextColor color = defaultColor;
+        private final EnumSet<TextDecoration> decorations = EnumSet.noneOf(TextDecoration.class);
+
+        void color(NamedTextColor color) {
+            this.color = color;
+        }
+        void undecorate(TextDecoration decoration) {
+            decorations.remove(decoration);
+        }
+        void decorate(TextDecoration decoration) {
+            decorations.add(decoration);
+        }
+
+        void reset() {
+            color = defaultColor;
+            decorations.clear();
+        }
+
+        net.kyori.adventure.text.format.Style toStyle() {
+            net.kyori.adventure.text.format.Style.Builder style =
+                    net.kyori.adventure.text.format.Style.style();
+            if (color != null) style.color(color);
+            for (TextDecoration d : decorations) style.decorate(d);
+            return style.build();
+        }
+    }
+
+    /**
+     * Mutable holder to avoid excessive object creation
+     */
+    private static final class Holder {
+        static ComponentBuilder builder;
+        static int length;
+
+        static Holder of(ComponentBuilder b, int l) {
+            builder = b;
+            length = l;
+            return null;
+        }
+    }
+}

+ 196 - 0
src/main/java/me/lethunderhawk/storeMore/persistence/ConfigLoader.java

@@ -0,0 +1,196 @@
+package me.lethunderhawk.storeMore.persistence;
+
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+import java.util.function.Function;
+
+public final class ConfigLoader {
+
+    private final JavaPlugin plugin;
+    private final File dataFolder;
+
+    public ConfigLoader(JavaPlugin plugin) {
+        this.plugin = plugin;
+        this.dataFolder = plugin.getDataFolder();
+
+        if (!dataFolder.exists()) {
+            dataFolder.mkdirs();
+        }
+    }
+
+    /* =========================================================
+       =============== BASIC FILE HANDLING =====================
+       ========================================================= */
+
+    public File getFile(String path) {
+        File file = new File(dataFolder, path.endsWith(".yml") ? path : path + ".yml");
+
+        if (!file.getParentFile().exists()) {
+            file.getParentFile().mkdirs();
+        }
+
+        return file;
+    }
+
+    /**
+     * @Deprecated since 1.2.5
+     * @param path
+     * @return
+     */
+    public YamlConfiguration loadConfig(String path) {
+        File file = getFile(path);
+        return YamlConfiguration.loadConfiguration(file);
+    }
+    public YamlConfiguration safeLoadConfig(String path) {
+        File file = getFile(path);
+
+        if(!file.exists())
+            return new YamlConfiguration();
+
+        try {
+            return YamlConfiguration.loadConfiguration(file);
+        } catch(Exception e) {
+            plugin.getLogger().warning("Failed to load config " + file.getName() + ", creating new one.");
+            return new YamlConfiguration();
+        }
+    }
+
+    public void saveConfig(YamlConfiguration cfg, String path) {
+        File file = getFile(path);
+        try {
+            cfg.save(file);
+        } catch (IOException e) {
+            throw new RuntimeException("Could not save file: " + file.getName(), e);
+        }
+    }
+
+    /* =========================================================
+       =============== SINGLE OBJECT ============================
+       ========================================================= */
+
+    public <T extends ConfigurationSerializable> void saveObject(
+            String path,
+            String node,
+            T object
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+        cfg.set(node, object);
+        saveConfig(cfg, path);
+    }
+
+    public <T extends ConfigurationSerializable> T loadObject(
+            String path,
+            String node,
+            Class<T> type
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+
+        Object obj = cfg.get(node);
+
+        if(obj == null){
+            System.out.println("Node '" + node + "' not found.");
+            return null;
+        }
+
+        if (!type.isInstance(obj)) {
+            throw new IllegalStateException(
+                    "Expected type " + type.getName() +
+                            " but got " + obj.getClass().getName()
+            );
+        }
+
+        return type.cast(obj);
+    }
+
+    /* =========================================================
+       =============== COLLECTION ===============================
+       ========================================================= */
+
+    public <T extends ConfigurationSerializable> void saveCollection(
+            String path,
+            String node,
+            Collection<T> collection
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+        List<T> list = new ArrayList<>(collection);
+        cfg.set(node, list);
+        saveConfig(cfg, path);
+    }
+
+    public <T extends ConfigurationSerializable> List<T> loadCollection(
+            String path,
+            String node,
+            Class<T> type
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+
+        List<?> rawList = cfg.getList(node);
+        if (rawList == null) return new ArrayList<>();
+
+        List<T> result = new ArrayList<>();
+
+        for (Object obj : rawList) {
+            if (type.isInstance(obj)) {
+                result.add(type.cast(obj));
+            }
+        }
+
+        return result;
+    }
+
+    /* =========================================================
+       =============== MAP STORAGE ==============================
+       ========================================================= */
+
+    public <K, V extends ConfigurationSerializable> void saveMap(
+            String path,
+            String node,
+            Map<K, V> map,
+            Function<K, String> keySerializer
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+
+        ConfigurationSection section = cfg.createSection(node);
+
+        for (Map.Entry<K, V> entry : map.entrySet()) {
+            String key = keySerializer.apply(entry.getKey());
+            section.set(key, entry.getValue());
+        }
+
+        saveConfig(cfg, path);
+    }
+
+    public <K, V extends ConfigurationSerializable> Map<K, V> loadMap(
+            String path,
+            String node,
+            Function<String, K> keyDeserializer,
+            Class<V> type
+    ) {
+        YamlConfiguration cfg = safeLoadConfig(path);
+
+        ConfigurationSection section = cfg.getConfigurationSection(node);
+        if (section == null) return new HashMap<>();
+
+        Map<K, V> result = new HashMap<>();
+
+        for (String key : section.getKeys(false)) {
+            Object obj = section.get(key);
+
+            if (type.isInstance(obj)) {
+                result.put(
+                        keyDeserializer.apply(key),
+                        type.cast(obj)
+                );
+            }
+        }
+
+        return result;
+    }
+}
+

+ 4 - 0
src/main/java/me/lethunderhawk/storeMore/persistence/ConfigSaver.java

@@ -0,0 +1,4 @@
+package me.lethunderhawk.storeMore.persistence;
+
+public class ConfigSaver {
+}