-
Notifications
You must be signed in to change notification settings - Fork 85
API
On this page I'll provide information on the AsyncWorldEdit API.
When you are using AsyncWorldEdit you have access to 5 types of EditSessions.
This is the default edit session provided by the WorlEdit plugin. It allows you to perform some basic world editing operations (mostly all the commands 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.
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.
This is the second edit session provided by the AsyncWorldEdit plugin. It has all the features that are available in EditSession. The CancelableEditSession is used internally to process jobs and should not be created externally. Each of those is basically a wrapper around a ThreadSafeEditSession 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 CancelableEditSession has one additional feature, it can by canceled. When this is done all block operations end in IllegalArgumentException(SessionCanceled()) exception.
public class CancelabeEditSession extends EditSessionStub {
public CancelabeEditSession(ThreadSafeEditSession parent, Mask mask, int jobId);
public boolean isCanceled();
public void cancel();
}
The next edit session added by AsyncWorldEdit has all the features that are available in EditSession. The only difference between ThreadSafeEditSession 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 class using the AsyncEditSessionFactory provided by AsyncWorldEdit.
The ThreadSafeEditSession 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. Those functions are used mostly by AsyncEditSession and should not be used externally.
public class ThreadSafeEditSession extends EditSessionStub {
public ThreadSafeEditSession(AsyncWorldEditMain plugin,
PlayerEntry player, EventBus eventBus, World world,
int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event);
public void setAsyncForced(boolean value);
public boolean isAsyncForced();
public boolean checkAsync(String operationName);
public boolean checkAsync(WorldeditOperations operation);
public void resetAsync();
public void addAsync(JobEntry job);
public void removeAsync(JobEntry job);
}
The last edit session provided by AsyncWorldEdit is the most important one. It is used to async all the WorldEdit operations. In addition to all the features provided by the ThreadSafeEditSession 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.
public class AsyncEditSession extends ThreadSafeEditSession {
public AsyncEditSession(AsyncWorldEditMain plugin,
PlayerEntry player, EventBus eventBus, World world,
int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event);
}