Class Transaction<T extends DataSerializable>

java.lang.Object
org.spongepowered.api.data.Transaction<T>
All Implemented Interfaces:
DataSerializable
Direct Known Subclasses:
BlockTransaction, SlotTransaction

public class Transaction<T extends DataSerializable> extends Object implements DataSerializable
  • Constructor Details Link icon

    • Transaction Link icon

      public Transaction(T original, T defaultReplacement)
      Creates a new transaction.
      Parameters:
      original - The original object being replaced
      defaultReplacement - The default replacement
    • Transaction Link icon

      public Transaction(T original, T defaultReplacement, @Nullable List<? extends T> intermediary)
      Creates a new Transaction with the added possibility of intermediary transactions that may have taken place between what is original and the default result. The list may be null, however the list will wrapped to become an unmodifiable list.

      It is imperative that the provided list is not to be modified outside this created Transaction synchronously and asynchronously as consumers of the provided list will not be able to react accordingly.

      Parameters:
      original - The original
      defaultReplacement - The replacement
      intermediary - The intermediary results
  • Method Details Link icon

    • original Link icon

      public final T original()
      Gets the original snapshot.
      Returns:
      The original snapshot
    • defaultReplacement Link icon

      public final T defaultReplacement()
      Gets the default replacement snapshot.
      Returns:
      The default replacement
    • intermediary Link icon

      public final List<? extends T> intermediary()
      Gets a List of any and all intermediary transactions that may have taken place to get the final Transaction of the original and the default results. This is exposed for monitoring purposes only, as the provided list is not modifiable. The list may be empty by default, but will never be null.

      Note that special processing with this list may sometimes only take place if a custom result has not been set by a plugin, or if isValid() returns false.

      Returns:
      The intermediary list of transactions
    • custom Link icon

      public final Optional<T> custom()
      Gets the custom snapshot if one was set.
      Returns:
      The custom snapshot, if available
    • setCustom Link icon

      public final void setCustom(@Nullable T custom)
      Sets the custom snapshot. If setting null, this will reset to use the defaultReplacement() snapshot.
      Parameters:
      custom - The custom snapshot
    • finalReplacement Link icon

      public final T finalReplacement()
      Gets the proposed final snapshot, if the custom() returns Optional.isPresent(), the custom is returned, otherwise, defaultReplacement() is returned.
      Returns:
      The proposed final snapshot
    • isValid Link icon

      public final boolean isValid()
      Gets whether this transaction is marked as valid.
      Returns:
      The valid state of this transaction
    • setValid Link icon

      public final void setValid(boolean valid)
      Sets whether this transaction is valid or not.
      Parameters:
      valid - The valid state of this transaction
    • validate Link icon

      public final void validate()
    • invalidate Link icon

      public final void invalidate()
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals Link icon

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • contentVersion Link icon

      public int contentVersion()
      Description copied from interface: DataSerializable
      Gets the content version of this DataSerializable. The version may differ between instances of plugins and implementations such that the DataView from DataSerializable.toContainer() may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand with DataContentUpdater as it is required when there exists any DataView of this DataSerializable with an "older" version.
      Specified by:
      contentVersion in interface DataSerializable
      Returns:
      The version of the content being serialized
    • toContainer Link icon

      public DataContainer toContainer()
      Description copied from interface: DataSerializable
      Serializes this object into a comprehensible DataContainer.
      Specified by:
      toContainer in interface DataSerializable
      Returns:
      A newly created DataContainer