Class CustomStack

java.lang.Object
dev.lone.itemsadder.api.CustomStack
Direct Known Subclasses:
CustomBlock, CustomFire, CustomFurniture

public class CustomStack extends Object
Wrapper for an ItemsAdder custom item stack.
  • Constructor Details

    • CustomStack

      public CustomStack()
  • Method Details

    • getNamespacedIdsInRegistry

      public static Set<String> getNamespacedIdsInRegistry()
      Gets all custom item namespaced ids currently registered.
      Returns:
      the registered custom item namespaced ids.
    • isInRegistry

      public static boolean isInRegistry(String namespacedId)
      Checks if a custom item is registered.
      Parameters:
      namespacedId - the custom item namespaced id.
      Returns:
      true if the custom item exists in the registry.
    • byItemStack

      @Nullable public static @Nullable CustomStack byItemStack(ItemStack itemStack)
      Returns null if the provided ItemStack is not a custom item created with ItemsAdder
    • getInstance

      @Nullable public static @Nullable CustomStack getInstance(String namespacedID)
      Gets a clone of the custom stack declared in ItemsAdder registry. You can give this to a player and do whatever you want without overwriting the original item.
    • getItemStack

      public ItemStack getItemStack()
      Gets the Bukkit item stack handled by this wrapper.
      Returns:
      the Bukkit item stack.
    • getNamespace

      public String getNamespace()
      Gets the namespace of this custom item.
      Returns:
      the namespace.
    • getId

      public String getId()
      Gets the id of this custom item without namespace.
      Returns:
      the id.
    • getNamespacedID

      public String getNamespacedID()
      Gets the full namespaced id of this custom item.
      Returns:
      the namespaced id.
    • getModelPath

      public String getModelPath()
      Gets the model path configured for this custom item.
      Returns:
      the model path.
    • getConfigPath

      public String getConfigPath()
      Gets the configuration file path that defines this custom item.
      Returns:
      the configuration file path.
    • getConfig

      public FileConfiguration getConfig()
      Gets the configuration file that defines this custom item.
      Returns:
      the configuration file.
    • getPermission

      @Nullable public @Nullable String getPermission()
      Gets the permission suffix configured for this custom item.
      Returns:
      the permission suffix, or null if no permission is configured.
    • hasPermission

      public boolean hasPermission()
      Checks if this custom item has a permission configured.
      Returns:
      true if a permission is configured.
    • matchNamespacedID

      public boolean matchNamespacedID(CustomStack other)
      Checks if another custom stack has the same namespaced id.
      Parameters:
      other - the other custom stack.
      Returns:
      true if both wrappers refer to the same custom item.
    • hasAutoGeneratedModel

      public boolean hasAutoGeneratedModel()
      Checks if this custom item uses an automatically generated model.
      Returns:
      true if the model is generated by ItemsAdder.
    • getTextures

      public List<String> getTextures()
      Gets the texture paths configured for this custom item.
      Returns:
      the texture paths.
    • isBlockAllEnchants

      public boolean isBlockAllEnchants()
      Checks if this custom item blocks all enchantments.
      Returns:
      true if all enchantments are blocked.
    • hasUsagesAttribute

      public boolean hasUsagesAttribute()
      Checks if this item stack has the usages NBT attribute.
      Returns:
      true if usages are stored on the item.
    • setUsages

      public void setUsages(int amount)
      Sets the remaining usages stored on this item stack.
      Parameters:
      amount - the new usages amount.
    • reduceUsages

      public void reduceUsages(int amount)
      Reduces the remaining usages stored on this item stack.
      Parameters:
      amount - the amount to subtract.
    • getUsages

      public int getUsages()
      Gets the remaining usages stored on this item stack.
      Returns:
      the usages amount.
    • hasCustomDurability

      public boolean hasCustomDurability()
      Checks if this item stack uses ItemsAdder custom durability.
      Returns:
      true if custom durability is enabled.
    • getDurability

      public int getDurability()
      Gets the current custom durability value.
      Returns:
      the current durability.
    • setDurability

      public void setDurability(int durability)
      Sets the current custom durability value.
      Parameters:
      durability - the new durability.
    • getMaxDurability

      public int getMaxDurability()
      Gets the maximum custom durability value.
      Returns:
      the maximum durability.
    • setMaxDurability

      public void setMaxDurability(int maxDurability)
      Sets the maximum custom durability value.
      Parameters:
      maxDurability - the new maximum durability.
    • setAttributeModifier

      public void setAttributeModifier(String attributeModifier, String slotStr, double value)
      Complete list here: https://minecraft.gamepedia.com/Attribute#Attributes The slot can be mainhand, offhand, head, chest, legs or feet.

      Example: item.setAttributeModifier("attack_damage", "mainhand", 10d);

      Parameters:
      attributeModifier -
      slotStr -
      value -
    • setDisplayName

      @Deprecated public void setDisplayName(String displayName)
      Deprecated.
      use Adventure item name APIs when possible.
      Sets the legacy display name of this item stack.
      Parameters:
      displayName - the new display name.
    • getDisplayName

      public String getDisplayName()
      Gets the configured legacy display name of this custom item.
      Returns:
      the legacy display name.
    • itemName

      public net.kyori.adventure.text.Component itemName()
      Gets the Adventure item name component from this item stack.
      Returns:
      the item name component, or null if no item name is stored.
    • getDamageMainhand

      public double getDamageMainhand()
      Gets the calculated main hand damage of this item stack.
      Returns:
      the main hand damage.
    • updateAttackDamageLore

      public void updateAttackDamageLore(String slot)
      Use this if you change attack damage of the item (via enchant or attribute modifier)
      Parameters:
      slot -
    • updateAttackSpeedLore

      public void updateAttackSpeedLore(String slot)
      Use this if you change attack speed of the item

      WARNING: it just appends at the end of the lore, no checking about already existing value.

      Parameters:
      slot -
    • isBlock

      public boolean isBlock()
      Checks if this custom item is a custom block.
      Returns:
      true if this item is a custom block.
    • drop

      public boolean drop(Location loc)
      Drops this item stack naturally at a location.
      Parameters:
      loc - the drop location.
      Returns:
      true if the item was dropped.
    • getConfigSectionCopy

      public ConfigurationSection getConfigSectionCopy()
      Gets a copy of this custom item's merged configuration section.
      Returns:
      the copied configuration section.
    • getConfigSectionCopy

      public ConfigurationSection getConfigSectionCopy(boolean merged)
      Gets a copy of this custom item's configuration section.
      Parameters:
      merged - true to include inherited and merged settings.
      Returns:
      the copied configuration section.
    • hasCooldown

      public static boolean hasCooldown(Player player, ItemStack customItemStack)
      Checks if a player still has cooldown for a custom item stack.
      Parameters:
      player - the player.
      customItemStack - the custom item stack.
      Returns:
      true if the item is still in cooldown.
    • getCooldownMs

      public static long getCooldownMs(Player player, ItemStack customItemStack)
      Gets the remaining cooldown for a custom item stack.
      Parameters:
      player - the player.
      customItemStack - the custom item stack.
      Returns:
      the remaining cooldown in milliseconds, or -1 if there is no cooldown data.
    • requiresStats

      public static boolean requiresStats(ItemStack customItemStack)
      Checks if a custom item stack requires player stats.
      Parameters:
      customItemStack - the custom item stack.
      Returns:
      true if the item has required stats.
    • getRequiredStats

      @Nullable public static @Nullable Map<String,String> getRequiredStats(ItemStack customItemStack)
      Gets the player stats required by a custom item stack.
      Parameters:
      customItemStack - the custom item stack.
      Returns:
      a map of required stats, or null if the item is not custom.
    • openTradeMenu

      public static boolean openTradeMenu(String namespacedId, Player player)
      Opens a furniture trade machine menu for a player.
      Parameters:
      namespacedId - the trade machine furniture namespaced id.
      player - the player.
      Returns:
      true if the menu was opened.
    • isBlock

      public static boolean isBlock(ItemStack itemStack)
      Checks if an item stack is a custom block item.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item is a custom block.
    • isFurniture

      public static boolean isFurniture(ItemStack itemStack)
      Checks if an item stack is furniture.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has furniture behaviour.
    • isFurnitureConsumable

      public static boolean isFurnitureConsumable(ItemStack itemStack)
      Checks if an item stack is consumable furniture.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has consumable furniture behaviour.
    • isFurnitureTradeMachine

      public static boolean isFurnitureTradeMachine(ItemStack itemStack)
      Checks if an item stack is a furniture trade machine.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has trade machine furniture behaviour.
    • isFurnitureSittable

      public static boolean isFurnitureSittable(ItemStack itemStack)
      Checks if an item stack is sittable furniture.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has sittable furniture behaviour.
    • isComplexFurniture

      public static boolean isComplexFurniture(ItemStack itemStack)
      Checks if an item stack is complex furniture.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has complex furniture behaviour.
    • isVehicle

      public static boolean isVehicle(ItemStack itemStack)
      Checks if an item stack is a vehicle.
      Parameters:
      itemStack - the item stack to check.
      Returns:
      true if the item has vehicle behaviour.
    • getConfigSectionCopy

      public static ConfigurationSection getConfigSectionCopy(ItemStack itemStack) throws IllegalStateException
      Gets a copy of the merged configuration section for a custom item stack.
      Parameters:
      itemStack - the custom item stack.
      Returns:
      the copied configuration section, or null if the item is not custom.
      Throws:
      IllegalStateException - if the configuration cannot be read.
    • getConfigSectionCopy

      public static ConfigurationSection getConfigSectionCopy(ItemStack itemStack, boolean merged) throws IllegalStateException
      Gets a copy of the configuration section for a custom item stack.
      Parameters:
      itemStack - the custom item stack.
      merged - true to include inherited and merged settings.
      Returns:
      the copied configuration section, or null if the item is not custom.
      Throws:
      IllegalStateException - if the configuration cannot be read.