Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
SBPrime edited this page Dec 31, 2016 · 4 revisions

On this page I'll provide information on the AsyncWorldEdit API.

Player management

The World's

The EditSessionFactory

The EditSession's

When you are using AsyncWorldEdit you have access to 5 (+1 special internal) types of EditSessions.

IEditSession

This simple interface exposes all features of EditSession using an interface.

EditSession

This is the default edit session provided by the WorlEdit plugin. It allows you to perform some basic world editing operations (mostly all the operations available from commands). In AsyncWorldEdit there are nothing special about it.

All operations from EditSession are not thread safe and need to be run from the server main thread. Therefore performing operations directly from this class you might lag the server.

In AsyncWorldEdit the EditSession this class implements the IEditSession

IAweEditSession

The first edit session provided by AsyncWorldEdit is used only to allow safe and easy creation of sub classes of EditSession. Its used only internally and should not be used externally.

The IAweEditSession has one additional feature, it allows you to perform a custom Change action.

public interface IAweEditSession extends IEditSession {
   void doCustomAction(Change change, boolean isDemanding) throws WorldEditException;
}

ICancelabeEditSession

This is the second edit session provided by the AsyncWorldEdit plugin. It has all the features that are available in EditSession. The ICancelableEditSession is used internally to process jobs and should not be created externally. Each of those is basically a wrapper around a IThreadSafeEditSession and delegates all the operations to the underlying edit session. Therefore all the operations available in this class are thread safe and can be done on any thread.

The ICancelableEditSession has one additional feature, it can by canceled. When this is done all block operations end in IllegalArgumentException() exception.

public interface ICancelabeEditSession extends IAweEditSession {
   void cancel();
   int getJobId();
   IThreadSafeEditSession getParent();
   IPlayerEntry getPlayer();
   boolean isCanceled();
   void resetAsync()
}

IThreadSafeEditSession

The next edit session added by AsyncWorldEdit it has all the features that are available in EditSession. The only difference between IThreadSafeEditSession and EditSession is that all operations from the first one are thread safe and can be done on any thread. You can obtain an instance of this interface using the IAsyncEditSessionFactory provided by AsyncWorldEdit.

The IThreadSafeEditSession provides job handling code and is also responsible for checking if async mode is on for a certain operation (either in the configuration) or its toggled off by the user. It also exposes some more advanced features that are mostly used internally.

public interface IThreadSafeEditSession extends IAweEditSession {
    void setAsyncForced(boolean value);
    boolean isAsyncForced();
    boolean checkAsync(String operationName);
    void resetAsync();
    void addAsync(IJobEntry job);
    void removeAsync(IJobEntry job);
    IBlockPlacer getBlockPlacer();
    EditSessionEvent getEditSessionEvent();
    EventBus getEventBus();
    Object getMutex();
    ChangeSet getRootChangeSet();
    IPlayerEntry getPlayer();
    IWorld getCBWorld();
    boolean setBlock(int jobId, Vector position, BaseBlock block, 
                     EditSession.Stage stage) 
                     throws WorldEditException;
    boolean setBlock(Vector pt, Pattern pat, int jobId) 
                     throws MaxChangedBlocksException;
    boolean setBlock(Vector pt, BaseBlock block, int jobId) 
                     throws MaxChangedBlocksException;
    boolean setBlockIfAir(Vector pt, BaseBlock block, int jobId) 
                     throws MaxChangedBlocksException;       
    Iterator<Change> doUndo();
    Iterator<Change> doRedo();
}

AsyncEditSession (internal)

When you create an EditSession using the IAsyncEditSessionFactory you will create a special EditSession. When you are using it all WorldEdit operations will be asynced. In addition to all the features provided by the IThreadSafeEditSession it automatically wraps all the operations into separate jobs (Note: Simple block set/get does not spawn a new job!). Therefore if you call any of the operations provided by this class from the server main thread its gonna be run on a async thread and won't lag the server.