Class: TransactionManager
The Transaction Manager is responsible for tracking and managing all of the registered transaction operations which represent creator changes in the world. Transaction Manager is the basis of the UNDO and REDO operations, and allows a creator to store the changes made to the world and the state of the world BEFORE those changes were applied, making it possible to UNDO those changes and restore the world state. The transactions are stored as a stack, and can be undone in stack order to restore the world to it's original state
Constructors
new TransactionManager()
private
new TransactionManager():TransactionManager
Returns
Methods
addUserDefinedOperation()
addUserDefinedOperation(
transactionHandlerId
,operationData
,operationName
?):void
Parameters
Parameter | Type |
---|---|
transactionHandlerId | UserDefinedTransactionHandlerId |
operationData | string |
operationName ? | string |
Returns
void
Remarks
This function can't be called in read-only mode.
Throws
This function can throw errors.
commitOpenTransaction()
commitOpenTransaction():
boolean
Returns
boolean
Remarks
Commit all of the transaction operations currently attached to the open transaction record to the manager. These will be added as a single transaction manager entry. The open record will be closed and all tracking operations will cease.
This function can't be called in read-only mode.
Throws
This function can throw errors.
commitTrackedChanges()
commitTrackedChanges():
number
Returns
number
Returns the number of change requests that were being tracked
Remarks
This function will commit the pending changes caused by any of the track changes variants. The changes will be committed to the currently open transaction, but the transaction will remain open for further records. Pending block changes from tracking operations will be added to the transaction record before submission to the transaction manager
This function can't be called in read-only mode.
Throws
This function can throw errors.
createUserDefinedTransactionHandler()
createUserDefinedTransactionHandler(
undoClosure
,redoClosure
):UserDefinedTransactionHandlerId
Parameters
Parameter | Type |
---|---|
undoClosure | (arg ) => void |
redoClosure | (arg ) => void |
Returns
UserDefinedTransactionHandlerId
Remarks
This function can't be called in read-only mode.
Throws
This function can throw errors.
discardOpenTransaction()
discardOpenTransaction():
boolean
Returns
boolean
Remarks
Discard the currently open transaction without committing it to the transaction manager stack. All records within the transaction will be discarded, and any tracking requests currently active will be stopped
This function can't be called in read-only mode.
Throws
This function can throw errors.
discardTrackedChanges()
discardTrackedChanges():
number
Returns
number
Returns the number of change requests that were discarded
Remarks
Discard any pending tracked changes. This does not affect the current open transaction contents, only the pending tracked block operations
This function can't be called in read-only mode.
Throws
This function can throw errors.
openTransaction()
openTransaction(
name
):boolean
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Give the transaction record a name |
Returns
boolean
Remarks
Open a transaction record which will be a container for any number of transaction operations. All transaction operations within a record are grouped and treated as a single atomic unit
This function can't be called in read-only mode.
Throws
This function can throw errors.
redo()
redo():
void
Returns
void
Remarks
Perform an redo operation. This will take the last transaction record on the redo stack and store the current world state and then apply the changes in the record. This will reduce the redo record stack by one.
The transaction record affected by this operation will be transferred to the undo stack in case the creator decides to undo it
This function can't be called in read-only mode.
Throws
This function can throw errors.
redoSize()
redoSize():
number
Returns
number
Remarks
Return the number of transaction records on the redo stack.
This function can't be called in read-only mode.
Throws
This function can throw errors.
trackBlockChangeArea()
trackBlockChangeArea(
from
,to
):boolean
Parameters
Parameter | Type | Description |
---|---|---|
from | Vector3 | Min block location of a bounding area |
to | Vector3 | Max block location of a bounding area |
Returns
boolean
Remarks
Begin tracking block changes in a specified area. These will be added to a pending changes list. The pending list will be added to the open transaction record when a commit has been issued.
This function can't be called in read-only mode.
Throws
This function can throw errors.
trackBlockChangeCompoundBlockVolume()
trackBlockChangeCompoundBlockVolume(
compoundBlockVolume
):boolean
Parameters
Parameter | Type | Description |
---|---|---|
compoundBlockVolume | CompoundBlockVolume | @minecraft-server/CompoundBlockVolume to track. Only non-void block locations will be tracked -- any changes falling into a void/negative space will not be tracked |
Returns
boolean
Remarks
Begin tracking block changes in an area defined by a @minecraft-server/CompoundBlockVolume. These will be added to a pending changes list. The pending list will be added to the open transaction record when a commit has been issued.
This function can't be called in read-only mode.
Throws
This function can throw errors.
trackBlockChangeList()
trackBlockChangeList(
locations
):boolean
Parameters
Parameter | Type | Description |
---|---|---|
locations | Vector3 [] | An array of block locations to monitor for changes |
Returns
boolean
Remarks
Begin tracking block changes in a list of specified block locations.
This function can't be called in read-only mode.
Throws
This function can throw errors.
trackBlockChangeSelection()
trackBlockChangeSelection(
selection
):boolean
Parameters
Parameter | Type | Description |
---|---|---|
selection | Selection | A collection of block location volumes represented by a Selection volume to monitor for changes. The Selection Volume is copied, so further changes to the volume after this call will not be reflected in the tracking list. |
Returns
boolean
Remarks
Begin tracking block changes that may happen in a selection volume. The volume is copied, so tracking will not move if the selection volume is translated after this instruction is issued. Selection Volumes can also represent irregular shapes with non-contiguous blocks and this tracking call will honor the actual selected areas in the volume (and not the negative space) (see @minecraft-server/CompoundBlockVolume for more details
This function can't be called in read-only mode.
Throws
This function can throw errors.
undo()
undo():
void
Returns
void
Remarks
Perform an undo operation. This will take the last transaction record on the stack and apply the stored world state from before the changes were made. This will reduce the record stack by one.
The transaction record affected by this operation will be transferred to the redo stack in case the creator decides to reapply it
This function can't be called in read-only mode.
Throws
This function can throw errors.
undoSize()
undoSize():
number
Returns
number
Remarks
Return how many transactions records currently exist on the stack
This function can't be called in read-only mode.
Throws
This function can throw errors.