Package com.sk89q.worldedit
Class WorldEdit
java.lang.Object
com.sk89q.worldedit.WorldEdit
The entry point and container for a working implementation of WorldEdit.
An instance handles event handling; block, mask, pattern, etc. registration;
the management of sessions; the creation of EditSession
s; and more.
In order to use WorldEdit, at least one Platform
must be registered
with WorldEdit using PlatformManager.register(Platform)
on the
manager retrieved using getPlatformManager()
.
An instance of WorldEdit can be retrieved using the static
method getInstance()
, which is shared among all
platforms within the same classloader hierarchy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.logging.log4j.Logger
This is for internal use only. -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkMaxBrushRadius
(double radius) Checks to see if the specified brush radius is within bounds.void
checkMaxRadius
(double radius) Checks to see if the specified radius is within bounds.void
flushBlockBag
(Actor actor, EditSession editSession) Flush a block bag's changes to a player.Return the asset loaders instance.Get the block factory from which newBlockStateHolder
s can be constructed.Get Worldedit's configuration.getDiagonalDirection
(Player player, String dirStr) Get the direction vector for a player's direction.getDirection
(Player player, String dirStr) Get the direction vector for a player's direction.Deprecated.Get the event bus for WorldEdit.com.google.common.util.concurrent.ListeningExecutorService
Get the executor service.static WorldEdit
Gets the current instance of this class.Get the item factory from which newBaseItem
s can be constructed.Get the mask factory from which newMask
s can be constructed.Get the pattern factory from which newPattern
s can be constructed.Get the platform manager, where platforms (that implement WorldEdit) can be registered and information about registered platforms can be queried.Gets the path to a file.Gets the path to a file.Return the session manager.Get the supervisor.Return the translation manager.static String
Get the version.Deprecated.UsegetWorkingDirectoryPath(String)
insteadGet a file relative to the defined working directory.boolean
handleArmSwing
(Player player) Called on arm swing.boolean
handleBlockLeftClick
(Player player, Location clicked) Deprecated.boolean
handleBlockLeftClick
(Player player, Location clicked, Direction face) Called on left click.boolean
handleBlockRightClick
(Player player, Location clicked) Deprecated.boolean
handleBlockRightClick
(Player player, Location clicked, Direction face) Called on right click.boolean
handleRightClick
(Player player) Called on right click (not on a block).void
Load the bundled mappings.<A extends Actor & Locatable>
EditSessionnewEditSession
(A locatableActor) Shorthand fornewEditSessionBuilder().locatableActor(locatableActor).build()
.newEditSession
(World world) Shorthand fornewEditSessionBuilder().world(world).build()
.Create a builder forEditSession
s.void
Executes a WorldEdit script.
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger loggerThis is for internal use only.
-
-
Method Details
-
getInstance
Gets the current instance of this class.An instance will always be available, but no platform may yet be registered with WorldEdit, meaning that a number of operations may fail. However, event handlers can be registered.
- Returns:
- an instance of WorldEdit.
-
getPlatformManager
Get the platform manager, where platforms (that implement WorldEdit) can be registered and information about registered platforms can be queried.- Returns:
- the platform manager
-
getEventBus
Get the event bus for WorldEdit.Event handlers can be registered on the event bus.
- Returns:
- the event bus
-
getSupervisor
Get the supervisor. Internal, not for API use.- Returns:
- the supervisor
-
getExecutorService
public com.google.common.util.concurrent.ListeningExecutorService getExecutorService()Get the executor service. Internal, not for API use.- Returns:
- the executor service
-
getBlockFactory
Get the block factory from which newBlockStateHolder
s can be constructed.- Returns:
- the block factory
-
getItemFactory
Get the item factory from which newBaseItem
s can be constructed.- Returns:
- the item factory
-
getMaskFactory
Get the mask factory from which newMask
s can be constructed.- Returns:
- the mask factory
-
getPatternFactory
Get the pattern factory from which newPattern
s can be constructed.- Returns:
- the pattern factory
-
getSessionManager
Return the session manager.- Returns:
- the session manager
-
getTranslationManager
Return the translation manager.- Returns:
- the translation manager
-
getAssetLoaders
Return the asset loaders instance.- Returns:
- the asset loaders instance
-
getSafeSaveFile
public File getSafeSaveFile(Actor actor, File dir, String filename, String defaultExt, String... extensions) throws FilenameException Gets the path to a file. This method will check to see if the filename has valid characters and has an extension. It also prevents directory traversal exploits by checking the root directory and the file directory. On success, ajava.io.File
object will be returned.- Parameters:
actor
- the actordir
- sub-directory to look infilename
- filename (user-submitted)defaultExt
- append an extension if missing one, null to not useextensions
- list of extensions, null for any- Returns:
- a file
- Throws:
FilenameException
- thrown if the filename is invalid
-
getSafeOpenFile
public File getSafeOpenFile(Actor actor, File dir, String filename, String defaultExt, String... extensions) throws FilenameException Gets the path to a file. This method will check to see if the filename has valid characters and has an extension. It also prevents directory traversal exploits by checking the root directory and the file directory. On success, ajava.io.File
object will be returned.- Parameters:
actor
- the actordir
- sub-directory to look infilename
- filename (user-submitted)defaultExt
- append an extension if missing one, null to not useextensions
- list of extensions, null for any- Returns:
- a file
- Throws:
FilenameException
- thrown if the filename is invalid
-
loadMappings
public void loadMappings()Load the bundled mappings. -
checkMaxRadius
Checks to see if the specified radius is within bounds.- Parameters:
radius
- the radius- Throws:
MaxRadiusException
- if the radius is bigger than the configured radius
-
checkMaxBrushRadius
Checks to see if the specified brush radius is within bounds.- Parameters:
radius
- the radius- Throws:
MaxBrushRadiusException
- if the radius is bigger than the configured radius
-
getWorkingDirectoryFile
Deprecated.UsegetWorkingDirectoryPath(String)
insteadGet a file relative to the defined working directory. If the specified path is absolute, then the working directory is not used.- Parameters:
path
- the subpath under the working directory- Returns:
- a working directory
-
getWorkingDirectoryPath
Get a file relative to the defined working directory. If the specified path is absolute, then the working directory is not used.- Parameters:
path
- the subpath under the working directory- Returns:
- a working directory
-
getDirection
public BlockVector3 getDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException Get the direction vector for a player's direction.- Parameters:
player
- the playerdirStr
- the direction string- Returns:
- a direction vector
- Throws:
UnknownDirectionException
- thrown if the direction is not known, or a relative direction is used with null player
-
getDiagonalDirection
public BlockVector3 getDiagonalDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException Get the direction vector for a player's direction.- Parameters:
player
- the playerdirStr
- the direction string- Returns:
- a direction vector
- Throws:
UnknownDirectionException
- thrown if the direction is not known, or a relative direction is used with null player
-
flushBlockBag
Flush a block bag's changes to a player.- Parameters:
actor
- the actoreditSession
- the edit session
-
handleArmSwing
Called on arm swing.- Parameters:
player
- the player- Returns:
- true if the swing was handled
-
handleRightClick
Called on right click (not on a block).- Parameters:
player
- the player- Returns:
- true if the right click was handled
-
handleBlockRightClick
Deprecated.Called on right click.- Parameters:
player
- the playerclicked
- the clicked block- Returns:
- false if you want the action to go through
-
handleBlockRightClick
Called on right click.- Parameters:
player
- the playerclicked
- the clicked blockface
- The clicked face- Returns:
- false if you want the action to go through
-
handleBlockLeftClick
Deprecated.Called on left click.- Parameters:
player
- the playerclicked
- the clicked block- Returns:
- false if you want the action to go through
-
handleBlockLeftClick
Called on left click.- Parameters:
player
- the playerclicked
- the clicked blockface
- The clicked face- Returns:
- false if you want the action to go through
-
runScript
Executes a WorldEdit script.- Parameters:
player
- the playerf
- the script file to executeargs
- arguments for the script- Throws:
WorldEditException
- if something goes wrong
-
getConfiguration
Get Worldedit's configuration.- Returns:
- a configuration
-
getEditSessionFactory
Deprecated.UsenewEditSessionBuilder()
instead. SeeEditSessionFactory
for details.Get a factory forEditSession
s. -
newEditSessionBuilder
Create a builder forEditSession
s. -
newEditSession
Shorthand fornewEditSessionBuilder().world(world).build()
.- Parameters:
world
- the world- Returns:
- the new
EditSession
-
newEditSession
Shorthand fornewEditSessionBuilder().locatableActor(locatableActor).build()
.- Parameters:
locatableActor
- the actor- Returns:
- the new
EditSession
-
getVersion
Get the version.- Returns:
- the version of WorldEdit
-
newEditSessionBuilder()
instead.