Package org.spongepowered.api.data
Class Transaction<T extends DataSerializable>
java.lang.Object
org.spongepowered.api.data.Transaction<T>
- All Implemented Interfaces:
DataSerializable
- Direct Known Subclasses:
BlockTransaction
,SlotTransaction
-
Constructor Summary
ConstructorDescriptionTransaction
(T original, T defaultReplacement) Creates a new transaction.Transaction
(T original, T defaultReplacement, @Nullable List<? extends T> intermediary) Creates a newTransaction
with the added possibility of intermediary transactions that may have taken place between what isoriginal
andthe default result
. -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the content version of thisDataSerializable
.custom()
Gets the custom snapshot if one was set.final T
Gets the default replacement snapshot.boolean
final T
Gets the proposed final snapshot, if thecustom()
returnsOptional.isPresent()
, the custom is returned, otherwise,defaultReplacement()
is returned.int
hashCode()
Gets aList
of any and all intermediary transactions that may have taken place to get the finalTransaction
ofthe original
andthe default
results.final void
final boolean
isValid()
Gets whether this transaction is marked as valid.final T
original()
Gets the original snapshot.final void
Sets the custom snapshot.final void
setValid
(boolean valid) Sets whether this transaction is valid or not.Serializes this object into a comprehensibleDataContainer
.toString()
final void
validate()
-
Constructor Details
-
Transaction
Creates a new transaction.- Parameters:
original
- The original object being replaceddefaultReplacement
- The default replacement
-
Transaction
Creates a newTransaction
with the added possibility of intermediary transactions that may have taken place between what isoriginal
andthe default result
. The list may benull
, 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 originaldefaultReplacement
- The replacementintermediary
- The intermediary results
-
-
Method Details
-
original
Gets the original snapshot.- Returns:
- The original snapshot
-
defaultReplacement
Gets the default replacement snapshot.- Returns:
- The default replacement
-
intermediary
Gets aList
of any and all intermediary transactions that may have taken place to get the finalTransaction
ofthe original
andthe default
results. This is exposed for monitoring purposes only, as the provided list is not modifiable. The list may beempty
by default, but will never benull
.Note that special processing with this list may sometimes only take place if
a custom
result has not been set by a plugin, or ifisValid()
returnsfalse
.- Returns:
- The intermediary list of transactions
-
custom
Gets the custom snapshot if one was set.- Returns:
- The custom snapshot, if available
-
setCustom
Sets the custom snapshot. If settingnull
, this will reset to use thedefaultReplacement()
snapshot.- Parameters:
custom
- The custom snapshot
-
finalReplacement
Gets the proposed final snapshot, if thecustom()
returnsOptional.isPresent()
, the custom is returned, otherwise,defaultReplacement()
is returned.- Returns:
- The proposed final snapshot
-
isValid
public final boolean isValid()Gets whether this transaction is marked as valid.- Returns:
- The valid state of this transaction
-
setValid
public final void setValid(boolean valid) Sets whether this transaction is valid or not.- Parameters:
valid
- The valid state of this transaction
-
validate
public final void validate() -
invalidate
public final void invalidate() -
hashCode
public int hashCode() -
equals
-
toString
-
contentVersion
public int contentVersion()Description copied from interface:DataSerializable
Gets the content version of thisDataSerializable
. The version may differ between instances of plugins and implementations such that theDataView
fromDataSerializable.toContainer()
may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand withDataContentUpdater
as it is required when there exists anyDataView
of thisDataSerializable
with an "older" version.- Specified by:
contentVersion
in interfaceDataSerializable
- Returns:
- The version of the content being serialized
-
toContainer
Description copied from interface:DataSerializable
Serializes this object into a comprehensibleDataContainer
.- Specified by:
toContainer
in interfaceDataSerializable
- Returns:
- A newly created DataContainer
-