Class EditSessionEvent

java.lang.Object
com.sk89q.worldedit.event.Event
com.sk89q.worldedit.event.extent.EditSessionEvent

public class EditSessionEvent extends Event
Raised (several times) when a new EditSession is being instantiated.

Block loggers, as well as block set interceptors, can use this event to wrap the given Extent with their own, which would allow them to intercept all changes made to the world. For example, the code below would wrap the existing extent with a custom one, and the custom extent would receive all method calls before the extent fetched from getExtent() would.

 event.setExtent(new MyExtent(event.getExtent())
 

This event is fired several times during the creation of a single EditSession, but getStage() will differ each time. The stage determines at which point Extents added to this event will be called. For example, if you inject an extent when the stage is set to EditSession.Stage.BEFORE_HISTORY, then you can drop (or log) changes before the change has reached the history, reordering, and actual change extents, but that means that any changes made with EditSession.rawSetBlock(BlockVector3, BlockStateHolder) will skip your custom Extent because that method bypasses history (and reorder). It is thus recommended that loggers intercept at EditSession.Stage.BEFORE_CHANGE and block interceptors intercept at BOTH EditSession.Stage.BEFORE_CHANGE and EditSession.Stage.BEFORE_HISTORY.

  • Constructor Details

    • EditSessionEvent

      public EditSessionEvent(@Nullable World world, Actor actor, int maxBlocks, EditSession.Stage stage)
      Create a new event.
      Parameters:
      world - the world
      actor - the actor, or null if there is no actor specified
      maxBlocks - the maximum number of block changes
      stage - the stage
  • Method Details

    • getActor

      @Nullable public Actor getActor()
      Get the actor for this event.
      Returns:
      the actor, which may be null if unavailable
    • getWorld

      @Nullable public World getWorld()
      Get the world.
      Returns:
      the world
    • getMaxBlocks

      public int getMaxBlocks()
      Get the maximum number of blocks that may be set.
      Returns:
      the maximum number of blocks, which is -1 if unlimited
    • getExtent

      public Extent getExtent()
      Get the Extent that can be wrapped.
      Returns:
      the extent
    • getStage

      public EditSession.Stage getStage()
      Get the stage that is being wrapped.
      Returns:
      the stage
    • setExtent

      public void setExtent(Extent extent)
      Set a new extent that should be used. It should wrap the extent returned from getExtent().
      Parameters:
      extent - the extent
    • setTracing

      public void setTracing(boolean tracing)
      Set tracing enabled, with the current extent as the "base". Internal use only.
      Parameters:
      tracing - if tracing is enabled
    • getTracingExtents

      public List<TracingExtent> getTracingExtents()
      Get the current list of tracing extents. Internal use only.
    • clone

      public EditSessionEvent clone(EditSession.Stage stage)
      Create a clone of this event with the given stage.
      Parameters:
      stage - the stage
      Returns:
      a new event