private static void UndoHandler( Player player, Command cmd )
{
World playerWorld = player.World;
if ( playerWorld == null )
PlayerOpException.ThrowNoWorld( player );
if ( cmd.HasNext ) {
player.Message( "Undo command takes no parameters. Did you mean to do &H/UndoPlayer&S or &H/UndoArea&S?" );
return;
}
string msg = "Undo: ";
UndoState undoState = player.UndoPop();
if ( undoState == null ) {
player.MessageNow( "There is currently nothing to undo." );
return;
}
// Cancel the last DrawOp, if still in progress
if ( undoState.Op != null && !undoState.Op.IsDone && !undoState.Op.IsCancelled ) {
undoState.Op.Cancel();
msg += String.Format( "Cancelled {0} (was {1}% done). ",
undoState.Op.Description,
undoState.Op.PercentDone );
}
// Check if command was too massive.
if ( undoState.IsTooLargeToUndo ) {
if ( undoState.Op != null ) {
player.MessageNow( "Cannot undo {0}: too massive.", undoState.Op.Description );
} else {
player.MessageNow( "Cannot undo: too massive." );
}
return;
}
// no need to set player.drawingInProgress here because this is done on the user thread
Logger.Log( LogType.UserActivity,
"Player {0} initiated /Undo affecting {1} blocks (on world {2})",
player.Name,
undoState.Buffer.Count,
playerWorld.Name );
msg += String.Format( "Restoring {0} blocks. Type &H/Redo&S to reverse.",
undoState.Buffer.Count );
player.MessageNow( msg );
var op = new UndoDrawOperation( player, undoState, false );
op.Prepare( new Vector3I[0] );
op.Begin();
}