Package me.yleoft.zAPI.item
Class ItemBuilder
java.lang.Object
me.yleoft.zAPI.item.ItemBuilder
Utility class for building ItemStacks from configuration files.
Handles item creation with support for placeholders, conditions, and dynamic slot allocation.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull StringapplyPlaceholdersPublic(@Nullable org.bukkit.OfflinePlayer player, @NotNull String text, @Nullable Map<String, String> placeholders) Public version of applyPlaceholders for use by InventoryBuilder.static @NotNull org.bukkit.inventory.ItemStackcreateItem(@Nullable org.bukkit.OfflinePlayer player, @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull String path, @Nullable Map<String, String> placeholders) Creates an ItemStack from a configuration path with placeholder support.static @NotNull org.bukkit.inventory.ItemStackcreateItem(@Nullable org.bukkit.entity.Player player, @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull String path) Creates an ItemStack from a configuration path without placeholders.static @NotNull org.bukkit.inventory.ItemStackcreateItemFromMaterial(@Nullable org.bukkit.OfflinePlayer player, @NotNull String materialString, int amount) Creates an ItemStack from a material string, handling special head formats.createSlotPlaceholders(@Nullable org.bukkit.OfflinePlayer player, int slot, int itemIndex) Creates a placeholder map for slot-based item generation.static booleanevaluateDisplayCondition(@Nullable org.bukkit.OfflinePlayer player, @NotNull String condition, @Nullable Map<String, String> placeholders) Evaluates a display condition, supporting both comparison operators and mathematical expressions.mergePlaceholders(@Nullable Map<String, String>... maps) Merges multiple placeholder maps together.static @NotNull org.bukkit.MaterialparseMaterial(@NotNull String materialString) Parses a material string, handling special head formats.parsePlaceholderDefinitions(@Nullable org.bukkit.OfflinePlayer player, @NotNull org.bukkit.configuration.file.YamlConfiguration config, @NotNull String path, @Nullable Map<String, String> basePlaceholders) Parses placeholder definitions from the config and processes them once.static voidRegisters native item placeholders with the placeholder handler system.static voidreplacePlaceholders(@NotNull org.bukkit.inventory.ItemStack item, @NotNull Map<String, String> replacements) Replaces placeholders in an existing item's name and lore.
-
Field Details
-
KEY_MATERIAL
- See Also:
-
KEY_AMOUNT
- See Also:
-
KEY_NAME
- See Also:
-
KEY_LORE
- See Also:
-
KEY_ENCHANTMENTS
- See Also:
-
KEY_UNBREAKABLE
- See Also:
-
KEY_ITEM_FLAGS
- See Also:
-
KEY_PICKABLE
- See Also:
-
KEY_COMMANDS
- See Also:
-
KEY_DISPLAY_CONDITION
- See Also:
-
KEY_PLACEHOLDERS
- See Also:
-
-
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 definitionpath- The configuration path to the itemplaceholders- 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 resolutiontext- The text to processplaceholders- 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 configurationpath- The configuration path to the placeholders sectionbasePlaceholders- 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 resolutioncondition- The condition string to evaluateplaceholders- 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.
-