Class ItemBuilder

java.lang.Object
me.yleoft.zAPI.item.ItemBuilder

public abstract class ItemBuilder extends Object
Utility class for building ItemStacks from configuration files. Handles item creation with support for placeholders, conditions, and dynamic slot allocation.
  • Field Details

  • Constructor Details

    • ItemBuilder

      public ItemBuilder()
  • Method Details

    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@Nullable @Nullable org.bukkit.OfflinePlayer player, @NotNull @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull @NotNull String path, @Nullable @Nullable Map<String,String> placeholders)
      Creates an ItemStack from a configuration path with placeholder support.
      Parameters:
      player - The player for placeholder resolution (can be null)
      config - The YAML configuration containing the item definition
      path - The configuration path to the item
      placeholders - Additional placeholders to apply (can be null)
      Returns:
      The created ItemStack
    • createItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItem(@Nullable @Nullable org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull @NotNull String path)
      Creates an ItemStack from a configuration path without placeholders.
    • parseMaterial

      @NotNull public static @NotNull org.bukkit.Material parseMaterial(@NotNull @NotNull String materialString)
      Parses a material string, handling special head formats.
    • createItemFromMaterial

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createItemFromMaterial(@Nullable @Nullable org.bukkit.OfflinePlayer player, @NotNull @NotNull String materialString, int amount)
      Creates an ItemStack from a material string, handling special head formats.
    • registerNativePlaceholders

      public static void registerNativePlaceholders()
      Registers native item placeholders with the placeholder handler system. This allows native placeholders to work with both PAPI and MiniPlaceholders. Should be called during plugin initialization.
    • applyPlaceholdersPublic

      @NotNull public static @NotNull String applyPlaceholdersPublic(@Nullable @Nullable org.bukkit.OfflinePlayer player, @NotNull @NotNull String text, @Nullable @Nullable Map<String,String> placeholders)
      Public version of applyPlaceholders for use by InventoryBuilder. This allows InventoryBuilder to process slot strings with placeholders and math.
      Parameters:
      player - The player for placeholder resolution
      text - The text to process
      placeholders - Custom placeholders to apply
      Returns:
      The processed text
    • createSlotPlaceholders

      @NotNull public static @NotNull Map<String,String> createSlotPlaceholders(@Nullable @Nullable org.bukkit.OfflinePlayer player, int slot, int itemIndex)
      Creates a placeholder map for slot-based item generation. Provides placeholders for: - %slot% - The slot number (0-based index) - %currentitem% - The item index in a multi-slot item (1-based)
      Parameters:
      player - The player (can be null)
      slot - The slot number (0-based)
      itemIndex - The item index (1-based, for when an item is spread across multiple slots)
      Returns:
      Map of slot-related placeholders
    • mergePlaceholders

      @NotNull public static @NotNull Map<String,String> mergePlaceholders(@Nullable @Nullable Map<String,String>... maps)
      Merges multiple placeholder maps together.
    • parsePlaceholderDefinitions

      @NotNull public static @NotNull Map<String,String> parsePlaceholderDefinitions(@Nullable @Nullable org.bukkit.OfflinePlayer player, @NotNull @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull @NotNull String path, @Nullable @Nullable Map<String,String> basePlaceholders)
      Parses placeholder definitions from the config and processes them once. The placeholders are evaluated following the standard order: 1. Custom placeholders (from basePlaceholders parameter) 2. Math expressions 3. PlaceholderAPI placeholders This allows you to define placeholders in the config that get parsed once and then reused across name, lore, commands, etc. Example config:
       item:
         name: "%parsedplaceholder%"
         lore:
           - "Value: %parsedplaceholder%"
         placeholders:
           parsedplaceholder: "Player #%currentitem% - %player_name%"
       
      Parameters:
      player - The player for placeholder resolution (can be null)
      config - The YAML configuration
      path - The configuration path to the placeholders section
      basePlaceholders - Base placeholders to use when parsing (e.g., %slot%, %currentitem%)
      Returns:
      Map of parsed placeholders ready to use
    • evaluateDisplayCondition

      public static boolean evaluateDisplayCondition(@Nullable @Nullable org.bukkit.OfflinePlayer player, @NotNull @NotNull String condition, @Nullable @Nullable Map<String,String> placeholders)
      Evaluates a display condition, supporting both comparison operators and mathematical expressions. Mathematical operations supported: - Basic: *, /, +, - - Functions: sqrt(), round(), roundDown() Example conditions: - "%homes_limit%*%zhomes_limit_multiplier%>=30" - "sqrt(%player_level%)+5>10" - "round(%value%/2)==5"
      Parameters:
      player - The player for placeholder resolution
      condition - The condition string to evaluate
      placeholders - Additional placeholders to apply
      Returns:
      true if the condition is met, false otherwise
    • replacePlaceholders

      public static void replacePlaceholders(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull Map<String,String> replacements)
      Replaces placeholders in an existing item's name and lore.