Package com.sk89q.worldedit.event.extent
Class EditSessionEvent
java.lang.Object
com.sk89q.worldedit.event.Event
com.sk89q.worldedit.event.extent.EditSessionEvent
- All Implemented Interfaces:
Cancellable
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 Extent
s 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 Summary
ConstructorDescriptionEditSessionEvent
(World world, Actor actor, int maxBlocks, EditSession.Stage stage) Create a new event. -
Method Summary
Modifier and TypeMethodDescriptionclone
(EditSession.Stage stage) Create a clone of this event with the given stage.getActor()
Get the actor for this event.Get theExtent
that can be wrapped.int
Get the maximum number of blocks that may be set.getStage()
Get the stage that is being wrapped.Get the current list of tracing extents.getWorld()
Get the world.boolean
Returns whether the event has been cancelled.void
setCancelled
(boolean cancelled) Set whether the event has been cancelled.void
Set a new extent that should be used.void
setTracing
(boolean tracing) Set tracing enabled, with the current extent as the "base".
-
Constructor Details
-
EditSessionEvent
Create a new event.- Parameters:
world
- the worldactor
- the actor, or null if there is no actor specifiedmaxBlocks
- the maximum number of block changesstage
- the stage
-
-
Method Details
-
getActor
Get the actor for this event.- Returns:
- the actor, which may be null if unavailable
-
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
Get theExtent
that can be wrapped.- Returns:
- the extent
-
getStage
Get the stage that is being wrapped.- Returns:
- the stage
-
setExtent
Set a new extent that should be used. It should wrap the extent returned fromgetExtent()
.- 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
Get the current list of tracing extents. Internal use only. -
clone
Create a clone of this event with the given stage.- Parameters:
stage
- the stage- Returns:
- a new event
-
isCancelled
public boolean isCancelled()Description copied from interface:Cancellable
Returns whether the event has been cancelled.- Specified by:
isCancelled
in interfaceCancellable
- Returns:
- true if cancelled
-
setCancelled
public void setCancelled(boolean cancelled) Description copied from interface:Cancellable
Set whether the event has been cancelled.- Specified by:
setCancelled
in interfaceCancellable
- Parameters:
cancelled
- true if cancelled
-