Package com.sk89q.worldedit.scripting
Class CraftScriptContext
java.lang.Object
com.sk89q.worldedit.scripting.CraftScriptEnvironment
com.sk89q.worldedit.scripting.CraftScriptContext
The context given to scripts.
-
Field Summary
Fields inherited from class com.sk89q.worldedit.scripting.CraftScriptEnvironment
config, controller, player, server, session
-
Constructor Summary
ConstructorDescriptionCraftScriptContext
(WorldEdit controller, Platform server, LocalConfiguration config, LocalSession session, Player player, String[] args) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks to make sure that there are enough but not too many arguments.void
Print an error message to the user.void
exit()
Immediately terminate execution of the script, but without a failure message.Get a block.Get an item from an item name or an item ID number.getBlockPattern
(String list) Get a list of blocks as a set.Get a list of blocks as a set.Get the configuration for WorldEdit.Get a list of edit sessions that have been created.Get the player.getSafeOpenFile
(String folder, String filename, String defaultExt, String... exts) Gets the path to a file for opening.getSafeSaveFile
(String folder, String filename, String defaultExt, String... exts) Gets the path to a file for saving.Get the player's session.void
Print a regular message to the user.void
Print a raw message to the user.remember()
Get an edit session.
-
Constructor Details
-
CraftScriptContext
public CraftScriptContext(WorldEdit controller, Platform server, LocalConfiguration config, LocalSession session, Player player, String[] args)
-
-
Method Details
-
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
Get the player.- Returns:
- the calling player
-
getSession
Get the player's session.- Returns:
- a session
-
getConfiguration
Get the configuration for WorldEdit.- Returns:
- the configuration
-
getEditSessions
Get a list of edit sessions that have been created.- Returns:
- a list of created
EditSession
s
-
print
Print a regular message to the user.- Parameters:
message
- a message
-
error
Print an error message to the user.- Parameters:
message
- a message
-
printRaw
Print a raw message to the user.- Parameters:
message
- a message
-
checkArgs
Checks to make sure that there are enough but not too many arguments.- Parameters:
min
- a number of argumentsmax
- -1 for no maximumusage
- 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.This exits by throwing an exception, which if caught will prevent the script from exiting
-
getBlock
Get an item from an item name or an item ID number.- Parameters:
input
- input to parseallAllowed
- true to ignore blacklists- Returns:
- a block
- Throws:
NoMatchException
- if no block was foundDisallowedUsageException
- if the block is disallowedWorldEditException
-
getBlock
Get a block.- Parameters:
id
- the type Id- Returns:
- a block
- Throws:
NoMatchException
- if no block was foundDisallowedUsageException
- if the block is disallowedWorldEditException
-
getBlockPattern
Get a list of blocks as a set. This returns a Pattern.- Parameters:
list
- the input- Returns:
- pattern
- Throws:
NoMatchException
- if the pattern was invalidDisallowedUsageException
- if the block is disallowedWorldEditException
-
getBlocks
Get a list of blocks as a set.- Parameters:
list
- a listallBlocksAllowed
- true if all blocks are allowed- Returns:
- set
- Throws:
NoMatchException
- if the blocks couldn't be foundDisallowedUsageException
- if the block is disallowedWorldEditException
-
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, ajava.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 infilename
- filename (user-submitted)defaultExt
- default extension to append if there is noneexts
- 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, ajava.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 infilename
- filename (user-submitted)defaultExt
- default extension to append if there is noneexts
- 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
-