Class CraftScriptContext

java.lang.Object
com.sk89q.worldedit.scripting.CraftScriptEnvironment
com.sk89q.worldedit.scripting.CraftScriptContext

public class CraftScriptContext extends CraftScriptEnvironment
The context given to scripts.
  • Constructor Details

  • Method Details

    • remember

      public EditSession remember()
      Get an edit session. Every subsequent call returns a new edit session. Usually you only need to use one edit session.
      Returns:
      an edit session
    • getPlayer

      public Player getPlayer()
      Get the player.
      Returns:
      the calling player
    • getSession

      public LocalSession getSession()
      Get the player's session.
      Returns:
      a session
    • getConfiguration

      public LocalConfiguration getConfiguration()
      Get the configuration for WorldEdit.
      Returns:
      the configuration
    • getEditSessions

      public List<EditSession> getEditSessions()
      Get a list of edit sessions that have been created.
      Returns:
      a list of created EditSessions
    • print

      public void print(String message)
      Print a regular message to the user.
      Parameters:
      message - a message
    • error

      public void error(String message)
      Print an error message to the user.
      Parameters:
      message - a message
    • printRaw

      public void printRaw(String message)
      Print a raw message to the user.
      Parameters:
      message - a message
    • checkArgs

      public void checkArgs(int min, int max, String usage) throws InsufficientArgumentsException
      Checks to make sure that there are enough but not too many arguments.
      Parameters:
      min - a number of arguments
      max - -1 for no maximum
      usage - usage string
      Throws:
      InsufficientArgumentsException - if the arguments are not "sufficiently" good
    • exit

      public void exit()
      Immediately terminate execution of the script, but without a failure message.
      Implementation Note:
      This exits by throwing an exception, which if caught will prevent the script from exiting
    • getBlock

      public BaseBlock getBlock(String input, boolean allAllowed) throws WorldEditException
      Get an item from an item name or an item ID number.
      Parameters:
      input - input to parse
      allAllowed - true to ignore blacklists
      Returns:
      a block
      Throws:
      NoMatchException - if no block was found
      DisallowedUsageException - if the block is disallowed
      WorldEditException
    • getBlock

      public BaseBlock getBlock(String id) throws WorldEditException
      Get a block.
      Parameters:
      id - the type Id
      Returns:
      a block
      Throws:
      NoMatchException - if no block was found
      DisallowedUsageException - if the block is disallowed
      WorldEditException
    • getBlockPattern

      public Pattern getBlockPattern(String list) throws WorldEditException
      Get a list of blocks as a set. This returns a Pattern.
      Parameters:
      list - the input
      Returns:
      pattern
      Throws:
      NoMatchException - if the pattern was invalid
      DisallowedUsageException - if the block is disallowed
      WorldEditException
    • getBlocks

      public Set<BaseBlock> getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException
      Get a list of blocks as a set.
      Parameters:
      list - a list
      allBlocksAllowed - true if all blocks are allowed
      Returns:
      set
      Throws:
      NoMatchException - if the blocks couldn't be found
      DisallowedUsageException - if the block is disallowed
      WorldEditException
    • getSafeOpenFile

      public File getSafeOpenFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException
      Gets the path to a file for opening. 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.

      Use this method if you need to read a file from a directory.

      Parameters:
      folder - sub-directory to look in
      filename - filename (user-submitted)
      defaultExt - default extension to append if there is none
      exts - list of extensions for file open dialog, null for no filter
      Returns:
      a file
      Throws:
      FilenameException - if there is a problem with the name of the file
    • getSafeSaveFile

      public File getSafeSaveFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException
      Gets the path to a file for saving. 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.

      Use this method if you need to read a file from a directory.

      Parameters:
      folder - sub-directory to look in
      filename - filename (user-submitted)
      defaultExt - default extension to append if there is none
      exts - list of extensions for file save dialog, null for no filter
      Returns:
      a file
      Throws:
      FilenameException - if there is a problem with the name of the file