Class RtagItem

java.lang.Object
com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
com.saicone.rtag.RtagItem

public class RtagItem extends com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
RtagItem class to edit any ItemStack NBT tags.
  • Constructor Details

    • RtagItem

      public RtagItem(ItemStack item)
      Constructs an RtagItem with ItemStack to edit.
      Parameters:
      item - Item to load changes.
    • RtagItem

      public RtagItem(com.saicone.rtag.Rtag rtag, ItemStack item)
      Constructs an RtagItem with specified Rtag parent and ItemStack to edit.
      Parameters:
      rtag - Rtag parent.
      item - Item to load changes.
    • RtagItem

      public RtagItem(com.saicone.rtag.Rtag rtag, ItemStack item, Object mcItem)
      Constructs an RtagItem with specified Rtag parent and NMS ItemStack to edit.
      Parameters:
      rtag - Rtag parent.
      item - Item to load changes.
      mcItem - Minecraft server item to edit.
    • RtagItem

      public RtagItem(com.saicone.rtag.Rtag rtag, ItemStack item, Object mcItem, Object tag)
      Constructs an RtagItem with specified Rtag parent and NMS ItemStack to edit.
      Parameters:
      rtag - Rtag parent.
      item - Item to load changes.
      mcItem - Minecraft server item to edit.
      tag - Item tag to edit.
  • Method Details

    • of

      public static RtagItem of(ItemStack item)
      Create an RtagItem using ItemStack.
      Parameters:
      item - Item to load changes.
      Returns:
      new RtagItem instance.
    • of

      public static RtagItem of(com.saicone.rtag.Rtag rtag, ItemStack item)
      Create an RtagItem using ItemStack and specified Rtag parent.
      Parameters:
      rtag - Rtag parent.
      item - Item to load changes.
      Returns:
      new RtagItem instance.
    • getItem

      public ItemStack getItem()
      Get current item instance.
      Returns:
      A Bukkit ItemStack.
    • getEditor

      protected RtagItem getEditor()
      Overrides:
      getEditor in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getLiteralObject

      public Object getLiteralObject(ItemStack item)
      Specified by:
      getLiteralObject in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getLiteralTag

      public Object getLiteralTag()
      Get current item tag or null.
      Returns:
      a compound tag.
    • getTag

      public Object getTag()
      Get current item tag to edit.
      If this instance has not been edited, it will copy the current tag or create a new one if the current tag is null.
      Overrides:
      getTag in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
      Returns:
      a compound tag.
    • getTag

      public Object getTag(Object item)
      Specified by:
      getTag in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getComponents

      @Experimental public Object getComponents()
      Get current data components.
      Returns:
      A patched data component map.
    • load

      public ItemStack load()
      Load changes into item instance.
      Specified by:
      load in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
      Returns:
      The current item instance.
    • loadCopy

      public ItemStack loadCopy()
      Load changes into new ItemStack instance and return it.
      Returns:
      Copy of the original item with changes loaded.
    • loadInto

      public <T> T loadInto(T item)
      Load changes into provided Minecraft ItemStack and return it.
      Type Parameters:
      T - Item type.
      Parameters:
      item - The item to load changes into
      Returns:
      The provided item with changes loaded.
    • update

      public void update(Object object)
      Overrides:
      update in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • hasComponent

      @Experimental public boolean hasComponent(Object type)
      Check if the current item or patch has he provided data component type.
      Parameters:
      type - Data component type object or ID.
      Returns:
      true if the item has the component type.
    • set

      public boolean set(Object value)
      Change item tag into new one.
      Value must be Map<String, Object> or CompoundTag.
      Overrides:
      set in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
      Parameters:
      value - Object to replace current tag.
      Returns:
      True if tag has replaced.
    • setComponent

      @Experimental public void setComponent(Object type)
      Set the provided component into patch.
      Parameters:
      type - Data component type object or ID.
    • setComponent

      @Experimental public void setComponent(Object type, Object value)
      Set the provided component value into patch.
      Parameters:
      type - Data component type object or ID.
      value - The value to parse, can be NBT, JsonElement or Java object.
    • removeComponent

      @Experimental public void removeComponent(Object type)
      Mark the provided component type to be removed using current patch.
      Parameters:
      type - Data component type object or ID.
    • get

      public Map<String,Object> get()
      Overrides:
      get in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • get

      public <V> V get(Object... path)
      Overrides:
      get in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getOptional

      public com.saicone.rtag.util.OptionalType getOptional(Object... path)
      Overrides:
      getOptional in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getExact

      public Object getExact(Object... path)
      Overrides:
      getExact in class com.saicone.rtag.RtagEditor<ItemStack, RtagItem>
    • getComponent

      @Experimental public Object getComponent(Object type)
      Get the provided component from patch or item.
      Parameters:
      type - Data component type object or ID.
      Returns:
      An object represented by component type or null if not exist.
    • hasHideFlags

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public boolean hasHideFlags(int... hideFlags)
      Deprecated.
      Check if the current item has the provided hide flags ordinals.
      Parameters:
      hideFlags - Flags to check.
      Returns:
      true if the item has all the flags.
      See Also:
    • hasEnchantment

      public boolean hasEnchantment(Object enchant)
      Check if the current item has the provided enchantment.
      Parameters:
      enchant - Enchantment object.
      Returns:
      true if contains the enchantment.
    • fixSerialization

      public void fixSerialization()
      Fix bad item caused by Bukkit serialization, most specifically item lore component that doesn't allow to compare with similar items.
    • addHideFlags

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public boolean addHideFlags(int... hideFlags)
      Deprecated.
      Add hide flags to item using flag ordinal:
      0 = Enchantments
      1 = AttributeModifiers
      2 = Unbreakable
      3 = CanDestroy
      4 = CanPlaceOn
      5 = Other information (stored enchants, potion effects, generation, author, explosion and fireworks)
      6 = Dyed
      7 = Palette information (armor trim)
      Parameters:
      hideFlags - Flags to add.
      Returns:
      true if the flags was added.
    • addEnchantment

      public boolean addEnchantment(Object enchant, int level)
      Add the provided enchantment to the item.
      Parameters:
      enchant - Enchantment object.
      level - Enchantment level.
      Returns:
      true if the enchantment was added.
    • setUnbreakable

      public boolean setUnbreakable(boolean unbreakable)
      Change the current unbreakable status of item.
      Parameters:
      unbreakable - true to make item unbreakable.
      Returns:
      true if the status was changed.
    • setCustomModelData

      @Deprecated public boolean setCustomModelData(Integer model)
      Deprecated.
      Set the current custom model data of item.
      Parameters:
      model - Model id, null of you want to remove it.
      Returns:
      true if the model was set or removed.
    • setHideFlags

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public boolean setHideFlags(int... hideFlags)
      Deprecated.
      Override the current item hide flags.
      Parameters:
      hideFlags - Flags to set.
      Returns:
      true if the flags was set.
      See Also:
    • setRepairCost

      public boolean setRepairCost(int cost)
      Change the item repair cost inside anvil.
      Parameters:
      cost - XP level repair cost.
      Returns:
      true if the repair cost was changes.
    • removeHideFlags

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public boolean removeHideFlags(int... hideFlags)
      Deprecated.
      Remove hide flags from item using flag ordinal.
      Parameters:
      hideFlags - Flags to remove.
      Returns:
      true if the flags was removed.
      See Also:
    • removeEnchantment

      public int removeEnchantment(EnchantmentTag enchant)
      Remove from item the provided enchantment.
      Parameters:
      enchant - Enchantment object.
      Returns:
      the enchantment level that was set on the item.
    • getCustomModelData

      @Deprecated public Integer getCustomModelData()
      Deprecated.
      Get the current custom model data inside item.
      Returns:
      Model id, null if the item doesn't have model.
    • getHideFlags

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public Set<Integer> getHideFlags()
      Deprecated.
      Get current hide flags.
      Returns:
      A set of flag ordinals.
      See Also:
    • getRepairCost

      public int getRepairCost()
      Get the XP level repair cost inside anvil.
      Returns:
      Level repair cost.
    • getEnchantment

      public Object getEnchantment(Object enchant)
      Get the CompoundTag that represent the provided enchantment.
      Parameters:
      enchant - Enchantment object.
      Returns:
      a compound tag if the enchantment was found, null otherwise.
    • getEnchantmentLevel

      public int getEnchantmentLevel(Object enchant)
      Get the current level for provided enchantment.
      Parameters:
      enchant - Enchantment object.
      Returns:
      Level integer if the enchantment was found, 0 otherwise.
    • getEnchantments

      public Map<EnchantmentTag, Integer> getEnchantments()
      Get all the enchantments inside item.
      Returns:
      A Map of EnchantmentTag objects.
    • isUnbreakable

      public boolean isUnbreakable()
      Get the current unbreakable status.
      Returns:
      true if the item is unbreakable.
    • edit

      public static <T extends ItemStack> T edit(T item, Consumer<RtagItem> consumer)
      Edit the provided item using a RtagItem instance by consumer.
      Type Parameters:
      T - ItemStack type.
      Parameters:
      item - Item to edit.
      consumer - Consumer to accept.
      Returns:
      The provided item.
    • edit

      public static <T extends ItemStack, R> R edit(T item, Function<RtagItem,R> function)
      Edit a RtagItem instance using the provided item by function that return any type.
      Take in count that you should use RtagEditor.load() if you want to load the changes.
      Type Parameters:
      T - ItemStack type.
      R - The required return type.
      Parameters:
      item - Item to edit.
      function - Function to apply.
      Returns:
      The object provided by the function.
    • edit

      public static <T extends ItemStack> T edit(com.saicone.rtag.Rtag rtag, T item, Consumer<RtagItem> consumer)
      Edit the provided item using a RtagItem instance by consumer with defined Rtag parent.
      Type Parameters:
      T - ItemStack type.
      Parameters:
      rtag - Rtag parent.
      item - Item to edit.
      consumer - Consumer to accept.
      Returns:
      The provided item.
    • edit

      public static <T extends ItemStack, R> R edit(com.saicone.rtag.Rtag rtag, T item, Function<RtagItem,R> function)
      Edit a RtagItem instance using the provided item by function that return any type with defined Rtag parent.
      Take in count that you should use RtagEditor.load() if you want to load the changes.
      Type Parameters:
      T - ItemStack type.
      R - The required return type.
      Parameters:
      rtag - Rtag parent.
      item - Item to edit.
      function - Function to apply.
      Returns:
      The object provided by the function.