It is currently January 18th, 2018, 5:53 pm


All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: invoking "UndoPlayer"
PostPosted: September 19th, 2012, 2:09 am 
User avatar

Joined: May 28th, 2012, 12:03 am
Posts: 25
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"

_________________
=== MeinKraft 24/7 ===
Server Owner & Code Developer


Top
Offline Profile  
Reply with quote  
 Post subject: Re: invoking "UndoPlayer"
PostPosted: September 19th, 2012, 2:31 am 
fCraft Developer
User avatar

Joined: May 21st, 2011, 10:53 pm
Posts: 1386
Well, I suggest taking a look at the source code of /UndoPlayer command ;)

Basically, what you want to do is:
  1. Get your World and target's PlayerInfo objects ready.
  2. Use one of the world.BlockDB.Lookup overloads to get a list of changes to undo.
  3. If any changes were found, launch a BlockDBDrawOperation with the given parameters, to apply the changes to the world.

Here is the most basic way of doing it:
Code:
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();
    }
}


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.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net