Class RtagEditor<T, EditorT extends RtagEditor<T,EditorT>>

java.lang.Object
com.saicone.rtag.RtagEditor<T,EditorT>
Type Parameters:
T - Parent object type.
EditorT - Editor object type.

public abstract class RtagEditor<T, EditorT extends RtagEditor<T,EditorT>> extends Object
RtagEditor abstract class who edit any object with CompoundTag inside.
Also provide methods to easy-edit object tags using a Rtag instance.
  • Field Details

    • rtag

      protected final Rtag rtag
    • typeObject

      protected final T typeObject
    • literalObject

      protected Object literalObject
    • tag

      protected Object tag
  • Constructor Details

    • RtagEditor

      public RtagEditor(Rtag rtag, T typeObject)
      Constructs an NBTEditor.
      Parameters:
      rtag - Rtag parent.
      typeObject - Editor type object that can be converted to literal object.
    • RtagEditor

      public RtagEditor(Rtag rtag, T typeObject, Object literalObject)
      Constructs an NBTEditor.
      Parameters:
      rtag - Rtag parent.
      typeObject - Editor type object that can be converted to literal object.
      literalObject - Object instance with CompoundTag inside.
    • RtagEditor

      public RtagEditor(Rtag rtag, T typeObject, Object literalObject, Object tag)
      Constructs an NBTEditor.
      Parameters:
      rtag - Rtag parent.
      typeObject - Editor type object that can be converted to literal object.
      literalObject - Object instance with CompoundTag inside.
      tag - CompoundTag object to edit.
  • Method Details

    • getEditor

      protected EditorT getEditor()
      Get current RtagEditor object.
      Returns:
      A RtagEditor instance.
    • getRtag

      public Rtag getRtag()
      Get current Rtag parent.
      Returns:
      A Rtag instance.
    • getObject

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public Object getObject()
      Deprecated.
      To get current object use getLiteralObject() instead.
      Get current object instance.
      Returns:
      An object with CompoundTag inside.
      See Also:
    • getTypeObject

      public T getTypeObject()
      Get current type object defined on editor.
      Returns:
      An object that can be converted to literal object.
    • getLiteralObject

      public Object getLiteralObject()
      Get current literal object.
      In most cases this is a Minecraft server object.
      Returns:
      An object with CompoundTag inside.
    • getLiteralObject

      public abstract Object getLiteralObject(T typeObject)
      Get type object as literal one.
      Parameters:
      typeObject - Editor type object that can be converted to literal object.
      Returns:
      An object with CompoundTag inside.
    • getTag

      public Object getTag()
      Get current tag.
      Returns:
      a compound tag.
    • getTag

      public abstract Object getTag(Object object)
      Get current tag inside type or literal object.
      Parameters:
      object - Object instance with CompoundTag inside.
      Returns:
      a compound tag.
    • load

      public abstract T load()
      Load changes into object instance.
      Returns:
      The current instance type object.
    • update

      public void update()
      Update the current tag using the original object type.
    • update

      public void update(Object object)
      Update the current tag using the provided object type.
      Parameters:
      object - Object type according RtagEditor instance.
    • hasTag

      public boolean hasTag()
      Check if current object has tag.
      Returns:
      True if tag is not null.
    • hasTag

      public boolean hasTag(Object... path)
      Check if current tag contains a object in defined path.
      Parameters:
      path - Final value path to get.
      Returns:
      True if final value is not null.
    • notHasTag

      public boolean notHasTag()
      Same has hasTag() but with inverted result.
      Returns:
      True if tag is null.
    • notHasTag

      public boolean notHasTag(Object... path)
      Same has hasTag(Object...) but with inverted result.
      Parameters:
      path - Final value path to get.
      Returns:
      True if final value is null.
    • hasEnum

      public <E extends Enum<E>> boolean hasEnum(E element, Object... path)
      Check if current tag has Enum element in defined path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      element - Enum element to check.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the tag contains a bit field with enum ordinal.
    • hasEnum

      public <E extends Enum<E>> boolean hasEnum(E[] elements, Object... path)
      Check if current tag has Enum elements array in defined path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      elements - Enum elements to check.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the tag contains a bit field with enum ordinals.
    • hasEnum

      public boolean hasEnum(int ordinal, Object... path)
      Check if current tag has Enum ordinal in defined path.
      Parameters:
      ordinal - Enum ordinal to check.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the tag contains a bit field with enum ordinal.
    • hasEnum

      public boolean hasEnum(int[] ordinals, Object... path)
      Check if current tag has Enum ordinals in defined path.
      Parameters:
      ordinals - Enum ordinal to check.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the tag contains a bit field with enum ordinals.
    • add

      public boolean add(Object value, Object... path)
      Add value to an ListTag on specified path inside current object tag.
      See Rtag.add(Object, Object, Object...) for more information.
      Parameters:
      value - Value to add.
      path - Final list path to add the specified value.
      Returns:
      True if the value was added.
    • addEnum

      public <E extends Enum<E>> boolean addEnum(E element, Object... path)
      Add Enum element into bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      element - Enum element to add.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum element was added successfully.
    • addEnum

      public <E extends Enum<E>> boolean addEnum(E[] elements, Object... path)
      Add Enum elements into bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      elements - Enum elements to add.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum elements was added successfully.
    • addEnum

      public boolean addEnum(int ordinal, Object... path)
      Add Enum ordinal into bit field on specified path.
      Parameters:
      ordinal - Enum ordinal to add.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum ordinal was added successfully.
    • addEnum

      public boolean addEnum(int[] ordinals, Object... path)
      Add Enum ordinals into bit field on specified path.
      Parameters:
      ordinals - Enum ordinals to add.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum ordinals was added successfully.
    • set

      public boolean set(Object value)
      Change object tag into new one.
      Value must be Map<String, Object> or CompoundTag.
      Parameters:
      value - Object to replace current tag.
      Returns:
      True if tag has replaced.
    • set

      public boolean set(Object value, Object... path)
      Set value to specified path inside current tag.
      See Rtag.set(Object, Object, Object...) for more information.
      Parameters:
      value - Value to set.
      path - Final value path to set.
      Returns:
      True if the value is set.
    • setEnum

      public <E extends Enum<E>> boolean setEnum(E element, Object... path)
      Set Enum element has bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      element - Enum element to set.
      path - Path to store enum ordinals has integer.
      Returns:
      true if the Enum element was set successfully.
    • setEnum

      public <E extends Enum<E>> boolean setEnum(E[] elements, Object... path)
      Set Enum elements has bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      elements - Enum elements to set.
      path - Path to store enum ordinals has integer.
      Returns:
      true if the Enum elements was set successfully.
    • setEnum

      public boolean setEnum(int ordinal, Object... path)
      Set Enum ordinal has bit field on specified path.
      Parameters:
      ordinal - Enum ordinal to set.
      path - Path to store enum ordinals has integer.
      Returns:
      true if the Enum ordinal was set successfully.
    • setEnum

      public boolean setEnum(int[] ordinals, Object... path)
      Set Enum ordinals has bit field on specified path.
      Parameters:
      ordinals - Enum ordinals to set.
      path - Path to store enum ordinals has integer.
      Returns:
      true if the Enum ordinals was set successfully.
    • merge

      public boolean merge(Object value, boolean replace)
      Merge the provided value into current tag.
      Parameters:
      value - The value to merge.
      replace - True to replace the repeated values inside current tag.
      Returns:
      true if the value was merged.
    • merge

      public boolean merge(Object value, boolean replace, Object... path)
      Merge the provided value at provided path.
      Parameters:
      value - The value to merge.
      replace - True to replace the repeated values inside CompoundTag.
      path - Final value path to merge into.
      Returns:
      true if the value was merged.
    • deepMerge

      public boolean deepMerge(Object value, boolean replace)
      Merge the provided value into current tag using deep method.
      Parameters:
      value - The value to merge.
      replace - True to replace the repeated values inside current tag.
      Returns:
      true if the value was merged.
    • deepMerge

      public boolean deepMerge(Object value, boolean replace, Object... path)
      Merge the provided value at provided path using deep method.
      Parameters:
      value - The value to merge.
      replace - True to replace the repeated values inside CompoundTag.
      path - Final value path to merge into.
      Returns:
      true if the value was merged.
    • move

      public boolean move(Object[] from, Object[] to)
      Move tag from specified path to any path.
      Parameters:
      from - Path to get the value.
      to - Path to set the value.
      Returns:
      true if the value was moved.
    • move

      public boolean move(Object[] from, Object[] to, boolean clear)
      Move tag from specified path to any path.
      Parameters:
      from - Path to get the value.
      to - Path to set the value.
      clear - True to clear empty paths.
      Returns:
      true if the value was moved.
    • remove

      public boolean remove(Object... path)
      Remove value to specified path inside current tag.
      See Rtag.set(Object, Object, Object...) for more information.
      Parameters:
      path - Final value path to remove.
      Returns:
      True if the value associated with the path exists and is removed.
    • removeEnum

      public <E extends Enum<E>> boolean removeEnum(E element, Object... path)
      Remove Enum element from bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      element - Enum element to remove.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum element was removed or the bit field doesn't exist.
    • removeEnum

      public <E extends Enum<E>> boolean removeEnum(E[] elements, Object... path)
      Remove Enum elements from bit field on specified path.
      Type Parameters:
      E - Enum element type.
      Parameters:
      elements - Enum elements to remove.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum elements was removed or the bit field doesn't exist.
    • removeEnum

      public boolean removeEnum(int ordinal, Object... path)
      Remove Enum ordinal from bit field on specified path.
      Parameters:
      ordinal - Enum ordinal to remove.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum ordinal was removed or the bit field doesn't exist.
    • removeEnum

      public boolean removeEnum(int[] ordinals, Object... path)
      Remove Enum ordinals from bit field on specified path.
      Parameters:
      ordinals - Enum ordinals to remove.
      path - Path with Integer storing enum ordinals.
      Returns:
      true if the Enum ordinals was removed or the bit field doesn't exist.
    • get

      public Map<String,Object> get()
      Get a converted version of current tag.
      Returns:
      A Map with objects converted by Rtag parent.
    • get

      public <V> V get(Object... path)
      Get value from the specified path inside current tag.
      See Rtag.get(Object, Object...) for more information.
      Type Parameters:
      V - Object type to cast the value.
      Parameters:
      path - Final value path to get.
      Returns:
      The value assigned to specified path, null if not exist or a ClassCastException occurs.
    • getOptional

      public OptionalType getOptional(Object... path)
      Same has get(Object...) but save the value into OptionalType.
      Parameters:
      path - Final value path to get.
      Returns:
      The value assigned to specified path has OptionalType.
    • getExact

      public Object getExact(Object... path)
      Get exact Tag value without any conversion, from the specified path inside current tag.
      See Rtag.getExact(Object, Object...) for more information.
      Parameters:
      path - Final value path to get.
      Returns:
      The value assigned to specified path, null if not exist.
    • getBitField

      public int getBitField(Object... path)
      Get Integer bit field from specified path.
      Parameters:
      path - Final value path to get.
      Returns:
      The value assigned to specified path, 0 if not exist.
    • edit

      public EditorT edit(Consumer<EditorT> consumer)
      Edit the current RtagEditor instance and return itself.
      Parameters:
      consumer - Function to apply.
      Returns:
      The current RtagEditor instance.