5 WorldEdit EditSession
Alw3ys edited this page 2017-03-16 16:55:04 +01:00

The EditSession is used by WorldEdit to make and record changes to the World. The EditSessionBuilder gives you full control over it.

  • A world must be provided, see FaweAPI.getWorld(...)

Example:

EditSession editSession = new EditSessionBuilder(world).fastmode(true).build();

Unset values will revert to their default:

  • player: The player doing the edit (defaults to to null)
  • limit: Block/Entity/Action limit (defaults to player limit or unlimited)
  • changeSet: Stores changes (defaults to config.yml value)
  • allowedRegions: Allowed editable regions (defaults to player's allowed regions, or everywhere)
  • autoQueue: Changes can occur before flushQueue() (defaults true)
  • fastmode: bypasses history (defaults to player fastmode or config.yml console history)
  • checkMemory: If low memory checks are enabled (defaults to player's fastmode or true)
  • combineStages: If history is combined with dispatching (defaults to config value)
  • blockBag: The blockbag to use (defaults to null)
  • eventBus: The eventBus to use (defaults to null)
  • event: The event to call (defaults to null)

See: https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java

Here's a non FAWE example:

// If no player is doing the changes
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(worldEditWorld, -1);
// For a specific player
editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(worldEditWorld, -1, actor);

// Do stuff with the EditSession
editSession.setBlock(new Vector(x, y, z), new BaseBlock(id, data));
// All changes will have been made once flushQueue is called
editSession.flushQueue();

Here's a FAWE example:

EditSession editSession = new EditSessionBuilder(world).fastmode(true).build();
editSession.setBlock(new Vector(x, y, z), new BaseBlock(id, data));
editSession.flushQueue();

Undoing an EditSession

Where editSession is what you are undoing.

// Create a new EditSession however you want
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(editSession.getWorld(), -1, null, null);
// Undo it
editSession.undo(newEditSession);
editSession.flushQueue();