Class WorldEdit

java.lang.Object
com.sk89q.worldedit.WorldEdit

public final class WorldEdit extends Object
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 EditSessions; 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 Details

    • logger

      public static final org.apache.logging.log4j.Logger logger
      This is for internal use only.
  • Method Details

    • getInstance

      public static WorldEdit 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

      public PlatformManager 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

      public EventBus getEventBus()
      Get the event bus for WorldEdit.

      Event handlers can be registered on the event bus.

      Returns:
      the event bus
    • getSupervisor

      public Supervisor 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

      public BlockFactory getBlockFactory()
      Get the block factory from which new BlockStateHolders can be constructed.
      Returns:
      the block factory
    • getItemFactory

      public ItemFactory getItemFactory()
      Get the item factory from which new BaseItems can be constructed.
      Returns:
      the item factory
    • getMaskFactory

      public MaskFactory getMaskFactory()
      Get the mask factory from which new Masks can be constructed.
      Returns:
      the mask factory
    • getPatternFactory

      public PatternFactory getPatternFactory()
      Get the pattern factory from which new Patterns can be constructed.
      Returns:
      the pattern factory
    • getSessionManager

      public SessionManager getSessionManager()
      Return the session manager.
      Returns:
      the session manager
    • getTranslationManager

      public TranslationManager getTranslationManager()
      Return the translation manager.
      Returns:
      the translation manager
    • getAssetLoaders

      public AssetLoaders 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, a java.io.File object will be returned.
      Parameters:
      actor - the actor
      dir - sub-directory to look in
      filename - filename (user-submitted)
      defaultExt - append an extension if missing one, null to not use
      extensions - 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, a java.io.File object will be returned.
      Parameters:
      actor - the actor
      dir - sub-directory to look in
      filename - filename (user-submitted)
      defaultExt - append an extension if missing one, null to not use
      extensions - 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

      public void checkMaxRadius(double radius) throws MaxRadiusException
      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

      public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException
      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 public File getWorkingDirectoryFile(String path)
      Deprecated.
      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
    • getWorkingDirectoryPath

      public Path getWorkingDirectoryPath(String path)
      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 player
      dirStr - 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 player
      dirStr - 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

      public void flushBlockBag(Actor actor, EditSession editSession)
      Flush a block bag's changes to a player.
      Parameters:
      actor - the actor
      editSession - the edit session
    • handleArmSwing

      public boolean handleArmSwing(Player player)
      Called on arm swing.
      Parameters:
      player - the player
      Returns:
      true if the swing was handled
    • handleRightClick

      public boolean handleRightClick(Player player)
      Called on right click (not on a block).
      Parameters:
      player - the player
      Returns:
      true if the right click was handled
    • handleBlockRightClick

      @Deprecated public boolean handleBlockRightClick(Player player, Location clicked)
      Deprecated.
      Called on right click.
      Parameters:
      player - the player
      clicked - the clicked block
      Returns:
      false if you want the action to go through
    • handleBlockRightClick

      public boolean handleBlockRightClick(Player player, Location clicked, @Nullable Direction face)
      Called on right click.
      Parameters:
      player - the player
      clicked - the clicked block
      face - The clicked face
      Returns:
      false if you want the action to go through
    • handleBlockLeftClick

      @Deprecated public boolean handleBlockLeftClick(Player player, Location clicked)
      Deprecated.
      Called on left click.
      Parameters:
      player - the player
      clicked - the clicked block
      Returns:
      false if you want the action to go through
    • handleBlockLeftClick

      public boolean handleBlockLeftClick(Player player, Location clicked, @Nullable Direction face)
      Called on left click.
      Parameters:
      player - the player
      clicked - the clicked block
      face - The clicked face
      Returns:
      false if you want the action to go through
    • runScript

      public void runScript(Player player, File f, String[] args) throws WorldEditException
      Executes a WorldEdit script.
      Parameters:
      player - the player
      f - the script file to execute
      args - arguments for the script
      Throws:
      WorldEditException - if something goes wrong
    • getConfiguration

      public LocalConfiguration getConfiguration()
      Get Worldedit's configuration.
      Returns:
      a configuration
    • getEditSessionFactory

      @Deprecated public EditSessionFactory getEditSessionFactory()
      Deprecated.
      Use newEditSessionBuilder() instead. See EditSessionFactory for details.
      Get a factory for EditSessions.
    • newEditSessionBuilder

      public EditSessionBuilder newEditSessionBuilder()
      Create a builder for EditSessions.
    • newEditSession

      public EditSession newEditSession(@Nullable World world)
      Shorthand for newEditSessionBuilder().world(world).build().
      Parameters:
      world - the world
      Returns:
      the new EditSession
    • newEditSession

      public <A extends Actor & Locatable> EditSession newEditSession(A locatableActor)
      Shorthand for newEditSessionBuilder().locatableActor(locatableActor).build().
      Parameters:
      locatableActor - the actor
      Returns:
      the new EditSession
    • getVersion

      public static String getVersion()
      Get the version.
      Returns:
      the version of WorldEdit