Hi. is there a quick way can force an undo player, all in one action, without having to type "/ok"
my idea is a ban and undo command... but I can't undo!
I'm after the equivilent of: "/UndoPlayer <target> 5h"
invoking "UndoPlayer"
- OfficerFlake
- Offline
- Posts: 25
- Joined: May 28th, 2012, 12:03 am
invoking "UndoPlayer"
=== MeinKraft 24/7 ===
Server Owner & Code Developer
Server Owner & Code Developer
Re: invoking "UndoPlayer"
Well, I suggest taking a look at the source code of /UndoPlayer command
Basically, what you want to do is:
Note that DrawOperations require a player to take "ownership" of it. That's done to allow permission-checks for block placement, logging, ability to /Undo, etc. That's where the first parameter of the above method (Player player) comes in.
Also you might want to invoke this method on a background thread (Scheduler.NewBackgroundTask) to avoid lagging up the player. BlockDB.Lookup() might take a while to finish, depending on database size.
Basically, what you want to do is:
- Get your World and target's PlayerInfo objects ready.
- Use one of the world.BlockDB.Lookup overloads to get a list of changes to undo.
- If any changes were found, launch a BlockDBDrawOperation with the given parameters, to apply the changes to the world.
Code: Select all
static void UndoPlayer( Player player, PlayerInfo target, World world, TimeSpan timespan ){
BlockDBEntry[] changes = world.BlockDB.Lookup( Int32.MaxValue, target, false, timespan );
if( changes.Length > 0 ){
BlockDBDrawOperation op = new BlockDBDrawOperation( player, "UndoPlayer", "", 0 );
op.Prepare( new Vector3I[0], changes );
op.Begin();
}
}
Also you might want to invoke this method on a background thread (Scheduler.NewBackgroundTask) to avoid lagging up the player. BlockDB.Lookup() might take a while to finish, depending on database size.