Class AbstractItemEditor

java.lang.Object
com.kamikazejam.kamicommon.nms.abstraction.item.AbstractItemEditor

public abstract class AbstractItemEditor extends Object
Abstract class providing version-specific implementations for editing ItemMeta properties that may vary across Minecraft versions.

This abstraction handles the differences in item metadata manipulation between different Minecraft versions, particularly for features that were added or changed in newer versions.

  • Constructor Details

    • AbstractItemEditor

      public AbstractItemEditor()
  • Method Details

    • setUnbreakable

      public abstract ItemMeta setUnbreakable(@NotNull @NotNull ItemMeta meta, boolean unbreakable)
      Sets the unbreakable status of an item through its ItemMeta.

      This method modifies the provided ItemMeta to set whether the item should be unbreakable. Unbreakable items do not lose durability when used, regardless of their material type.

      The implementation handles version-specific differences in how the unbreakable flag is stored and accessed in item metadata.

      Parameters:
      meta - the ItemMeta to modify
      unbreakable - true to make the item unbreakable, false to make it breakable
      Returns:
      the modified ItemMeta for method chaining
    • isUnbreakable

      public abstract boolean isUnbreakable(@NotNull @NotNull ItemMeta meta)
      Parameters:
      meta - the ItemMeta to check
      Returns:
      true if the item is unbreakable, false otherwise
      Since:
      1.1.3 Checks if an item is unbreakable through its ItemMeta.

      This method retrieves the unbreakable status from the provided ItemMeta. It returns true if the item is unbreakable, and false otherwise.

      The implementation handles version-specific differences in how the unbreakable flag is stored and accessed in item metadata.

    • setDamage

      public abstract ItemStack setDamage(@NotNull @NotNull ItemStack item, int damage)
      Parameters:
      item - the ItemStack to modify
      damage - the damage value to set (0 for undamaged, higher values for more damage)
      Throws:
      IllegalArgumentException - if the item's meta does not support damage (e.g., non-damageable items)
      Since:
      1.1.4 Sets the damage (or 'durability') of an item.

      In pre-1.13 versions of Minecraft, item durability is set directly on the ItemStack
      In 1.13 and later versions, item durability is managed through the ItemMeta.

    • getDamage

      public abstract int getDamage(@NotNull @NotNull ItemStack item)
      Parameters:
      item - the ItemStack to check
      Returns:
      the current damage value (0 for undamaged, higher values for more damage)
      Throws:
      IllegalArgumentException - if the item's meta does not support damage (e.g., non-damageable items)
      Since:
      1.1.4 Gets the damage (or 'durability') of an item.

      In pre-1.13 versions of Minecraft, item durability is retrieved directly from the ItemStack
      In 1.13 and later versions, item durability is managed through the ItemMeta.

    • isDamageable

      public abstract boolean isDamageable(@NotNull @NotNull ItemStack item)
      Parameters:
      item - the ItemStack to check
      Returns:
      true if the item is damageable, false otherwise
      Since:
      1.1.5 Checks if the given item is damageable (i.e., has durability).

      This method determines if the provided ItemStack can take damage.
      - In pre-1.13 versions this checks if the item's material has a max durability greater than 0.
      - In 1.13 and later versions this checks if the item's meta is an instance of Damageable.