You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
- ArrayHandling
- BasicLogic
- BossBar
- BukkitMetadata
- ByteArrays
- Clipboard
- Cmdline
- Commands
- Compiler
- ControlFlow
- Crypto
- DataHandling
- DataTransformations
- Debug
- Easings
- Echoes
- Enchantments
- EntityManagement
- Environment
- EventBinding
- Exceptions
- ExecutionQueue
- ExtensionMeta
- FileHandling
- InventoryManagement
- ItemMeta
- Marquee
- Math
- Meta
- Minecraft
- MobManagement
- OAuth
- OS
- ObjectManagement
- Performance
- Permissions
- Persistence
- PlayerManagement
- PluginMeta
- Recipes
- Reflection
- Regex
- ResourceManager
- SQL
- Sandbox
- Scheduling
- Scoreboards
- Statistics
- StringHandling
- TaskHandling
- Threading
- Trades
- Weather
- Web
- World
- XGUI
This class contains functions that provide a way to manipulate arrays. To create an array, use the
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/array_clear|array_clear]]()
| void
| array
| {{object|CastException}}
| Clears the array of all values. This keeps the array reference the same, but empties it. Both normal and associative arrays are supported, but the internal type (normal or associative) is not reset.array
function. For more detailed information on array usage, see the page on [[Arrays|arrays]]([[API/functions/array_clear#Examples|Examples...]]) | No |- | [[API/functions/array_contains|array_contains]]() | boolean | array, testValue | {{object|CastException}} | Checks to see if testValue is in array. For associative arrays, only the values are searched, the keys are ignored. If you need to check for the existence of a particular key, use array_index_exists().
([[API/functions/array_contains#Examples|Examples...]]) | No |- | [[API/functions/array_contains_ic|array_contains_ic]]() | boolean | array, testValue | {{object|CastException}} | Works like array_contains, except the comparison ignores case.
([[API/functions/array_contains_ic#Examples|Examples...]]) | No |- | [[API/functions/array_deep_clone|array_deep_clone]]() | array | array | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Performs a deep clone on an array (as opposed to a shallow clone). This is useful for multidimensional arrays. See the examples for more info.
([[API/functions/array_deep_clone#Examples|Examples...]]) | No |- | [[API/functions/array_every|array_every]]() | boolean | array, closure | {{object|CastException}} | Returns true if every value in the array meets some test, which the closure should return true or false about. Not all values will necessarily be checked, once a value is determined to fail the check, execution is stopped, and false is returned. The closure will be passed each value in the array, one at a time, and must return a boolean.
([[API/functions/array_every#Examples|Examples...]]) | No |- | [[API/functions/array_fill|array_fill]]() | array | array, fill | {{object|CastException}} | Fills the array fully with the given item. This works with both dynamic and fixed arrays, however with dynamic arrays, it must be a normal array, if the array is associative, a cast exception is thrown. This fills the entire array. The change is made in place, but a reference to the array is returned for easy chaining. | No |- | [[API/functions/array_filter|array_filter]]() | array | array, boolean closure(key, value) | {{object|CastException}} | Filters an array by callback. The items in the array are iterated over, each one sent to the closure one at a time, as key, value. The closure should return true if the item should be included in the array, or false if not. The filtered array is then returned by the function. If the array is associative, the keys will continue to map to the same values, however a normal array, the values are simply pushed onto the new array, and won't correspond to the same values per se.
([[API/functions/array_filter#Examples|Examples...]]) | No |- | [[API/functions/array_get|array_get]]() | mixed | array, index, [default] | {{object|CastException}}
{{object|IndexOverflowException}} | Returns the element specified at the index of the array. If the element doesn't exist, an exception is thrown. [[API/functions/array_get|See more...]]
([[API/functions/array_get#Examples|Examples...]]) | No |- | [[API/functions/array_get_rand|array_get_rand]]() | mixed | array | {{object|CastException}}
{{object|LengthException}} | Returns a random value from an array. If the array is empty a LengthException is thrown.
([[API/functions/array_get_rand#Examples|Examples...]]) | No |- | [[API/functions/array_implode|array_implode]]() | string | array, [glue] | {{object|CastException}} | Given an array and glue, to-strings all the elements in the array (just the values, not the keys), and joins them with the glue, defaulting to a space. For instance array_implode(array(1, 2, 3), '-') will return "1-2-3".
([[API/functions/array_implode#Examples|Examples...]]) | No |- | [[API/functions/array_index|array_index]]() | mixed | array, value | {{object|CastException}} | Works exactly like array_indexes(array, value)[0], except in the case where the value is not found, returns null. That is to say, if the value is contained in an array (even multiple times) the index of the first element is returned.
([[API/functions/array_index#Examples|Examples...]]) | No |- | [[API/functions/array_index_exists|array_index_exists]]() | boolean | array, index... | {{object|CastException}} | Checks to see if the specified array has an element at index. If more than one index is specified, then it recursively checks down nested arrays.
([[API/functions/array_index_exists#Examples|Examples...]]) | No |- | [[API/functions/array_indexes|array_indexes]]() | array | array, value | {{object|CastException}} | Returns an array with all the keys of the specified array at which the specified value is equal. That is, for the array(1, 2, 2, 3), if value were 2, would return array(1, 2). If the value cannot be found in the array at all, an empty array will be returned.
([[API/functions/array_indexes#Examples|Examples...]]) | No |- | [[API/functions/array_insert|array_insert]]() | void | array, item, index | {{object|CastException}}
{{object|IndexOverflowException}} | Inserts an item at the specified index, and shifts all other items in the array to the right one. If index is greater than the size of the array, an IndexOverflowException is thrown, though the index may be equal to the size, in which case this works just like array_push(). The array must be normal though; associative arrays are not supported.
([[API/functions/array_insert#Examples|Examples...]]) | No |- | [[API/functions/array_intersect|array_intersect]]() | array | array1, array2, [comparisonMode]
array1, array2, comparisonClosure | {{object|CastException}}
{{object|IllegalArgumentException}} | Returns an array that is the intersection of the two provided arrays. If either array is associative, it puts the function in associative mode. For normal arrays, the values are compared, and for associative arrays, the keys are compared, but the values are taken from the left array. comparisonMode is only applicable for normal arrays, and defaults to HASH, but determines the mode in which the system decides if two values are equal or not. A closure may be sent instead, which should return true if the two values are considered equals or not. Using the HASH mode is fastest, as this puts the function in an optimizing mode, and it can run at O(n log n). Otherwise, the runtime is O(n**2). The results between HASH and STRICT_EQUALS should almost never be different, and so in that case using STRICT_EQUALS has a lower performance for no gain, but there may be some cases where using the hash code is not desirable. EQUALS is necessary if you wish to disregard typing, so that array(1, 2, 3) and array('1', '2', '3') are considered equal. Duplicate values in the left array are duplicated, but duplicates in the right are not.
([[API/functions/array_intersect#Examples|Examples...]]) | No |- | [[API/functions/array_iterate|array_iterate]]() | array | array, closure | {{object|CastException}} | Iterates across an array, calling the closure for each value of the array. The closure should accept two arguments, the key and the value. This method can be used in some code to increase readability, to increase re-usability, or keep variables created in a loop in an isolated scope. Note that this runs at approximately the same speed as a for loop, which is probably slower than a foreach loop. Any values returned from the closure are silently ignored. Returns a reference to the original array.
([[API/functions/array_iterate#Examples|Examples...]]) | No |- | [[API/functions/array_keys|array_keys]]() | array | array | {{object|CastException}} | Returns the keys in this array as a normal array. If the array passed in is already a normal array, the keys will be 0 -> (array_size(array) - 1)
([[API/functions/array_keys#Examples|Examples...]]) | No |- | [[API/functions/array_last_index|array_last_index]]() | mixed | array, value | {{object|CastException}} | Finds the index in the array where value occurs last. If the value is not found, returns null. That is to say, if the value is contained in an array (even multiple times) the index of the last element is returned.
([[API/functions/array_last_index#Examples|Examples...]]) | No |- | [[API/functions/array_map|array_map]]() | array | array, closure | {{object|CastException}}
{{object|IllegalArgumentException}} | Calls the closure on each element of an array, and returns an array that contains the results.
([[API/functions/array_map#Examples|Examples...]]) | No |- | [[API/functions/array_merge|array_merge]]() | array | array1, array2, [arrayN...] | {{object|InsufficientArgumentsException}}
{{object|CastException}} | Merges the specified arrays from left to right, and returns a new array. If the array merged is associative, it will overwrite the keys from left to right, but if the arrays are normal, the keys are ignored, and values are simply pushed.
([[API/functions/array_merge#Examples|Examples...]]) | No |- | [[API/functions/array_normalize|array_normalize]]() | array | array | {{object|CastException}} | Returns a new normal array, given an associative array. (If the array passed in is not associative, a copy of the array is returned).
([[API/functions/array_normalize#Examples|Examples...]]) | No |- | [[API/functions/array_push|array_push]]() | void | array, value, [value2...] | {{object|CastException}} | Pushes the specified value(s) onto the end of the array. Unlike calling array_set(@array, array_size(@array), @value) on a normal array, the size of the array is increased first. The special operator syntax @array[] = 'value' is also supported, as shorthand for array_push().
([[API/functions/array_push#Examples|Examples...]]) | No |- | [[API/functions/array_push_all|array_push_all]]() | void | array, values | {{object|CastException}} | Pushes all the values of an array individually. If you try to push an array onto array_push, this will give you a two dimensional array, this method pushes the sub values of the values array into the destination array. | No |- | [[API/functions/array_rand|array_rand]]() | array | array, [number, [getKeys]] | {{object|RangeException}}
{{object|CastException}} | Returns a random selection of keys or values from an array. The array may be either normal or associative. Number defaults to 1, and getKey defaults to true. If number is greater than the size of the array, a RangeException is thrown. No value will be returned twice from the array however, one it is "drawn" from the array, it is not placed back in. The order of the elements in the array will also be random, if order is important, use array_sort().
([[API/functions/array_rand#Examples|Examples...]]) | No |- | [[API/functions/array_reduce|array_reduce]]() | mixed | array, closure | {{object|CastException}}
{{object|IllegalArgumentException}} | Reduces an array to a single value. This is useful for, for instance, summing the values of an array. The previously calculated value, then the next value of the array are sent to the closure, which is expected to return a value, based on the two values, which will be sent again to the closure as the new calculated value. If the array is empty, null is returned, and if the array has exactly one value in it, only that value is returned. Associative arrays are supported, but the order is based on the key order, which may not be as expected. The keys of the array are ignored.
([[API/functions/array_reduce#Examples|Examples...]]) | No |- | [[API/functions/array_reduce_right|array_reduce_right]]() | mixed | array, closure | {{object|CastException}}
{{object|IllegalArgumentException}} | Reduces an array to a single value. This works in reverse of array_reduce(). This is useful for, for instance, summing the values of an array. The previously calculated value, then the previous value of the array are sent to the closure, which is expected to return a value, based on the two values, which will be sent again to the closure as the new calculated value. If the array is empty, null is returned, and if the array has exactly one value in it, only that value is returned. Associative arrays are supported, but the order is based on the key order, which may not be as expected. The keys of the array are ignored.
([[API/functions/array_reduce_right#Examples|Examples...]]) | No |- | [[API/functions/array_remove|array_remove]]() | mixed | array, index | {{object|RangeException}}
{{object|CastException}}
{{object|PluginInternalException}} | Removes an index from an array. If the array is a normal array, all values' indices are shifted left one. If the array is associative, the index is simply removed. If the index exists, the value removed is returned. If the index doesn't exist, the array remains unchanged, however it'll throw a RangeException for normal arrays (returns null for associative arrays).
([[API/functions/array_remove#Examples|Examples...]]) | No |- | [[API/functions/array_remove_values|array_remove_values]]() | void | array, value | {{object|CastException}} | Removes all instances of value from the specified array. For instance, array_remove_values(array(1, 2, 2, 3), 2) would produce the array(1, 3). Note that it returns void however, so it will simply in place modify the array passed in, much like array_remove.
([[API/functions/array_remove_values#Examples|Examples...]]) | No |- | [[API/functions/array_resize|array_resize]]() | array | array, size, [fill] | {{object|CastException}} | Resizes the given array so that it is at least of size size, filling the blank spaces with fill, or null by default. If the size of the array is already at least size, nothing happens; in other words this function can only be used to increase the size of the array. A reference to the array is returned, for easy chaining.
([[API/functions/array_resize#Examples|Examples...]]) | No |- | [[API/functions/array_reverse|array_reverse]]() | array | array | {{object|CastException}} | Reverses an array in place. However, if the array is associative, throws a CastException, since associative arrays are more like a map. Returns the array for easy chaining.
([[API/functions/array_reverse#Examples|Examples...]]) | No |- | [[API/functions/array_scontains|array_scontains]]() | boolean | array, testValue | {{object|CastException}} | Checks if the array contains a value of the same datatype and value as testValue. For associative arrays, only the values are searched, the keys are ignored. If you need to check for the existence of a particular key, use array_index_exists().
([[API/functions/array_scontains#Examples|Examples...]]) | No |- | [[API/functions/array_set|array_set]]() | mixed | array, index, value | {{object|CastException}}
{{object|IndexOverflowException}} | Sets the value of the array at the specified index. The value that was set is returned, to allow for chaining.
([[API/functions/array_set#Examples|Examples...]]) | No |- | [[API/functions/array_shallow_clone|array_shallow_clone]]() | array | array | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Performs a shallow clone on an array (as opposed to a deep clone). See the examples for more info.
([[API/functions/array_shallow_clone#Examples|Examples...]]) | No |- | [[API/functions/array_size|array_size]]() | int | array | {{object|CastException}} | Returns the size of this array as an integer.
([[API/functions/array_size#Examples|Examples...]]) | No |- | [[API/functions/array_some|array_some]]() | boolean | array, closure | {{object|CastException}} | Returns true if any value in the array meets some test, which the closure should return true or false about. Not all values will necessarily be checked, once a value is determined to pass the check, execution is stopped, and true is returned. The closure will be passed each value in the array, one at a time, and must return a boolean.
([[API/functions/array_some#Examples|Examples...]]) | No |- | [[API/functions/array_sort|array_sort]]() | array | array, [sortType] | {{object|CastException}}
{{object|FormatException}} | Sorts an array in place, and also returns a reference to the array. [[API/functions/array_sort|See more...]]
([[API/functions/array_sort#Examples|Examples...]]) | No |- | [[API/functions/array_sort_async|array_sort_async]]() | void | array, [sortType], closure(array) | {{object|CastException}} | Works like array_sort, but does the sort on another thread, then calls the closure and sends it the sorted array. This is useful if the array is large enough to actually "stall" the server when doing the sort. Sort type should be one of REGULAR, NUMERIC, STRING or STRING_IC | No |- | [[API/functions/array_subset_of|array_subset_of]]() | boolean | array, array | {{object|IllegalArgumentException}} | Returns true if first array is a subset of second array.
([[API/functions/array_subset_of#Examples|Examples...]]) | No |- | [[API/functions/array_subtract|array_subtract]]() | array | array1, array2, [comparisonMode] | {{object|CastException}}
{{object|IllegalArgumentException}} | Returns a new array, which contains all the values in the left array, which are not present in the right array. comparisonMode defaults to HASH, but may also be EQUALS or STRICT_EQUALS. A closure may be sent instead, which should return true if the two values are considered equals or not. [[API/functions/array_subtract|See more...]]
| No |- | [[API/functions/array_unique|array_unique]]() | array | array, [compareTypes] | {{object|CastException}} | Removes all non-unique values from an array. [[API/functions/array_unique|See more...]]
([[API/functions/array_unique#Examples|Examples...]]) | No |- | [[API/functions/cslice|cslice]]() | slice | from, to | {{object|CastException}} | Dynamically creates an array slice, which can be used with array_get (or the [bracket notation]) to get a range of elements. cslice(0, 5) is equivalent to 0..5 directly in code, however with this function you can also do cslice(@var, @var), or other more complex expressions, which are not possible in static code.
([[API/functions/cslice#Examples|Examples...]]) | No |- | [[API/functions/map_implode|map_implode]]() | string | associativeArray, innerGlue, outerGlue | {{object|CastException}} | Implodes an associative array. The innerGlue is used to glue the key to the value, and then the outerGlue is used to glue those elements together. This only works with associative arrays, and will throw CastException if the array passed in isa normal array.
([[API/functions/map_implode#Examples|Examples...]]) | No |- | [[API/functions/range|range]]() | array | start, finish, [increment]
finish | {{object|CastException}} | Returns an array of numbers from start to (finish - 1) skipping increment integers per count. start defaults to 0, and increment defaults to 1. All inputs must be integers. If the input doesn't make sense, it will reasonably degrade, and return an empty array.
([[API/functions/range#Examples|Examples...]]) | No |} == BasicLogic ==
These functions provide basic logical operations.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/and|and]]()
| boolean
| var1, [var2...]
| {{object|CastException}}
| Returns the boolean value of a logical AND across all arguments. Uses lazy determination, so once an argument returns false, the function returns. Operator syntax is supported: @a && @b([[API/functions/and#Examples|Examples...]]) | No |- | [[API/functions/bit_and|bit_and]]() | int | int1, int2, [int3...] | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Returns the bitwise AND of the values
([[API/functions/bit_and#Examples|Examples...]]) | No |- | [[API/functions/bit_not|bit_not]]() | int | int1 | {{object|CastException}} | Returns the bitwise NOT of the given value
([[API/functions/bit_not#Examples|Examples...]]) | No |- | [[API/functions/bit_or|bit_or]]() | int | int1, int2, [int3...] | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Returns the bitwise OR of the specified values
([[API/functions/bit_or#Examples|Examples...]]) | No |- | [[API/functions/bit_xor|bit_xor]]() | int | int1, int2, [int3...] | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Returns the bitwise exclusive OR of the specified values
([[API/functions/bit_xor#Examples|Examples...]]) | No |- | [[API/functions/compile_error|compile_error]]() | nothing | message | | Throws a compile error unconditionally at link time, if the function has not been fully compiled out with preprocessor directives. This is useful for causing a custom compile error if certain compilation environment settings are not correct. | Yes |- | [[API/functions/dand|dand]]() | mixed | ... | | Returns the first falsey value. The arguments to this function are lazily evaluated, so if the first value evaluates to falsey, the rest of the arguments will not be evaluated. If none of the values are falsey, the last value is returned. Usage of the operator is preferred: &&& | No |- | [[API/functions/dor|dor]]() | mixed | ... | | Returns the first true value. The arguments to this function are lazily evaluated, so if the first value evaluates to true, the rest of the arguments will not be evaluated. If none of the values are true, the last value is returned (which will be falsy). Usage of the operator is preferred: |||
([[API/functions/dor#Examples|Examples...]]) | No |- | [[API/functions/equals|equals]]() | boolean | var1, var2[, varX...] | {{object|InsufficientArgumentsException}} | Returns true if all the arguments are equal. Operator syntax is also supported: @a == @b
([[API/functions/equals#Examples|Examples...]]) | No |- | [[API/functions/equals_epsilon|equals_epsilon]]() | boolean | double d1, number d2, double epsilon
number d1, double d2, double epsilon | {{object|CastException}} | When comparing the equality of floating point numbers, it is often impossible to directly compare via == (equals) since two floating point numbers that might be actually semantically equivalent, are represented slightly differently in the computer, thus making them not actually equal, even though they are effectively equal. This function provides an epsilon argument to verify if two numbers are within that degree of difference. A good rule of thumb is to use 5-6 places of precision, but depending on your program's needs, more or less might be required.
([[API/functions/equals_epsilon#Examples|Examples...]]) | No |- | [[API/functions/equals_ic|equals_ic]]() | boolean | val1, val2[, valX...] | {{object|InsufficientArgumentsException}} | Returns true if all the values are equal to each other, while ignoring case.
([[API/functions/equals_ic#Examples|Examples...]]) | No |- | [[API/functions/gt|gt]]() | boolean | var1, var2 | {{object|CastException}} | Returns the result of a greater than operation. Operator syntax is also supported: @a > @b
([[API/functions/gt#Examples|Examples...]]) | No |- | [[API/functions/gte|gte]]() | boolean | var1, var2 | {{object|CastException}} | Returns the result of a greater than or equal to operation. Operator sytnax is also supported: @a >= @b
([[API/functions/gte#Examples|Examples...]]) | No |- | [[API/functions/hash|hash]]() | int | value | | Hashes the value, and returns an int representing that value.
([[API/functions/hash#Examples|Examples...]]) | No |- | [[API/functions/lshift|lshift]]() | int | value, bitsToShift | {{object|CastException}} | Left shifts the value bitsToShift times
([[API/functions/lshift#Examples|Examples...]]) | No |- | [[API/functions/lt|lt]]() | boolean | var1, var2 | {{object|CastException}} | Returns the results of a less than operation. Operator syntax is also supported: @a < @b
([[API/functions/lt#Examples|Examples...]]) | No |- | [[API/functions/lte|lte]]() | boolean | var1, var2 | {{object|CastException}} | Returns the result of a less than or equal to operation. Operator syntax is also supported: @a <= @b
([[API/functions/lte#Examples|Examples...]]) | No |- | [[API/functions/nand|nand]]() | boolean | val1, [val2...] | {{object|CastException}} | Return the equivalent of not(and())
([[API/functions/nand#Examples|Examples...]]) | No |- | [[API/functions/nequals|nequals]]() | boolean | val1, val2 | | Returns true if the two values are NOT equal, or false otherwise. Equivalent to not(equals(val1, val2)). Operator syntax is also supported: @a != @b
([[API/functions/nequals#Examples|Examples...]]) | No |- | [[API/functions/nequals_ic|nequals_ic]]() | boolean | val1, val2 | | Returns true if the two values are NOT equal to each other, while ignoring case.
([[API/functions/nequals_ic#Examples|Examples...]]) | No |- | [[API/functions/nor|nor]]() | boolean | val1, [val2...] | {{object|CastException}} | Returns the equivalent of not(or())
([[API/functions/nor#Examples|Examples...]]) | No |- | [[API/functions/not|not]]() | boolean | var1 | {{object|CastException}} | Returns the boolean value of a logical NOT for this argument. Operator syntax is also supported: !@var
([[API/functions/not#Examples|Examples...]]) | No |- | [[API/functions/or|or]]() | boolean | var1, [var2...] | {{object|CastException}} | Returns the boolean value of a logical OR across all arguments. Uses lazy determination, so once an argument resolves to true, the function returns. Operator syntax is also supported: @a || @b
([[API/functions/or#Examples|Examples...]]) | No |- | [[API/functions/ref_equals|ref_equals]]() | boolean | val1, val2 | | Returns true if and only if the two values are actually the same reference. Primitives that are equal will always be the same reference, this method is only useful for object/array comparisons.
([[API/functions/ref_equals#Examples|Examples...]]) | No |- | [[API/functions/rshift|rshift]]() | int | value, bitsToShift | {{object|CastException}} | Right shifts the value bitsToShift times
([[API/functions/rshift#Examples|Examples...]]) | No |- | [[API/functions/sequals|sequals]]() | boolean | val1, val2 | | Uses a strict equals check, which determines if two values are not only equal, but also the same type. So, while equals('1', 1) returns true, sequals('1', 1) returns false, because the first one is a string, and the second one is an int. More often than not, you want to use plain equals(). In addition, type juggling is explicitly not performed on strings. Thus '2' !== '2.0', despite those being ==. Operator syntax is also supported: @a === @b
([[API/functions/sequals#Examples|Examples...]]) | No |- | [[API/functions/sequals_ic|sequals_ic]]() | boolean | value1, value2 | | Returns true if the values are the same type, as well as equal, according to equals_ic. Generally, equals_ic will suffice, because usually you will be comparing two strings, however, this function may be useful in various other cases, perhaps where the datatypes are unknown, but could be strings.
([[API/functions/sequals_ic#Examples|Examples...]]) | No |- | [[API/functions/snequals|snequals]]() | boolean | val1, val2 | | Equivalent to not(sequals(val1, val2)). Operator syntax is also supported: @a !== @b
([[API/functions/snequals#Examples|Examples...]]) | No |- | [[API/functions/urshift|urshift]]() | int | value, bitsToShift | {{object|CastException}} | Right shifts value bitsToShift times, pushing a 0, making this an unsigned right shift.
([[API/functions/urshift#Examples|Examples...]]) | No |- | [[API/functions/xnor|xnor]]() | boolean | val1, val2 | {{object|CastException}} | Returns the xnor of the two values
([[API/functions/xnor#Examples|Examples...]]) | No |- | [[API/functions/xor|xor]]() | boolean | val1, val2 | {{object|CastException}} | Returns the xor of the two values.
([[API/functions/xor#Examples|Examples...]]) | No |} == BossBar ==
Functions to create and manage boss bars in Minecraft.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/bar_add_player|bar_add_player]]()
| void
| id, player
| {{object|NotFoundException}}{{object|PlayerOfflineException}}
{{object|LengthException}} | Adds a player to the specified boss bar. | Yes |- | [[API/functions/bar_remove_player|bar_remove_player]]() | void | id, player | {{object|NotFoundException}}
{{object|PlayerOfflineException}}
{{object|LengthException}} | Removes a player from the specified boss bar. | Yes |- | [[API/functions/create_bar|create_bar]]() | void | id, [optionsArray] | {{object|IllegalArgumentException}}
{{object|CastException}}
{{object|FormatException}}
{{object|RangeException}}
{{object|Exception}} | Creates a new boss bar with a reference id. An optional array can be given with the keys: title, color, style, visible, percent. Title displays above the boss bar. Color can be one of PINK, BLUE, RED, GREEN, YELLOW, PURPLE, or WHITE. Style can be one of SOLID, SEGMENTED_6, SEGMENTED_10, SEGMENTED_12, or SEGMENTED_20. Visible is a boolean for whether the bar is visible or not. Percent is a double from 0.0 to 1.0 representing the how much the bar is filled from left to right. Defaults to an empty title with a WHITE, SOLID, visible, full bar. Once the bar is created, it can be shown to specified players with {{function|bar_add_player}} and the display can be modified with {{function|update_bar}} | Yes |- | [[API/functions/get_bar|get_bar]]() | array | id | {{object|NotFoundException}} | Gets an array of current options for the specified boss bar. | Yes |- | [[API/functions/get_bar_players|get_bar_players]]() | array | id | {{object|NotFoundException}} | Returns an array of players that can see this boss bar. | Yes |- | [[API/functions/get_bars|get_bars]]() | array | | | Gets an array of boss bar ids currently in use. | Yes |- | [[API/functions/remove_bar|remove_bar]]() | void | id | {{object|NotFoundException}} | Removes the boss bar for all players. | Yes |- | [[API/functions/update_bar|update_bar]]() | void | id, optionsArray
id, percent
id, title | {{object|IllegalArgumentException}}
{{object|CastException}}
{{object|FormatException}}
{{object|NotFoundException}}
{{object|RangeException}} | Updates the state for the specified boss bar. See create_bar() for available option keys and values for the optionsArray. If the second argument is a string, it'll use it to update the title. If it's a double, it'll use it to update the percentage filled (0.0 - 1.0). | Yes |} == BukkitMetadata ==
This class allows manipulation of bukkit metadata.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/get_metadata|get_metadata]]()
| mixed
| [object], key object, key, [plugin] | {{object|BadEntityException}}
{{object|CastException}}
{{object|FormatException}}
{{object|InvalidPluginException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|PlayerOfflineException}} | Returns the metadata values attached to the given object. object can be a location array (it will designate a block), an entityID (it will designate an entity) or a string (it will designate a world). If only the key is given, the object is the current player. The function returns an associative array where the values are keyed by plugin which have registered the metadata with the given key, and the array values the registered metadata values. If the plugin argument is given (a string that represent the plugin name), the function simply returns the value of the metadata registered by the plugin with this key, or null if no metadata is found. --- The Bukkit metadata allow to attach information to entities, blocks and worlds, and allow plugins to exchange these information between them without requiring one to be dependant on each other. The metadata are persistent across server reloads, but not across server restarts. The metadata attached to a player are also persistent between logins.
([[API/functions/get_metadata#Examples|Examples...]]) | Yes |- | [[API/functions/has_metadata|has_metadata]]() | boolean | [object], key
object, key, [plugin] | {{object|BadEntityException}}
{{object|CastException}}
{{object|FormatException}}
{{object|InvalidPluginException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|PlayerOfflineException}} | Returns if the given object has metadata registered with this key. object can be a location array (it will designate a block), an entityID (it will designate an entity) or a string (it will designate a world). If only the key is given, the object is the current player. If the plugin is given, the function returns if the plugin have registered a metadata in the object with the given key. See get_metadata() for more information about Bukkit metadata. | Yes |- | [[API/functions/remove_metadata|remove_metadata]]() | void | [object], key
object, key, [plugin] | {{object|BadEntityException}}
{{object|CastException}}
{{object|FormatException}}
{{object|InvalidPluginException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|PlayerOfflineException}} | Remove the metadata in the given object at the given key. object can be a location array (it will designate a block), an entityID (it will designate an entity) or a string (it will designate a world). If only the key is given, the object is the current player. If no plugin is given, the function removes all metadata at the given key, otherwise only the value set by the given plugin. See get_metadata() for more information about Bukkit metadata. | Yes |- | [[API/functions/set_metadata|set_metadata]]() | void | [object], key, value
object, key, value, [plugin] | {{object|BadEntityException}}
{{object|CastException}}
{{object|FormatException}}
{{object|InvalidPluginException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|PlayerOfflineException}} | Registers a metadata value in the given object with the given key. object can be a location array (it will designate a block), an entityID (it will designate an entity) or a string (it will designate a world). If only the key and the value are given, the object is the current player. You can specify the plugin that will own the metadata, 'MethodScript' by default. See get_metadata() for more information about Bukkit metadata. | Yes |} == ByteArrays ==
This class contains all the methods needed to manipulate a byte array primitive. Since byte arrays would be very inefficient to implement using a normal array, this data type allows for more efficient operations, while still allowing for low level data access. Most data transferred within scripts is higher level, and does not require access to a byte array, however, code that interacts with external processes may require use of these functions to properly manipulate the data. Note that all the methods deal with low level types, so the following definitions apply: a byte is 8 bits, a short is 16 bits, an int is 32 bits, a long is 64 bits. UTF-8 strings are supported directly. The byte array is automatically resized as needed.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/ba_as_array|ba_as_array]]()
| array
| byte_array
| {{object|CastException}}
| Returns a new read only copy of the underlying byte array. This array is much more efficient than if the array were made manually, however, it is read only. If you need to manipulate the array's contents, then you can clone the array, however, the returned array (and any clones) cannot be automatically interfaced with the byte array primitives. This operation is discouraged, because normal arrays are very inefficient for dealing with low level bit data.
| No
|-
| [[API/functions/ba_get_byte|ba_get_byte]]()
| int
| byte_array, [pos]
| {{object|CastException}}{{object|RangeException}} | Returns an int, read in as an 8 bit signed byte, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_bytes|ba_get_bytes]]() | byte_array | byte_array, length, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns a new byte_array primitive containing 'length' bytes starting from pos (or wherever the marker is by default) in the given byte array. | No |- | [[API/functions/ba_get_char|ba_get_char]]() | string | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns a one character string, read in as an 32 bit char, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_double|ba_get_double]]() | double | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns a double, read in as a 64 bit double, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_float|ba_get_float]]() | double | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns a double, read in as a 32 bit float, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_int|ba_get_int]]() | int | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns an int, read in as a 32 bit signed int, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_long|ba_get_long]]() | int | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns an int, read in as a 64 bit signed long, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_short|ba_get_short]]() | int | byte_array, [pos] | {{object|CastException}}
{{object|RangeException}} | Returns an int, read in as a 16 bit signed short, from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_get_string|ba_get_string]]() | string | byte_array, [pos], [encoding] | {{object|CastException}}
{{object|RangeException}} | Returns a UTF-8 encoded string, from the given position, or wherever the marker is currently at by default. The string is assumed to have encoded the length of the string with a 32 bit integer, then the string bytes. (This will be the case is the byte_array was encoded with ba_set_string.) The encoding of the string may be set, but defaults to UTF-8. | No |- | [[API/functions/ba_is_little_endian|ba_is_little_endian]]() | boolean | byte_array | {{object|CastException}} | Returns true if this byte array is little endian. By default, byte arrays are big endian, but this may be changed with ba_set_little_endian. | No |- | [[API/functions/ba_put_byte|ba_put_byte]]() | void | byte_array, int, [pos] | {{object|CastException}}
{{object|RangeException}} | Writes an int, interpreted as an 8 bit signed byte, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_bytes|ba_put_bytes]]() | void | destination_byte_array, source_byte_array, [pos] | {{object|CastException}} | Writes the contents of the source_byte_array into this byte array, starting at pos, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_char|ba_put_char]]() | void | byte_array, string, [pos] | {{object|CastException}} | Writes the first character of the string, interpreted as an 32 bit char, starting from the given position, or wherever the marker is currently at by default. If the string is empty, a \0 is written instead. | No |- | [[API/functions/ba_put_double|ba_put_double]]() | void | byte_array, double, [pos] | {{object|CastException}} | Writes a double, interpreted as a 64 bit double, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_float|ba_put_float]]() | void | byte_array, double, [pos] | {{object|CastException}}
{{object|RangeException}} | Writes a double, interpreted as a 32 bit float, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_int|ba_put_int]]() | void | byte_array, int, [pos] | {{object|CastException}}
{{object|RangeException}} | Writes an int, interpreted as a 32 bit signed int, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_long|ba_put_long]]() | void | byte_array, int, [pos] | {{object|CastException}} | Writes an int, interpreted as a 64 bit signed long, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_short|ba_put_short]]() | void | byte_array, int, [pos] | {{object|CastException}}
{{object|RangeException}} | Writes an int, interpreted as an 16 bit signed short, starting from the given position, or wherever the marker is currently at by default. | No |- | [[API/functions/ba_put_string|ba_put_string]]() | void | byte_array, string, [pos], [encoding] | {{object|CastException}} | Writes the length of the string to the byte array, as a short, (interpreted as UTF-8), then writes the UTF-8 string itself. If an external application requires the string to be serialized in a different manner, then use the string-byte_array conversion methods in StringHandling, however strings written in this manner are compatible with ba_get_string. The encoding may be set, but defaults to UTF-8. | No |- | [[API/functions/ba_rewind|ba_rewind]]() | void | byte_array | {{object|CastException}} | Rewinds the byte array marker to 0. | No |- | [[API/functions/ba_set_little_endian|ba_set_little_endian]]() | void | byte_array, setLittleEndian | {{object|CastException}} | Sets the byte order that the specified byte array will use for all future gets/sets. By default, a byte array is Big Endian. If setLittleEndian is true, the byte array will be set to little endian, otherwise it will be set to big endian. | No |- | [[API/functions/byte_array|byte_array]]() | byte_array | | | Returns a new byte array primitive, which can be operated on with the ba_ series of functions. | No |} == Clipboard ==
Provides functions for managing the system clipboard
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/get_clipboard|get_clipboard]]()
| string
| [flavor]
| {{object|FormatException}}{{object|InsufficientPermissionException}}
{{object|UnsupportedOperationException}} | Returns the contents of the system clipboard. Can only be used in cmdline mode. Flavor defaults to null, and is currently unused. Only strings are currently supported. If a string version of the clipboard contents cannot be parsed, a FormatException is thrown. If the platform doesn't support clipboard operations, an UnsupportedOperationException is thrown. | Yes |- | [[API/functions/set_clipboard|set_clipboard]]() | void | value, [flavor] | {{object|InsufficientPermissionException}}
{{object|UnsupportedOperationException}} | Sets the contents of the system clipboard, to the given value. Can only be used in cmdline mode. Flavor defaults to null, and is currently unused. Only strings are currently supported. If the platform doesn't support clipboard operations, an UnsupportedOperationException is thrown. | Yes |} == Cmdline ==
This class contains functions that are mostly only useful for command line scripts, but in general may be used by any script. For more information on running MethodScript from the command line, see [[Command_Line_Scripting|this wiki page]].
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/cd|cd]]()
| void
| [dir]
| {{object|IOException}}{{object|InsufficientPermissionException}} | Changes the current working directory to the path specified, or the user's home directory if omitted. This only works from cmdline mode. | Yes |- | [[API/functions/clear_screen|clear_screen]]() | void | | | Clears the screen. This only works from cmdline mode, nothing happens otherwise. | Yes |- | [[API/functions/exit|exit]]() | void | [int] | | Exits the program. If this is being run from the command line, works by exiting the interpreter, with the specified exit code (defaulting to 0). If this is being run from in-game, works just like die().
([[API/functions/exit#Examples|Examples...]]) | No |- | [[API/functions/get_env|get_env]]() | mixed | [variableName] | | Returns the environment variable specified, if variableName is set. Otherwise, returns an associative array of all the environment variables. | Yes |- | [[API/functions/get_os|get_os]]() | string | | | Returns the name of the current OS. Will be one of WINDOWS, MAC, LINUX, SOLARIS, or UNKNOWN. | Yes |- | [[API/functions/get_terminal_width|get_terminal_width]]() | int | | {{object|InsufficientPermissionException}} | Returns the current width of the terminal, measured in characters. This is useful for determining proper layout for dynamic output. This only works in cmdline mode. | Yes |- | [[API/functions/in_cmdline_mode|in_cmdline_mode]]() | boolean | | | Returns true if the environment is in cmdline mode. False otherwise. | No |- | [[API/functions/ls|ls]]() | array | [directory] | {{object|InsufficientPermissionException}}
{{object|IOException}} | Returns an array of files in the current working directory, including "hidden" files, orif directory is specified, the files in that directory. This is only available in cmdline mode. | Yes |- | [[API/functions/print_err|print_err]]() | void | text | | Writes the text to the system's std err, but does not automatically add a newline at the end. Unlike console(), this does not use anything else to format the output, though in many cases they will behave the same. Unlike other print methods, colors and other formatting characters WILL "bleed" through, so print_err(color(RED) . 'This is red') will also cause the next line to also be red, so if you need to print multiple lines out, you should manually reset the color with print_out(color(RESET)), or use sys_err. | Yes |- | [[API/functions/print_out|print_out]]() | void | text | | Writes the text to the system's std out, but does not automatically add a newline at the end. Unlike console(), this does not use anything else to format the output, though in many cases they will behave the same. Unlike other print methods, colors and other formatting characters WILL "bleed" through, so print_out(color(RED) . 'This is red') will also cause the next line to also be red, so if you need to print multiple lines out, you should manually reset the color with print_out(color(RESET)), or use sys_out.. | Yes |- | [[API/functions/prompt_char|prompt_char]]() | string | prompt | {{object|InsufficientPermissionException}}
{{object|IOException}} | Prompts the user for a single character. They do not need to hit enter first. This only works in cmdline mode. | Yes |- | [[API/functions/prompt_line|prompt_line]]() | string | prompt | {{object|InsufficientPermissionException}}
{{object|IOException}} | Prompts the user for a line. The line typed is returned once the user presses enter. This only works in cmdline mode. | Yes |- | [[API/functions/prompt_pass|prompt_pass]]() | secure_string | prompt, [mask] | {{object|InsufficientPermissionException}}
{{object|IOException}} | Prompts the user for a password. This only works in cmdline mode. If mask is true (default), then the password displays * characters for each password character they type. If mask is false, the field stays blank as they type. What they type is returned once they hit enter. The value returned is a secure_string, so to get the actual password, you must use decrypt_secure_string.
([[API/functions/prompt_pass#Examples|Examples...]]) | Yes |- | [[API/functions/pwd|pwd]]() | string | | {{object|ShellException}} | Returns the path to the current working directory. This is available outside cmdline mode, but is probably only useful for debugging, meta, or informational purposes when not in cmdline interpreter mode, as the current working directory is known simply by knowing what file this is running from. When run from a context where there is no working directory, a ShellException is thrown. | Yes |- | [[API/functions/read_pipe_input|read_pipe_input]]() | mixed | [binary] | {{object|IOException}}
{{object|InsufficientPermissionException}} | Reads the input from a process that is piped to this script. It is assumed that the data piped to the script will come all at once, and it will be returned as a string (or byte_array if binary is true). This can only be used in cmdline mode, and binary defaults to false. If the script isn't started in TTY mode, an IOException is thrown. | Yes |- | [[API/functions/set_cmdline_prompt|set_cmdline_prompt]]() | void | closure | {{object|CastException}}
{{object|InsufficientPermissionException}} | Sets the cmdline prompt. This is only usable or useful in cmdline interpreter mode. The closure should return a string, that string will be used as the prompt. The closure is called each time a prompt needs generating, thereby allowing for dynamic prompts. A boolean is sent to the closure, if true, the shell is in shellMode, meaning the command is interpreted as a shell command. If false, it is in normal mscript mode. | Yes |- | [[API/functions/set_env|set_env]]() | void | variableName, value | | Sets the value of an environment variable. This only changes the environment value in this process, not system-wide. This uses some hackery to work, and may not be 100% reliable in all cases, and shouldn't be relied on heavily. It will always work with get_env, however, so you can rely on that mechanism. The value will always be interpreted as a string, so if you are expecting a particular data type on a call to get_env, you will need to manually cast the variable. Arrays will be toString'd as well, but will be accepted. | Yes |- | [[API/functions/shell|shell]]() | string | command, [options] | {{object|InsufficientPermissionException}}
{{object|ShellException}}
{{object|IOException}}
{{object|IllegalArgumentException}} | Runs a shell command. <code>command</code> can be either a string, or array of string arguments. This works mostly like {{function|shell_adv}} however, it buffers then returns the output for sysout once the process is completed, and throws a ShellException with the exception message set to the syserr output if the process exits with an exit code that isn't the expectedExitCode, which defaults to 0. This is useful for simple commands that return output and don't need very complicated usage, and failures don't need to check the exact error code. If the underlying command throws an IOException, it is passed through. Requires the allow-shell-commands option to be enabled in preferences, or run from command line, otherwise an InsufficientPermissionException is thrown. When the passed command results in an empty shell command, an IllegalArgumentException is thrown. Options is an associative array which expects zero or more of the following options: expectedErrorCode - The expected error code indicating successful command completion. Defaults to 0. workingDir - Sets the working directory for the sub process. By default null, which represents the directory of this script. If the path is relative, it is relative to the directory of this script.
([[API/functions/shell#Examples|Examples...]]) | Yes |- | [[API/functions/shell_adv|shell_adv]]() | void | command, [options] | {{object|InsufficientPermissionException}}
{{object|IOException}}
{{object|IllegalArgumentException}} | Runs a shell command. <code>command</code> can either be a string or an array of string arguments, which are run as an external process. Requires the allow-shell-commands option to be enabled in preferences, or run from command line, otherwise an InsufficientPermissionException is thrown.When the passed command results in an empty shell command, an IllegalArgumentException is thrown. [[API/functions/shell_adv|See more...]]
| Yes |- | [[API/functions/shell_on|shell_on]]() | string | os, command, [options] | {{object|InsufficientPermissionException}}
{{object|ShellException}}
{{object|IOException}}
{{object|FormatException}} | Executes the command if and only if on the given operating system (one of WINDOWS, MAC, LINUX, SOLARIS, or UNKNOWN). If not on the specified OS, this command returns null. The os argument may be a pipe seperated list of OSes, for instance 'MAC|LINUX', which is useful given that both are unix based, and often times the same command will work for both. Otherwise completely equivalent to {{function|shell}}. This is useful, because usually a command is tailored to a specific OS, and simply won't run on other OSes. This allows you to create similar commands across various OSes, and ensure that they only run for the correct OS.
([[API/functions/shell_on#Examples|Examples...]]) | Yes |- | [[API/functions/shell_on_adv|shell_on_adv]]() | void | os, command, [options] | {{object|InsufficientPermissionException}}
{{object|ShellException}}
{{object|IOException}}
{{object|FormatException}} | Executes the command if and only if on the given operating system (one of WINDOWS, MAC, LINUX, SOLARIS, or UNKNOWN). If not on the specified OS, this command does nothing. The os argument may be a pipe seperated list of OSes, for instance 'MAC|LINUX', which is useful given that both are unix based, and often times the same command will work for both. Otherwise completely equivalent to {{function|shell_adv}}. This is useful, because usually a command is tailored to a specific OS, and simply won't run on other OSes. This allows you to create similar commands across various OSes, and ensure that they only run for the correct OS. | Yes |- | [[API/functions/sys_beep|sys_beep]]() | void | | {{object|InsufficientPermissionException}}
{{object|PluginInternalException}} | Emits a system beep, on the system itself, not in game. This is only useful from cmdline. | Yes |- | [[API/functions/sys_err|sys_err]]() | void | text | | Writes the text to the system's std err. Unlike console(), this does not use anything else to format the output, though in many cases they will behave nearly the same. However, colors and other formatting characters will not "bleed" through, so sys_err(color(RED) . 'This is red') will not cause the next line to also be red, so if you need to print multiple lines out, you should manually add \n to create your linebreaks, and only make one call to sys_err.
([[API/functions/sys_err#Examples|Examples...]]) | Yes |- | [[API/functions/sys_properties|sys_properties]]() | mixed | [propertyName] | | If propertyName is set, that single property is returned, or null if that property doesn't exist. If propertyName is not set, an associative array with all the system properties is returned. This mechanism hooks into Java's system property mechanism, and is just a wrapper for that. System properties are more reliable than environmental variables, and so are preferred in cases where they exist. For more information about system properties, see http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html. In addition, known preferences listed in preferences.ini are also included, starting with the prefix "methodscript.preference."
([[API/functions/sys_properties#Examples|Examples...]]) | Yes |- | [[API/functions/user|user]]() | string | | | Returns the name of the current user. This is retrieved in a platform specific manner, and should be cross compatible in all scripts. Null is returned if this function call is non-sensical in the current platform | No |- | [[API/functions/x_find|x_find]]() | array
regex, [startFrom], types | {{object|IllegalArgumentException}}
{{object|InsufficientPermissionException}} | Returns a list of absolute paths of files whose name matches the given regex, searching recursively. Only available in cmdline mode. [[API/functions/x_find|See more...]]
| Yes |} == Commands ==
A series of functions for creating and managing custom commands.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/clear_commands|clear_commands]]()
| void
|
|
| Attempts to clear all registered commands on the server. Vanilla and default Spigot functions are not affected, but all plugins commands are.
| Yes
|-
| [[API/functions/get_commands|get_commands]]()
| array
|
|
| Returns an array of command arrays in the format register_command expects or null if no commands could be found. The command arrays will not include executors or tabcompleters. This does not include MethodScript aliases, as they are not registered commands.
| Yes
|-
| [[API/functions/get_tabcomplete_prototype|get_tabcomplete_prototype]]()
| closure
| prototypes...
| {{object|CastException}}
| Returns a closure which can be provided to tabcompleters or run manually,
which provides an easy to use syntax for simple to moderately complex tab completion scenarios. Note that
this cannot be used in all cases, particularly where there are variable length arguments. In these cases,
it's best to write the closure yourself. [[API/functions/get_tabcomplete_prototype|See more...]]([[API/functions/get_tabcomplete_prototype#Examples|Examples...]]) | No |- | [[API/functions/register_command|register_command]]() | boolean | commandname, optionsArray | {{object|FormatException}}
{{object|NotFoundException}} | Registers a command to the server's command list, or updates an existing one. Options is an associative array that can have the following keys: description, usage, permission, noPermMsg, aliases, tabcompleter, and/or executor. [[API/functions/register_command|See more...]]
([[API/functions/register_command#Examples|Examples...]]) | Yes |- | [[API/functions/set_executor|set_executor]]() | void | commandname, closure | {{object|FormatException}}
{{object|NotFoundException}} | Sets the code that will be run when a user attempts to execute a command. The closure can return true false (treated as true by default). Returning false will display The usage message if it is set. The closure is passed the following information in this order: alias used, name of the sender, array of arguments used, array of command info. | Yes |- | [[API/functions/set_tabcompleter|set_tabcompleter]]() | void | commandname, closure | {{object|FormatException}}
{{object|NotFoundException}} | Sets the code that will be run when a user attempts to tabcomplete a command. The closure is expected to return an array of completions, otherwise the tab_complete_command event will be fired and used to send completions. The closure is passed the following information in this order: alias used, name of the sender, array of arguments used, array of command info.
([[API/functions/set_tabcompleter#Examples|Examples...]]) | Yes |- | [[API/functions/unregister_command|unregister_command]]() | boolean | commandname | {{object|NotFoundException}} | Unregisters a command from the server's command list. Commands from other plugins can be unregistered using this function. | Yes |} == Compiler ==
Compiler internal functions should be declared here. If you're reading this from anywhere but the source code, there's a bug, because these functions shouldn't be public or used in a script.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|- class="hiddenFunction"
| [[API/functions/__smart_string__|__smart_string__]]()
| none
| string
|
| This is a compiler construct, and is not normally used directly. It is created via double quoted strings.
| No
|}
== ControlFlow ==
This class provides various functions to manage control flow.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/break|break]]()
| nothing
| [int]
| {{object|CastException}}
| Stops the current loop. If int is specified, and is greater than 1, the break travels that many loops up. So, if you had a loop embedded in a loop, and you wanted to break in both loops, you would call break(2). If this function is called outside a loop (or the number specified would cause the break to travel up further than any loops are defined), the function will fail. If no argument is specified, it is the same as calling break(1). This function has special compilation rules. The break number must not be dynamic, or a compile error will occur. An integer must be hard coded into the function.([[API/functions/break#Examples|Examples...]]) | No |- | [[API/functions/call_proc|call_proc]]() | mixed | proc_name, [var1...] | {{object|InvalidProcedureException}} | Dynamically calls a user defined procedure. call_proc(_myProc, 'var1') is the equivalent of _myProc('var1'), except you could dynamically build the procedure name if need be. This is useful for dynamic coding, however, closures work best for callbacks. Throws an InvalidProcedureException if the procedure isn't defined. If you are hardcoding the first parameter, a warning will be issued, because it is much more efficient and safe to directly use a procedure if you know what its name is beforehand. | Yes |- | [[API/functions/call_proc_array|call_proc_array]]() | mixed | proc_name, array | {{object|InvalidProcedureException}}
{{object|CastException}} | Works like call_proc, but allows for variable or unknown number of arguments to be passed to a proc. The array parameter is "flattened", and call_proc is essentially called. If the array is associative, an exception is thrown. | Yes |- | [[API/functions/continue|continue]]() | void | [int] | {{object|CastException}} | Skips the rest of the code in this loop, and starts the loop over, with it continuing at the next index. If this function is called outside of a loop, the command will fail. If int is set, it will skip 'int' repetitions. If no argument is specified, 1 is used.
([[API/functions/continue#Examples|Examples...]]) | No |- | [[API/functions/die|die]]() | nothing | [var1, var2...,] | | Kills the command immediately, without completing it. A message is optional, but if provided, displayed to the user. | No |- | [[API/functions/dowhile|dowhile]]() | void | code, condition | | Like while, but always runs the code at least once. The condition is checked after each run of the code, and if it is true, the code is run again. break and continue work inside a dowhile, but continuing more than once is pointless, since the loop isn't inherently keeping track of any counters anyways. Breaking multiple times still works however. In general, using brace syntax is preferred: do { code(); } while(@condition); instead of using dowhile() directly.
([[API/functions/dowhile#Examples|Examples...]]) | No |- | [[API/functions/for|for]]() | void | assign, condition, loopExpr, loopCode | {{object|CastException}} | Acts as a typical for loop. The assignment is first run. Then, a condition is checked. If that condition is checked and returns true, loopCode is run. After that, loopExpr is run. In java syntax, this would be: for(assign; condition; loopExpr){loopCode}. assign must be an ivariable, either a pre defined one, or the results of the assign() function. condition must be a boolean.
([[API/functions/for#Examples|Examples...]]) | No |- | [[API/functions/foreach|foreach]]() | void | array, [key], ivar, code | {{object|CastException}}
{{object|RangeException}} | Walks through array, setting ivar equal to each element in the array, then running code. In addition, foreach(1..4, @i, code()) is also valid, setting @i to 1, 2, 3, 4 each time. The same syntax is valid as in an array slice. If key is set (it must be an ivariable) then the index of each iteration will be set to that. See the examples for a demonstration. [[API/functions/foreach|See more...]]
([[API/functions/foreach#Examples|Examples...]]) | No |- | [[API/functions/foreachelse|foreachelse]]() | void | array, [key], ivar, code, else | {{object|CastException}}
{{object|RangeException}} | Works like a foreach, except if the array is empty, the else code runs instead. That is, if the code would not run at all, the else condition would. In general, brace syntax and use of foreach(){ } else { } syntax is preferred, instead of using foreachelse directly.
([[API/functions/foreachelse#Examples|Examples...]]) | No |- | [[API/functions/forelse|forelse]]() | void | assign, condition, loopExpr, loopCode, elseCode | | Works like a normal for loop, but if upon checking the condition the first time, it is determined that it is false (that is, NO code loops are going to be run) the else code is run instead. If the loop runs, even once, it will NOT run the else branch. In general, brace syntax and use of for(){ } else { } syntax is preferred, instead of using forelse directly. | No |- | [[API/functions/if|if]]() | mixed | cond, trueRet, [falseRet] | {{object|CastException}} | If the first argument evaluates to a true value, the second argument is returned, otherwise the third argument is returned. If there is no third argument, it returns void.
([[API/functions/if#Examples|Examples...]]) | No |- | [[API/functions/ifelse|ifelse]]() | mixed | [boolean1, code]..., [elseCode] | {{object|InsufficientArgumentsException}} | Provides a more convenient method for running if/else chains. If none of the conditions are true, and there is no 'else' condition, void is returned.
([[API/functions/ifelse#Examples|Examples...]]) | No |- | [[API/functions/return|return]]() | nothing | mixed | | Returns the specified value from this procedure or closure. It cannot be called outside a procedure or closure. The function itself does not return a value as such, as it is a terminal function, and prevents further execution within the calling code. Instead it causes the host procedure or closure to return the specified value, and ends termination. (There are exceptions to this rule, see the docs on try/catch, particularly the finally clause for example). | No |- | [[API/functions/switch|switch]]() | mixed | value, [equals, code]..., [defaultCode] | {{object|InsufficientArgumentsException}} | Provides a switch statement. If none of the conditions match, and no default is provided, void is returned. See the documentation on [[Logic|Logic]] for more information. [[API/functions/switch|See more...]]
([[API/functions/switch#Examples|Examples...]]) | No |- | [[API/functions/switch_ic|switch_ic]]() | mixed | value, [equals, code]..., [defaultCode] | {{object|InsufficientArgumentsException}} | Provides a case insensitive switch statement, for switching over strings. This works by compiler transformations, transforming this into a normal switch statement, with each case lowercased, and the input to the switch wrapped in to_lower. The case statements must be strings, however, which is the main difference between this method and the normal switch statement. The lowercasing is done with the system's default locale.
([[API/functions/switch_ic#Examples|Examples...]]) | No |- | [[API/functions/while|while]]() | void | condition, [code] | | While the condition is true, the code is executed. break and continue work inside a dowhile, but continuing more than once is pointless, since the loop isn't inherently keeping track of any counters anyways. Breaking multiple times still works however.
([[API/functions/while#Examples|Examples...]]) | No |} == Crypto ==
Provides common cryptographic functions. Many functions in this class are aware of and compatible with secure_string (where specified in the function documentation). In these cases, if the argument passed in is a secure_string, it is first decrypted and the underlying string is used rather than the default string value "**secure string**".
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/base64_decode|base64_decode]]()
| byte_array
| base64data
| {{object|CastException}}
| Decodes the base 64 encoded byte_array data back into the original byte_array data.([[API/functions/base64_decode#Examples|Examples...]]) | No |- | [[API/functions/base64_encode|base64_encode]]() | byte_array | byteData | {{object|CastException}} | Encodes the given byte_array data into a base 64 byte_array.
([[API/functions/base64_encode#Examples|Examples...]]) | No |- | [[API/functions/bcrypt|bcrypt]]() | string | val, [workload] | {{object|CastException}}
{{object|RangeException}} | Encrypts a value using bcrypt, using the specified workload, or 5 if none provided. BCrypt is supposedly more secure than SHA1, and certainly more secure than md5. Note that using bcrypt is slower, which is one of its security advantages, however, setting the workload to higher numbers will take exponentially more time. A workload of 5 is a moderate operation, which should complete in under a second, however, setting it to 10 will take many seconds, and setting it to 15 will take a few minutes. The workload must be between 5 and 31. See the documentation for check_bcrypt for full usage. Bcrypt is recommended for password hashing, whereas sha-* functions are not. This function is aware of and compatible with secure_string.
([[API/functions/bcrypt#Examples|Examples...]]) | No |- | [[API/functions/check_bcrypt|check_bcrypt]]() | boolean | plaintext, hash | | Checks to see if this plaintext password does in fact hash to the hash specified. Unlike md5 or sha1, simply comparing hashes won't work. This function is aware of and compatible with secure_string.
([[API/functions/check_bcrypt#Examples|Examples...]]) | No |- | [[API/functions/hmac_md5|hmac_md5]]() | string | key, val | {{object|PluginInternalException}} | Returns the md5 HMAC of the specified value using the provided key. If the key or value is not a byte array, it will be converted to a byte array through its UTF-8 string representation. This function is aware of and compatible with secure_string.
([[API/functions/hmac_md5#Examples|Examples...]]) | No |- | [[API/functions/hmac_sha1|hmac_sha1]]() | string | key, val | {{object|PluginInternalException}} | Returns the sha1 HMAC of the specified value using the provided key. If the key or value is not a byte array, it will be converted to a byte array through its UTF-8 string representation. This function is aware of and compatible with secure_string.
([[API/functions/hmac_sha1#Examples|Examples...]]) | No |- | [[API/functions/hmac_sha256|hmac_sha256]]() | string | key, val | {{object|PluginInternalException}} | Returns the sha256 HMAC of the specified value using the provided key. If the key or value is not a byte array, it will be converted to a byte array through its UTF-8 string representation. This function is aware of and compatible with secure_string.
([[API/functions/hmac_sha256#Examples|Examples...]]) | No |- | [[API/functions/md5|md5]]() | string | val | {{object|PluginInternalException}} | Returns the md5 hash of the specified string or byte array. The md5 hash is no longer considered secure, so you should not use it for storage of sensitive data, however for general hashing, it is a quick and easy solution. md5 is a one way hashing algorithm. This function is aware of and compatible with secure_string.
([[API/functions/md5#Examples|Examples...]]) | No |- | [[API/functions/rot13|rot13]]() | string | val | | Returns the rot13 version of val. Note that rot13(rot13(val)) returns val
([[API/functions/rot13#Examples|Examples...]]) | No |- | [[API/functions/sha1|sha1]]() | string | val | {{object|PluginInternalException}} | Returns the sha1 hash of the specified string or byte array. Note that sha1 is considered no more secure than md5, and should not be used in a security context. sha-256 should be used instead for storing sensitive data. It is a one way hashing algorithm. This function is aware of and compatible with secure_string.
([[API/functions/sha1#Examples|Examples...]]) | No |- | [[API/functions/sha256|sha256]]() | string | val | {{object|PluginInternalException}} | Returns the sha256 hash of the specified string or byte array. Note that sha256 is considered more secure than sha1 and md5, and is typically used when storing sensitive data. It is a one way hashing algorithm. This function is aware of and compatible with secure_string.
([[API/functions/sha256#Examples|Examples...]]) | No |- | [[API/functions/sha512|sha512]]() | string | val | {{object|PluginInternalException}} | Returns the sha512 hash of the specified string or byte array. Note that sha512 is considered more secure than sha1 and md5 (and sha256, because it takes longer to calculate), and is typically used when storing sensitive data. It is a one way hashing algorithm. This function is aware of and compatible with secure_string.
([[API/functions/sha512#Examples|Examples...]]) | No |} == DataHandling ==
This class provides various methods to control script data and program flow.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/array|array]]()
| array
| [var1, [var2...]]
|
| Creates an array of values.([[API/functions/array#Examples|Examples...]]) | No |- | [[API/functions/associative_array|associative_array]]() | array | [args...] | | Works exactly like array(), except the array created will be an associative array, even if the array has been created with no elements. This is the only use case where this is necessary, vs using the normal array() function, or in the case where you assign sequential keys anyways, and the same array could have been created using array().
([[API/functions/associative_array#Examples|Examples...]]) | No |- | [[API/functions/boolean|boolean]]() | boolean | item | | Returns a new construct that has been cast to a boolean. The item is cast according to the boolean conversion rules. Since all data types can be cast to a a boolean, this function will never throw an exception.
([[API/functions/boolean#Examples|Examples...]]) | No |- | [[API/functions/closure|closure]]() | closure | [params...], code | | Returns a closure on the provided code. A closure is a datatype that represents some code as code, not the results of some code after it is run. Code placed in a closure can be used as a string, or executed by other functions using the execute() function. If a closure is "to string'd" it will not necessarily look like the original code, but will be functionally equivalent. The current environment is "snapshotted" and stored with the closure, however, this information is only stored in memory, it isn't retained during a serialization operation. Also, the special variable @arguments is automatically created for you, and contains an array of all the arguments passed to the closure, much like procedures. See the wiki article on [[Closures|closures]] for more details and examples.
([[API/functions/closure#Examples|Examples...]]) | Yes |- | [[API/functions/double|double]]() | double | item | {{object|CastException}} | Returns a new construct that has been cast to an double. This function will throw a CastException if is_numeric would return false for this item, but otherwise, it will be cast properly.
([[API/functions/double#Examples|Examples...]]) | No |- | [[API/functions/eval|eval]]() | string | script_string | {{object|CastException}}
{{object|InsufficientPermissionException}} | Executes arbitrary MethodScript. Note that this function is very experimental, and is subject to changing or removal. To globally disable use of eval, set the runtime setting "function.eval.disable" to true, which will cause use of the function to throw an exception. | Yes |- | [[API/functions/execute|execute]]() | mixed | [values...], callable | {{object|CastException}} | Executes the given closure or other Callable. You can also send arguments to the Callable, which it may or may not use, depending on the particular Callable's definition. If the Callable returns a value, then that value will be returned with execute. Otherwise, void is returned. Note that Callables are in general first class language features, which can be invoked with parenthesis, for instance <code>Callable @c = ...; @c();</code> will execute @c, and is the preferred syntax. | Yes |- | [[API/functions/execute_array|execute_array]]() | mixed | valueArray, closure | {{object|CastException}} | Executes the given closure, expanding the value array as individual arguments to the closure. If there are no arguments to be sent to the closure, an empty array can be sent. If the closure returns a value with return(), then that value will be returned with execute. Otherwise, void is returned. | Yes |- | [[API/functions/executeas|executeas]]() | mixed | sender, label, [values...], closure | {{object|CastException}} | Executes the given closure in the context of a given player or ~console. A closure that runs player(), for instance, would return the specified player's name. If null is given, it will execute with the current sender context instead of the closure's. The label argument sets the permission label that this closure will use. If null is given, the closure's label will be used, like with execute(). | Yes |- | [[API/functions/export|export]]() | void | key, value | {{object|IllegalArgumentException}}
{{object|IndexOverflowException}} | Stores a value in the global storage register. An arbitrary value is stored with the given key, and can be retrieved using import. If the value is already stored, it is overwritten. See {{function|import}}. The reference to the value is stored, not a copy of the value, so in the case of arrays, manipulating the contents of the array will manipulate the stored value. An array may be used as a key. It is converted into a string with the array values separated by dots. export() is threadsafe.
([[API/functions/export#Examples|Examples...]]) | Yes |- | [[API/functions/fixed_array|fixed_array]]() | fixed_array | ClassType type, int size, [boolean nullOut] | {{object|RangeException}}
{{object|CastException}} | Creates an array that can hold values of the given type, and is of the given size. The array cannot be resized or retyped later. The array cannot be associative. In general, this isn't meant for normal use, and unless you have specific need for a fixed_size array, array() should be used instead. This is instead meant for writing low level system code. On the other hand, for performance sensitive needs, this may be used instead, though note that most of the API does not accept fixed_arrays (though it does implement ArrayAccess, and so can be used in most read only array based functions), nor will it in the future. This does however map to the underlying system array closely, and so can in particular be used to integrate more directly with the system. fixed_array isn't a particularly flexible type, but it isn't meant to be, it's meant to more directly map to the lower level part of the system. nullOut defaults to true, and in the interpreter is irrelevant, but for native code, if set to true, this loops through the array and sets each value to null (or equivalent for primitive types). This takes additional work, but sets the value to a known state. This can be bypassed if the array is about to be filled from 0 to length, but should otherwise always be set to true. A RangeException is thrown if size is negative, or larger than a 32 bits signed integer. A CastException is thrown when size cannot be cast to an int. | No |- class="hiddenFunction" | [[API/functions/g|g]]() | string | func1, [func2...] | | Groups any number of functions together, and returns void. | No |- | [[API/functions/get_proc|get_proc]]() | Procedure | reference | {{object|IllegalArgumentException}} | Returns a first class reference to the currently in scope procedure. This can be stored in variables and generally passed around, though it cannot be serialized. Keyword usage is preferred, such as <code>proc _asdf;</code> instead of <code>get_proc('_asdf')</code>. Note that this is a special compiler function, and must contain a hardcoded procedure name. | Yes |- | [[API/functions/iclosure|iclosure]]() | iclosure | [params...], code | | Returns a scope isolated closure on the provided code. An iclosure is a datatype that represents some code as code, not the results of some code after it is run. Code placed in an iclosure can be used as a string, or executed by other functions using the execute() function. If a closure is "to string'd" it will not necessarily look like the original code, but will be functionally equivalent. The current environment is "snapshotted" and stored with the closure, however, this information is only stored in memory, it isn't retained during a serialization operation. However, the variable table of the parent scope is not retained, thus making this closure "isolated" from the parent code. The special variable @arguments is automatically created for you, and contains an array of all the arguments passed to the closure, much like procedures. See the wiki article on [[Closures|closures]] for more details and examples.
([[API/functions/iclosure#Examples|Examples...]]) | Yes |- | [[API/functions/import|import]]() | mixed | key, [default] | {{object|IllegalArgumentException}}
{{object|IndexOverflowException}} | This function imports a value from the global value register. It looks for a value stored with the specified key (using the export function), and returns that value. If specified key doesn't exist, it will return either null or the default value if specified. An array may be used as a key. It is converted into a string with the array values separated by dots. import() is threadsafe.
([[API/functions/import#Examples|Examples...]]) | Yes |- | [[API/functions/include|include]]() | void | path | {{object|IncludeException}}
{{object|IOException}} | Includes external code at the specified path. | No |- | [[API/functions/include_dir|include_dir]]() | nothing | directory, [recursive] | | Works like include, but takes a directory, and includes all files within the directory. Recursive defaults to false, but if true, recurses down into all subdirectories as well. As an implementation note, this function is fully resolved at compile time, thus the inputs must be hardcoded. The directories are scanned at compile time, and replaced with individual includes for each .ms file found. | No |- | [[API/functions/instanceof|instanceof]]() | boolean | value, type | | Checks to see if the value is, extends, or implements the given type. Keyword usage is preferred: <code>@value instanceof int</code>. The opposite operation is <code>@value notinstanceof int</code>. [[API/functions/instanceof|See more...]]
([[API/functions/instanceof#Examples|Examples...]]) | No |- | [[API/functions/integer|integer]]() | integer | item | {{object|CastException}} | Returns a new construct that has been cast to an integer. This function will throw a CastException if is_numeric would return false for this item, but otherwise, it will be cast properly. Data may be lost in this conversion. For instance, 4.5 will be converted to 4, by using integer truncation. You can use is_integral to see if this data loss would occur.
([[API/functions/integer#Examples|Examples...]]) | No |- | [[API/functions/is_array|is_array]]() | boolean | item | | Returns whether or not the item is an array
([[API/functions/is_array#Examples|Examples...]]) | No |- | [[API/functions/is_associative|is_associative]]() | boolean | array | {{object|CastException}} | Returns whether or not the array is associative. If the parameter is not an array, throws a CastException.
([[API/functions/is_associative#Examples|Examples...]]) | No |- | [[API/functions/is_boolean|is_boolean]]() | boolean | item | | Returns whether the given item is of the boolean datatype. Note that all datatypes can be used as booleans, however this function checks the specific datatype of the given item.
([[API/functions/is_boolean#Examples|Examples...]]) | No |- | [[API/functions/is_bytearray|is_bytearray]]() | boolean | item | | Returns whether or not the item is actually a ByteArray datatype.
([[API/functions/is_bytearray#Examples|Examples...]]) | No |- | [[API/functions/is_closure|is_closure]]() | boolean | arg | | Returns true if the argument is a closure (could be executed) or false otherwise
([[API/functions/is_closure#Examples|Examples...]]) | No |- | [[API/functions/is_double|is_double]]() | boolean | item | | Returns whether or not the given item is a double. Note that numeric strings and integers can usually be used as a double, however this function checks the actual datatype of the item. If you just want to see if an item can be used as a number, use is_numeric() instead.
([[API/functions/is_double#Examples|Examples...]]) | No |- | [[API/functions/is_integer|is_integer]]() | boolean | item | | Returns whether or not the given item is an integer. Note that numeric strings can usually be used as integers, however this function checks the actual datatype of the item. If you just want to see if an item can be used as a number, use is_integral() or is_numeric() instead.
([[API/functions/is_integer#Examples|Examples...]]) | No |- | [[API/functions/is_integral|is_integral]]() | boolean | item | {{object|CastException}} | Returns true if the numeric value represented by a given double or numeric string could be cast to an integer without losing data (or if it's an integer). For instance, is_numeric(4.5) would return true, and integer(4.5) would work, however, equals(4.5, integer(4.5)) returns false, because the value was narrowed to 4.
([[API/functions/is_integral#Examples|Examples...]]) | No |- | [[API/functions/is_null|is_null]]() | boolean | item | | Returns whether or not the given item is null.
([[API/functions/is_null#Examples|Examples...]]) | No |- | [[API/functions/is_number|is_number]]() | boolean | item | | Returns whether or not the given item is an integer or a double. Note that numeric strings can usually be used as integers and doubles, however this function checks the actual datatype of the item. If you just want to see if an item can be used as a number, use is_integral() or is_numeric() instead.
([[API/functions/is_number#Examples|Examples...]]) | No |- | [[API/functions/is_numeric|is_numeric]]() | boolean | item | | Returns false if the item would fail if it were used as a numeric value. If it can be parsed or otherwise converted into a numeric value, true is returned.
([[API/functions/is_numeric#Examples|Examples...]]) | No |- | [[API/functions/is_proc|is_proc]]() | boolean | procName | | Returns whether or not the given procName is currently defined, i.e. if calling this proc wouldn't throw an exception. | Yes |- | [[API/functions/is_string|is_string]]() | boolean | item | | Returns whether or not the item is actually a string datatype. If you just care if some data can be used as a string, use is_stringable().
([[API/functions/is_string#Examples|Examples...]]) | No |- | [[API/functions/is_stringable|is_stringable]]() | boolean | item | | Returns whether or not the item is convertable to a string. Everything but arrays can be used as strings.
([[API/functions/is_stringable#Examples|Examples...]]) | No |- class="hiddenFunction" | [[API/functions/mutable_primitive|mutable_primitive]]() | mutable_primitive | [primitive_value] | {{object|FormatException}} | Creates a mutable primitive object, initially setting the value of the object to null, or the specified value. The value must be a primitive value, and cannot be an array or object. [[API/functions/mutable_primitive|See more...]]
([[API/functions/mutable_primitive#Examples|Examples...]]) | No |- | [[API/functions/parse_int|parse_int]]() | int | value, radix | {{object|CastException}}
{{object|RangeException}}
{{object|FormatException}} | Converts a string representation of an integer to a real integer, given the value's radix (base). See {{function|to_radix}} for a more detailed explanation of number theory. Radix must be between 2 and 36, inclusive.
([[API/functions/parse_int#Examples|Examples...]]) | No |- | [[API/functions/proc|proc]]() | void | procName, [params...], procCode | {{object|FormatException}} | Creates a new user defined procedure (also known as "function"), with the given name and parameters, that can be called later in code. The name of the procedure must be a constant and its parameters must be variables. Please see the more detailed documentation on procedures for more information. In general, brace syntax and keyword usage is preferred: proc _myProc(@a, @b){ procCode(@a, @b); } | No |- class="hiddenFunction" | [[API/functions/rclosure|rclosure]]() | closure | [params...], code | | Returns a non-linking closure on the provided code. The same rules apply for closures, except the top level internal code does not check for proper linking at compile time, and instead links at runtime. Lexer errors and some other compile time checks ARE done however, but functions are not optimized or linked. This is used for remote code execution, since the remote platform may have some functionality unavailable on this current platform.
([[API/functions/rclosure#Examples|Examples...]]) | Yes |- | [[API/functions/string|string]]() | string | item | | Creates a new construct that is the "toString" of an item. For arrays, an human readable version is returned; this should not be used directly, as the format is not guaranteed to remain consistent. Booleans return "true" or "false" and null returns "null". Strings (and subclasses of strings) are simply returned as is.
([[API/functions/string#Examples|Examples...]]) | No |- | [[API/functions/to_radix|to_radix]]() | string | value, radix | {{object|CastException}}
{{object|RangeException}}
{{object|FormatException}} | Given an int and a radix, returns a string representation of the integer value in the given base. A common use would be to output a hex or binary representation of a number, for instance. [[API/functions/to_radix|See more...]]
([[API/functions/to_radix#Examples|Examples...]]) | No |- | [[API/functions/typeof|typeof]]() | ClassType | arg | | Returns a ClassType value of the typeof a value. For instance 'array' is returned for typeof(array()). This is a generic replacement for the is_* series of functions.
([[API/functions/typeof#Examples|Examples...]]) | No |} == DataTransformations ==
This class provides functions that are able to transform data from native objects to their serialized forms, i.e. json, ini, etc.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/ini_decode|ini_decode]]()
| array
| string
| {{object|FormatException}}
| Returns an array, given an INI format input. INI files are loosely defined as a set of key->value pairs, which lends itself to an associative array format. Key value pairs are denoted usually by a <code>key=value</code> format. The specific rules for decoding an INI file can be found [http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.Reader%29 here]. An associative array is returned. All values are stored as strings, so if 1 was stored, it will be returned as a string '1'. This is a limitation of the ini format, as it is expected that the code that reads the ini knows what the type of the data is anticipated, not the data itself. You can easily cast data that is expected to be numeric via the {{function|integer}} and {{function|double}} functions when reading in the data if exact types are truly needed. INI doesn't easily support non-string values, if that is needed, consider using {{function|json_encode}}/{{function|json_decode}} instead.
| No
|-
| [[API/functions/ini_encode|ini_encode]]()
| string
| array, [comment]
| {{object|FormatException}}{{object|CastException}} | Encodes an array into an INI format output. An associative array is expected, and a format exception is thrown if it is a normal array. The comment is optional, but if provided will be added to the header of the returned string. Inner arrays cannot be stored, and will throw a CastException if attempted. Nulls are encoded as an empty string, so when reading the value back in, the difference between '' and null is lost. All values are stored as strings, so if 1 is stored, it will be returned as a string '1'. This is a limitation of the ini format, as it is expected that the code that reads the ini knows what the type of the data is anticipated, not the data itself. | No |- | [[API/functions/json_decode|json_decode]]() | array | string | {{object|FormatException}} | Takes a JSON encoded string, and returns an array, either normal or associative, depending on the contents of the JSON string. If the JSON string is improperly formatted, a FormatException is thrown.
([[API/functions/json_decode#Examples|Examples...]]) | No |- | [[API/functions/json_encode|json_encode]]() | string | array | {{object|CastException}} | Converts an array into a JSON encoded string. Both normal and associative arrays are supported. Within the array, only primitives and arrays can be encoded.
([[API/functions/json_encode#Examples|Examples...]]) | No |- | [[API/functions/parse_text_table|parse_text_table]]() | array | string table, [array options] | {{object|FormatException}}
{{object|CastException}} | Parses tabular data into an array [[API/functions/parse_text_table|See more...]]
| No |- | [[API/functions/xml_read|xml_read]]() | mixed | xml, xpath | {{object|FormatException}} | Reads a field from some xml using an XPath address. The XPath address is assumed to be absolute, even if it doesn't start with a '/'. | No |- | [[API/functions/yml_decode|yml_decode]]() | array | string | {{object|FormatException}}
{{object|PluginInternalException}} | Takes a YML encoded string, and returns an associative array, depending on the contents of the YML string. If the YML string is improperly formatted, a FormatException is thrown. If an exception occurs in the YML parsing library, a PluginInternalException is thrown. By default YML strings up to 3 * 1024 * 1024 (3 MB) code points can be parsed. This limit can be exceeded through the 'function.yml_decode.code_point_limit' runtime setting. | No |- | [[API/functions/yml_encode|yml_encode]]() | string | array, [prettyPrint] | {{object|CastException}} | Converts an array into a YML encoded string. Only associative arrays are supported. prettyPrint defaults to false. Within the array, only primitives and arrays can be encoded. | No |} == Debug ==
Provides methods for viewing data about both CommandHelper and the other plugins in your server. Though not meant to be called by normal scripts, these methods are available everywhere other methods are available. Note that for some of these functions to even work, play-dirty mode must set to on. These are most useful in conjunction with interpreter mode.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/always_trace|always_trace]]()
| void
| ivar
| {{object|CastException}}
| Outputs debug information about a variable to standard out. Unlike {{function|debug}}, this only accepts an ivar; it is a meta function. The runtime will then take the variable, and output information about it, in a human readable format, including the variable's defined type, actual type, name and value.([[API/functions/always_trace#Examples|Examples...]]) | Yes |- | [[API/functions/debug|debug]]() | void | message | {{object|IOException}} | Manually logs a timestamped message to the debug log and the console, if debug-mode is set to true in the preferences | Yes |- | [[API/functions/dump_threads|dump_threads]]() | array | | | Returns an array of all thread names that are currently running in the JVM. This is a debugging tool for your server, and less of a CommandHelper specific thing. | Yes |- | [[API/functions/heap_dump|heap_dump]]() | void | | {{object|PluginInternalException}} | Creates a heap dump file, and places it in the working directory, as "dump.hprof". This might throw a PluginInternalException if the heap dump tools aren't available in your JVM. Once dumped, the heap dump can be analyzed using tools such as jhat. More information about jhat can be found [http://docs.oracle.com/javase/6/docs/technotes/tools/share/jhat.html here]. | Yes |- | [[API/functions/set_debug_output|set_debug_output]]() | void | booleanValue | | Turns verbose debug output on or off. This should generally never be on in a production server, but can be useful to quickly trace what a script is doing when it runs in a test environment. When on, every single function call will be printed out, along with the parameters passed in to it. To reduce impact on scripts when this is disabled, this has been implemented as a system wide setting, and applies to all scripts running in the same system. | Yes |- | [[API/functions/trace|trace]]() | void | ivar | {{object|CastException}} | Works like {{function|always_trace}}, but only if debug-mode is enabled in the preferences. See {{function|always_trace}} for details of the output.
([[API/functions/trace#Examples|Examples...]]) | Yes |} == Easings ==
Easing related functions. Easings are based on the easings listed at http://easings.net, with the addition of the LINEAR easing, which just returns x.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/ease_between_loc|ease_between_loc]]()
| array
| array start, array finish, EasingType type, double x
| {{object|CastException}}
| Given an easing type, and a duration percentage x, returns the given resulting interpolated distance. [[API/functions/ease_between_loc|See more...]]([[API/functions/ease_between_loc#Examples|Examples...]]) | No |- | [[API/functions/easing|easing]]() | double | EasingType type, double x | {{object|CastException}} | Given an easing type, and a duration percentage x, returns the given resulting interpolation value. [[API/functions/easing|See more...]]
([[API/functions/easing#Examples|Examples...]]) | No |} == Echoes ==
These functions allow you to echo information to the screen
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/action_msg|action_msg]]()
| void
| [player], message
| {{object|PlayerOfflineException}}{{object|LengthException}} | Sends a message to the action bar above the hot bar. | Yes |- | [[API/functions/broadcast|broadcast]]() | void | message, [permission]
message, [recipients] | {{object|FormatException}} | Broadcasts a message to all or some players and/or console. If permission is given, only players with that permission and console will see the broadcast. If an array of recipients is given, only online players in the list will see the broadcast. Console will receive the broadcast only when the array contains case-insensitive '~console'. Offline players and duplicate recipients in the list will be ignored. If permission/recipients is null, all players and console will see the broadcast. Throws FormatException when the given recipients array is associative. | Yes |- | [[API/functions/chat|chat]]() | void | string | {{object|PlayerOfflineException}} | Echoes string to the chat, as if the user simply typed something into the chat bar. This function cannot be run from console, a PlayerOfflineException is thrown if attempted. Use broadcast() instead. | Yes |- | [[API/functions/chatas|chatas]]() | void | player, msg | {{object|PlayerOfflineException}}
{{object|LengthException}} | Sends a chat message to the server, as the given player. Otherwise the same as the chat() function | Yes |- | [[API/functions/color|color]]() | string | name | | Returns the color (or style) code modifier for a given value. If the value isn't valid, white is used instead. The list of valid color names is: BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE, RANDOM, BOLD, STRIKETHROUGH, UNDERLINE, ITALIC, or PLAIN_WHITE. Other supported values include the color integers 0-15, the color hex numbers 0-F, and the style values k, l, m, n, o, and r. Additionally, any RGB color can be used in the hex format '#rrggbb' (except in tellraw). [[API/functions/color|See more...]]
| No |- | [[API/functions/colorize|colorize]]() | mixed | text, [symbol] | | Replaces all the colorizable character codes in the string. For instance, colorize('&aText') would be equivalent to (color('a').'Text'). By default, the symbol is '&', but that can be any arbitrary string that you specify. If text is not a string, that value is simply returned. If you need to "escape" a symbol, (that is have a literal symbol followed by a letter that is a valid color) just repeat the symbol twice, for instance '&&c' would return a literal '&c' instead of a red modifier. Additionally, any RGB color can be used in the hex format '&#rrggbb' (except in tellraw). [[API/functions/colorize|See more...]]
| No |- | [[API/functions/console|console]]() | void | message, [prefix] | {{object|CastException}} | Logs a message to the console. If prefix is true, prepends "CommandHelper:" to the message. Default is true. If you wish to set the default value of prefix to false, use set_runtime_setting('function.console.prefix_default', false). | Yes |- | [[API/functions/msg|msg]]() | void | var1, [var2...] | {{object|PlayerOfflineException}} | Echoes a message to the player running the command | No |- | [[API/functions/strip_colors|strip_colors]]() | string | toStrip | | Strips all the color codes from a given string | No |- | [[API/functions/tellraw|tellraw]]() | void | [string selector], array raw | {{object|CastException}} | A thin wrapper around the tellraw command from console context, this simply passes the input to the command. The raw is passed in as a normal (possibly associative) array, and json encoded. No validation is done on the input, so the command may fail. If not provided, the selector defaults to @a. Do not use double quotes (smart string) when providing the selector. See {{function|ptellraw}} if you need player context. [[API/functions/tellraw|See more...]]
([[API/functions/tellraw#Examples|Examples...]]) | Yes |- | [[API/functions/title|title]]() | void | [player], title, subtitle, [fadein, stay, fadeout] | {{object|PlayerOfflineException}}
{{object|CastException}}
{{object|RangeException}}
{{object|LengthException}} | Shows a title and/or subtitle to a player. The title and subtitle parameters can be null. The integers fadein, stay, and fadeout define the time in ticks that the title will be displayed. The defaults are 10, 70, and 20 respectively. | Yes |- | [[API/functions/tmsg|tmsg]]() | void | player, msg, [...] | {{object|PlayerOfflineException}}
{{object|InsufficientArgumentsException}}
{{object|LengthException}} | Displays a message on the specified players screen, similar to msg, but targets a specific user. | Yes |} == Enchantments ==
Provides methods for dealing with enchanted items
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/can_enchant_item|can_enchant_item]]()
| boolean
| name, item
| {{object|EnchantmentException}}{{object|FormatException}}
{{object|CastException}}
{{object|RangeException}}
{{object|NotFoundException}} | Given an enchantment name and an item array, returns whether or not that item can be enchanted with that enchantment. Throws an EnchantmentException if the name is not a valid enchantment type. | No |- | [[API/functions/enchant_item|enchant_item]]() | void | [player], slot, type, level
player, slot, enchantsArray | {{object|CastException}}
{{object|EnchantmentException}}
{{object|PlayerOfflineException}} | Adds enchantments to an item in the player's inventory. A single enchantment type and level can be specified or an enchantment array may be given. If slot is null, the currently selected slot is used. If an enchantment cannot be applied to the specified item, an EnchantmentException is thrown. The enchantment array must have the enchantment as keys and levels as the values. (eg. array('unbreaking': 1)) The level parameter can be a number or a roman numeral. [[API/functions/enchant_item|See more...]]
| Yes |- | [[API/functions/enchantment_list|enchantment_list]]() | array | | | Returns an informational list of all valid enchantment names. Note that this will simply cover all enchantment types, but may not be a comprehensive list of names that can be accepted, there may be more, however, the list returned here is "comprehensive" and "official". Additionally, this may vary from server type to server type. | No |- | [[API/functions/get_enchant_max|get_enchant_max]]() | int | name | {{object|EnchantmentException}} | Given an enchantment name, returns the max level it can be. If name is not a valid enchantment, an EnchantException is thrown. | No |- | [[API/functions/get_enchants|get_enchants]]() | array | item | {{object|FormatException}}
{{object|CastException}}
{{object|RangeException}}
{{object|NotFoundException}} | Given an item array, returns the enchantments that can be validly added to this item. This may return an empty array. | No |- | [[API/functions/get_item_enchants|get_item_enchants]]() | array | [player], slot | {{object|PlayerOfflineException}}
{{object|CastException}} | Returns an array of arrays of the enchantments and their levels on the given item. For example: array('sharpness': 1, 'unbreaking': 3). | Yes |- | [[API/functions/is_enchantment|is_enchantment]]() | boolean | name | | Returns true if this name is a valid enchantment type. | No |- | [[API/functions/remove_item_enchant|remove_item_enchant]]() | void | [player], slot, type | {{object|CastException}}
{{object|EnchantmentException}}
{{object|PlayerOfflineException}} | Removes an enchantment from an item. The type may be a valid enchantment, or an array of enchantment names. It can also be null, and all enchantments will be removed. If an enchantment is specified, and the item is not enchanted with that, it is simply ignored. | Yes |} == EntityManagement ==
This class of functions allow entities to be managed.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/add_scoreboard_tag|add_scoreboard_tag]]()
| boolean
| entityUUID, tag
| {{object|FormatException}}{{object|LengthException}}
{{object|BadEntityException}} | Adds a tag to the entity. Returns whether or not it was successful. | Yes |- | [[API/functions/all_entities|all_entities]]() | array | [world, [x, z]]
[locationArray] | {{object|InvalidWorldException}}
{{object|FormatException}}
{{object|CastException}} | Returns an array of IDs for all entities in the given scope. With no args, this will return all entities loaded on the entire server. If the first argument is given and is a location, only entities in the chunk containing that location will be returned, or if it is a world only entities in that world will be returned. If all three arguments are given, only entities in the chunk with those coords will be returned. This can take chunk coords (ints) or location coords (doubles).
([[API/functions/all_entities#Examples|Examples...]]) | Yes |- | [[API/functions/drop_item|drop_item]]() | string | [player/LocationArray], itemArray, [spawnNaturally] | {{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|InvalidWorldException}} | Drops the specified item stack at the specified player's feet (or at an arbitrary Location, if an array is given), and returns its entity UUID. spawnNaturally takes a boolean, which forces the way the item will be spawned. If true, the item will be dropped with a random velocity. | Yes |- | [[API/functions/entities_in_radius|entities_in_radius]]() | array | locationArray, distance, [type]
locationArray, distance, [arrayTypes] | {{object|CastException}}
{{object|BadEntityException}}
{{object|FormatException}}
{{object|RangeException}} | Returns an array of all entities within the given distance from the location. Set type argument to filter entities to a specific entity type. You can pass an array of types. [[API/functions/entities_in_radius|See more...]]
| Yes |- | [[API/functions/entity_exists|entity_exists]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if entity exists, otherwise false. | Yes |- | [[API/functions/entity_fall_distance|entity_fall_distance]]() | double | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the distance the entity has fallen. | Yes |- | [[API/functions/entity_grounded|entity_grounded]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | returns whether the entity is touching the ground | Yes |- | [[API/functions/entity_in_water|entity_in_water]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether an entity is colliding with water. This accounts for waterlogged blocks, bubble columns, and fluid height. It does not account for water cauldrons. | Yes |- | [[API/functions/entity_loc|entity_loc]]() | locationArray | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the location array for this entity, if it exists. This array will be compatible with any function that expects a location.
([[API/functions/entity_loc#Examples|Examples...]]) | Yes |- | [[API/functions/entity_onfire|entity_onfire]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the number of seconds until this entity stops being on fire, 0 if it already isn't. | Yes |- | [[API/functions/entity_remove|entity_remove]]() | void | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Removes the specified entity from the world, without any drops or animations. Note: you can't remove players. As a safety measure for working with NPC plugins, it will not work on anything human, even if it is not a player. | Yes |- | [[API/functions/entity_spec|entity_spec]]() | array | entityID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an associative array containing all the data of the given entity that are too specific to have its own function. [[API/functions/entity_spec|See more...]]
| Yes |- | [[API/functions/entity_type|entity_type]]() | string | entityUUID | {{object|CastException}} | Returns the EntityType of the entity with the specified ID. Returns null if the entity does not exist. | Yes |- | [[API/functions/entity_velocity|entity_velocity]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an entity's motion vector represented as an associative array with the the keys x, y, and z. As a convenience, the magnitude is also included.
([[API/functions/entity_velocity#Examples|Examples...]]) | Yes |- | [[API/functions/get_art_at|get_art_at]]() | string | locationArray | {{object|BadEntityException}}
{{object|FormatException}} | Gets the specified art at the given location. If the item at the specified location isn't a painting, an [[API/functions/get_art_at|See more...]]
| Yes |- | [[API/functions/get_display_entity|get_display_entity]]() | array | entityUUID | {{object|BadEntityException}}
{{object|LengthException}}
{{object|FormatException}} | Returns an associative array of display entity data. Array keys are: 'billboard', 'brightness', 'glowcolor', 'height', 'width', 'viewrange', 'shadowradius', 'shadowstrength', 'teleportduration', and 'transformation'. [[API/functions/get_display_entity|See more...]]
| Yes |- | [[API/functions/get_entity_age|get_entity_age]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the entity age as an integer, represented by server ticks. | Yes |- | [[API/functions/get_entity_freezing|get_entity_freezing]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the number of ticks the entity has been freezing in powdered snow. (MC 1.17+) Counts down by 2 every tick when entity is thawing. | Yes |- | [[API/functions/get_entity_glowing|get_entity_glowing]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if the entity is glowing | Yes |- | [[API/functions/get_entity_gravity|get_entity_gravity]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if gravity applies to the entity. | Yes |- | [[API/functions/get_entity_invulnerable|get_entity_invulnerable]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if the entity cannot be damaged | Yes |- | [[API/functions/get_entity_max_speed|get_entity_max_speed]]() | double | entityUUID | {{object|BadEntityException}}
{{object|BadEntityTypeException}}
{{object|LengthException}} | Returns a max speed for given entity. Make sure that the entity is a minecart. | Yes |- | [[API/functions/get_entity_rider|get_entity_rider]]() | string | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the UUID of the given entity's rider, or null if it doesn't have one. If there are multiple riders, only the first is returned. | Yes |- | [[API/functions/get_entity_riders|get_entity_riders]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an array of UUIDs for the given entity's riders. | Yes |- | [[API/functions/get_entity_saves_on_unload|get_entity_saves_on_unload]]() | void | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Gets whether the entity will be saved to disk when it is unloaded. | Yes |- | [[API/functions/get_entity_silent|get_entity_silent]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if the entity produces sounds | Yes |- | [[API/functions/get_entity_transient_id|get_entity_transient_id]]() | int | uuid | {{object|LengthException}}
{{object|BadEntityException}} | Given a permanent entity uuid, returns the transient entity id. This should not be stored, as it is reset every restart, and is only useful for dealing with low level packets. | No |- | [[API/functions/get_entity_vehicle|get_entity_vehicle]]() | string | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the UUID of the given entity's vehicle, or null if none exists. | Yes |- | [[API/functions/get_hanging_direction|get_hanging_direction]]() | string | entityUUID | {{object|BadEntityException}}
{{object|LengthException}}
{{object|FormatException}} | Returns the direction a hanging entity is facing. | Yes |- | [[API/functions/get_mob_name|get_mob_name]]() | string | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the name of the given mob. | Yes |- | [[API/functions/get_name_visible|get_name_visible]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether or not a mob's custom name is always visible. If this is true it will be as visible as player names, otherwise it will only be visible when near the mob. | Yes |- | [[API/functions/get_projectile_bounce|get_projectile_bounce]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns if the given projectile should bounce when it hits something. (deprecated) | Yes |- | [[API/functions/get_projectile_item|get_projectile_item]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the displayed item for some projectiles. This can be used on throwable projectiles (snowballs, eggs, exp bottles, enderpearls) as well as large and small fireballs. | Yes |- | [[API/functions/get_projectile_shooter|get_projectile_shooter]]() | mixed | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the shooter of the given projectile, can be null. If the shooter is an entity, that entity's ID will be return, but if it is a block, that block's location will be returned. | Yes |- | [[API/functions/get_scoreboard_tags|get_scoreboard_tags]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an array of scoreboard tags for this entity. | Yes |- | [[API/functions/get_transformation_from_matrix|get_transformation_from_matrix]]() | array | array matrix
float f0, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15 | {{object|LengthException}} | Converts a Minecraft transformation matrix into a transformation object. This is the same underlying algorithm that set_display_entity uses when accepting a transformation matrix. | No |- | [[API/functions/has_scoreboard_tag|has_scoreboard_tag]]() | boolean | entityUUID, tag | {{object|BadEntityException}}
{{object|LengthException}}
{{object|FormatException}} | Returns whether this entity has a specific tag. | Yes |- | [[API/functions/is_entity_living|is_entity_living]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if entity is living, otherwise false. | Yes |- | [[API/functions/is_tameable|is_tameable]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true or false if the specified entity is tameable | Yes |- | [[API/functions/launch_firework|launch_firework]]() | string | locationArray, [optionsArray] | {{object|FormatException}}
{{object|RangeException}}
{{object|InvalidWorldException}} | Launches a firework rocket. The location array specifies where it is launched from, and the options array is an associative array described below. All parameters in the array are optional, and default to the specified values if not set. The default options being set will make it look like a normal firework, with a white explosion. Returns the firework rocket entity's UUID. [[API/functions/launch_firework|See more...]]
| Yes |- | [[API/functions/play_entity_effect|play_entity_effect]]() | void | entityUUID, effect | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Plays the given visual effect on the entity. Non-applicable effects simply won't happen. Note: the death effect makes the mob invisible to players and immune to melee attacks. When used on players, they are shown the respawn menu, but because they are not actually dead, they can only log out. [[API/functions/play_entity_effect|See more...]]
| Yes |- | [[API/functions/remove_scoreboard_tag|remove_scoreboard_tag]]() | boolean | entityUUID, tag | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Removes a tag from the entity. Returns whether or not it was successful. | Yes |- | [[API/functions/set_art_at|set_art_at]]() | boolean | locationArray, art | {{object|FormatException}} | Sets the art at the specified location. If the art doesn't fit, nothing happens, and false is returned. Otherwise, true is returned. [[API/functions/set_art_at|See more...]]
| Yes |- | [[API/functions/set_display_entity|set_display_entity]]() | void | entityUUID, array | {{object|BadEntityException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|IllegalArgumentException}}
{{object|CastException}}
{{object|RangeException}} | Sets the data for a display entity. See {{function|get_display_entity}} for details about the array format. [[API/functions/set_display_entity|See more...]]
| Yes |- | [[API/functions/set_entity_age|set_entity_age]]() | void | entityUUID, int | {{object|CastException}}
{{object|BadEntityException}}
{{object|RangeException}}
{{object|LengthException}} | Sets the age of the entity to the specified int, represented by server ticks. Entity age cannot be less than 1 server tick, | Yes |- | [[API/functions/set_entity_fall_distance|set_entity_fall_distance]]() | void | entityUUID, double | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the distance the entity has fallen. | Yes |- | [[API/functions/set_entity_freezing|set_entity_freezing]]() | void | entityUUID, int | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}}
{{object|RangeException}} | Sets how many server ticks the entity has been freezing. (MC 1.17+) Must be above zero, and will clamp to the maximum the server allows. | Yes |- | [[API/functions/set_entity_glowing|set_entity_glowing]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | If true, applies glowing effect to the entity | Yes |- | [[API/functions/set_entity_gravity|set_entity_gravity]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets whether or not gravity applies to the entity. | Yes |- | [[API/functions/set_entity_invulnerable|set_entity_invulnerable]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | If set to true the entity cannot be damaged, except by players in creative mode | Yes |- | [[API/functions/set_entity_loc|set_entity_loc]]() | boolean | entityUUID, locationArray | {{object|BadEntityException}}
{{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|LengthException}}
{{object|IllegalArgumentException}} | Teleports the entity to the given location and returns whether the action was successful. Note this can set both location and direction. On paper servers, this teleports passengers along with the entity.
([[API/functions/set_entity_loc#Examples|Examples...]]) | Yes |- | [[API/functions/set_entity_max_speed|set_entity_max_speed]]() | void | entityUUID | {{object|BadEntityException}}
{{object|BadEntityTypeException}}
{{object|CastException}}
{{object|LengthException}} | Sets a max speed for given entity. Make sure that the entity is a minecart. | Yes |- | [[API/functions/set_entity_onfire|set_entity_onfire]]() | void | entityUUID, seconds | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the entity on fire for the given number of seconds. Throws a RangeException if seconds is less than 0 or greater than 107374182. | Yes |- | [[API/functions/set_entity_rider|set_entity_rider]]() | boolean | horse, rider | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the way two entities are stacked. Horse and rider are entity ids. If rider is null, horse will eject its current rider, if it has one. If horse is null, rider will leave whatever it is riding. If horse and rider are both valid entities, rider will ride horse. The function returns the success of whatever operation is done. If horse and rider are both null, or otherwise the same, a FormatException is thrown. If a horse already has a rider, this will add the new rider without ejecting the existing one. | Yes |- | [[API/functions/set_entity_rotation|set_entity_rotation]]() | void | entityUUID, yaw, [pitch] | {{object|UnsupportedOperationException}}
{{object|LengthException}} | Sets an entity's yaw and pitch without teleporting or ejecting. If used on a player, an UnsupportedOperationException is thrown. | Yes |- | [[API/functions/set_entity_saves_on_unload|set_entity_saves_on_unload]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets whether the entity is saved to disk when it is unloaded. By default an entity is saved. Setting this to false disables that. Can be used on players to disable player data saving on quit. | Yes |- | [[API/functions/set_entity_silent|set_entity_silent]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets whether or not entity produces sounds | Yes |- | [[API/functions/set_entity_spec|set_entity_spec]]() | void | entityUUID, specArray | {{object|CastException}}
{{object|BadEntityException}}
{{object|IndexOverflowException}}
{{object|IndexOverflowException}}
{{object|RangeException}}
{{object|FormatException}}
{{object|LengthException}}
{{object|InvalidWorldException}} | Sets the data in the specArray to the given entity. The specArray must follow the same format as entity_spec(). See the documentation for that function for info on available options. All indices in the specArray are optional. | Yes |- | [[API/functions/set_entity_velocity|set_entity_velocity]]() | void | entityUUID, array | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}}
{{object|IllegalArgumentException}} | Sets the velocity of this entity according to the supplied xyz array. All 3 values default to 0, so an empty array will simply stop the entity's motion. Both normal and associative arrays are accepted.
([[API/functions/set_entity_velocity#Examples|Examples...]]) | Yes |- | [[API/functions/set_hanging_direction|set_hanging_direction]]() | void | entityUUID, direction, [force] | {{object|BadEntityException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|IllegalArgumentException}} | Sets the direction a hanging entity is facing. Valid directions are NORTH, SOUTH, EAST, and WEST. UP and DOWN are also valid for item frames. A hanging will not change direction if there's no supporting block in the new position. However, the 'force' parameter can be set to true to override this behavior. While leash hitches are technically hangings, they don't support different directions. | Yes |- | [[API/functions/set_mob_name|set_mob_name]]() | void | entityUUID, name | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the name of the given mob. This automatically truncates if it is more than 64 characters. | Yes |- | [[API/functions/set_name_visible|set_name_visible]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the visibility of a mob's custom name. True means it will be visible from a distance, like a playername. False means it will only be visible when near the mob. | Yes |- | [[API/functions/set_projectile_bounce|set_projectile_bounce]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets if the given projectile should bounce when it hits something. (deprecated) | Yes |- | [[API/functions/set_projectile_item|set_projectile_item]]() | void | entityUUID, itemArray | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the displayed item for some projectiles. This can be used on throwable projectiles (snowballs, eggs, exp bottles, enderpearls) as well as large and small fireballs. | Yes |- | [[API/functions/set_projectile_shooter|set_projectile_shooter]]() | void | entityUUID, shooter | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the shooter of the given projectile. This can be an entity UUID, dispenser location array (throws CastException if not a dispenser), or null. | Yes |- | [[API/functions/shoot_projectile|shoot_projectile]]() | string | [entity[, projectile]]
player, projectile, target[, speed] | {{object|BadEntityException}}
{{object|BadEntityTypeException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Shoots an entity from the specified location (can be an entity UUID, player name or location array), or the current player if no arguments are passed. If no entity type is specified, it defaults to a fireball. If provide three arguments, with target (entity UUID, player name or location array), entity will shoot to target location. Last, fourth argument, is double and specifies the speed of projectile. Returns the UUID of the entity. | Yes |- | [[API/functions/spawn_entity|spawn_entity]]() | array | entityType, [qty], [location], [closure] | {{object|CastException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|PlayerOfflineException}}
{{object|IllegalArgumentException}} | Spawns the specified number of entities of the given type at the given location. Returns an array of entity UUIDs of what is spawned. Qty defaults to 1 and location defaults to the location of the commandsender, if it is a block or player. If the commandsender is console, location must be supplied. [[API/functions/spawn_entity|See more...]]
([[API/functions/spawn_entity#Examples|Examples...]]) | Yes |} == Environment ==
Allows you to manipulate the environment around the player
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/bone_meal_block|bone_meal_block]]()
| boolean
| locationArray
| {{object|CastException}}{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|RangeException}} | Applies bone meal to a block, if possible. Returns true if it was successfully applied, as some block types cannot be bone-mealed. | Yes |- | [[API/functions/break_block|break_block]]() | boolean | locationArray, [itemArray] | {{object|FormatException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|RangeException}} | Mostly simulates a block break at a location. Optional item array to simulate tool used to break block. Returns true if block was not already air and either no tool was given, a correct tool was given, or the block type does not require a specific tool. Does not trigger an event. | Yes |- | [[API/functions/explosion|explosion]]() | boolean | locationArray, [size], [safe], [fire], [source] | {{object|FormatException}}
{{object|CastException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|RangeException}}
{{object|BadEntityException}} | Creates an explosion at a location. Size defaults to size of a creeper (3), where 0 does no damage to entities. If safe is true (defaults to false) the explosion won't break blocks. If fire is true (defaults to true unless safe is true), the explosion may leave behind fire. The source must be an entity UUID, which can be used for block and entity damage attribution. The explosion will not damage source entity. Returns false if the explosion was canceled. | Yes |- | [[API/functions/generate_tree|generate_tree]]() | boolean | locationArray, [treeType] | {{object|CastException}}
{{object|BadEntityException}}
{{object|FormatException}} | Generates a tree at the given location and returns if the generation succeeded or not. The treeType can be TREE, BIG_TREE, REDWOOD, TALL_REDWOOD, BIRCH, JUNGLE, SMALL_JUNGLE, JUNGLE_BUSH, RED_MUSHROOM, BROWN_MUSHROOM, SWAMP, ACACIA, DARK_OAK, COCOA_TREE, MEGA_REDWOOD, MEGA_PINE, TALL_BIRCH, CHORUS_PLANT, CRIMSON_FUNGUS, WARPED_FUNGUS, AZALEA, MANGROVE, TALL_MANGROVE, CHERRY, PALE_OAK, or PALE_OAK_CREAKING, defaulting to TREE. | Yes |- | [[API/functions/get_banner_patterns|get_banner_patterns]]() | array | array location | {{object|FormatException}} | Returns the banner pattern information for the standing banner at the given location. This will be an array of items containing the "color" and "shape" parameters. [[API/functions/get_banner_patterns|See more...]]
| Yes |- | [[API/functions/get_biome|get_biome]]() | string | locationArray | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Returns the biome type at a block location. [[API/functions/get_biome|See more...]]
| Yes |- | [[API/functions/get_block|get_block]]() | string | locationArray | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Gets the type the block at the location. | Yes |- | [[API/functions/get_block_command|get_block_command]]() | string | locationArray | {{object|CastException}}
{{object|FormatException}} | Returns the command string in the Command Block at the given location. | Yes |- | [[API/functions/get_block_info|get_block_info]]() | mixed | locationArray, [index] | {{object|CastException}}
{{object|FormatException}} | Returns an associative array with various information about a block. If an index is specified, it will return a boolean. [[API/functions/get_block_info|See more...]]
| Yes |- | [[API/functions/get_block_light_at|get_block_light_at]]() | int | locationArray | {{object|CastException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Returns the block light level at a location. This counts block sources like torches and lava, disregarding light from the sky. | No |- | [[API/functions/get_block_lock|get_block_lock]]() | string | locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Returns the string lock for this block if its lockable. [[API/functions/get_block_lock|See more...]]
| Yes |- | [[API/functions/get_block_power|get_block_power]]() | int | locationArray | {{object|CastException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Returns the redstone power level that is supplied to this block [0-15]. If is_block_powered(locationArray, 'DIRECT_ONLY') returns true, a redstone dust placed at the given location would be powered the return value - 1. | No |- | [[API/functions/get_blockdata|get_blockdata]]() | array | locationArray | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Gets the block data as an array at the location. | Yes |- | [[API/functions/get_blockdata_string|get_blockdata_string]]() | string | locationArray | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Gets the block data at the location in a string format. Forward compatibility is not ensured. | Yes |- | [[API/functions/get_command_block_name|get_command_block_name]]() | string | locationArray | {{object|CastException}}
{{object|FormatException}} | Returns the name of the Command Block at the given location. | Yes |- | [[API/functions/get_decorated_pot_sherds|get_decorated_pot_sherds]]() | array | locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Returns an associative array of sherds for each side of a decorated pot. The keys for each side are 'front', 'back', 'left', and 'right'. The values are one of any sherd materials or a brick if there's no decoration on that side. | Yes |- | [[API/functions/get_highest_block_at|get_highest_block_at]]() | array | x, z, [world]
locationArray, [world] | {{object|FormatException}}
{{object|CastException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Gets a location array for the highest block at a specific x and z column. If a location array is specified, the y coordinate is ignored. | Yes |- | [[API/functions/get_light_at|get_light_at]]() | int | locationArray | {{object|CastException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Returns the combined light level at a block, taking into account all sources. | No |- | [[API/functions/get_sign_text|get_sign_text]]() | array | locationArray, [side] | {{object|RangeException}}
{{object|FormatException}} | Gets an array of 4 strings of the text on the side of a sign. Side can be FRONT (default) or BACK. (MC 1.20+) If the location given isn't a sign, then a RangeException is thrown. | Yes |- | [[API/functions/get_skull_owner|get_skull_owner]]() | array | locationArray | {{object|RangeException}}
{{object|FormatException}} | Returns the owner name and uuid of the skull at the given location as an array in format: {name: string, uuid: string, texture: string}, or null if the skull does not have an owner. The value at the 'name' key will be an empty string if the server does not know the player's name. The 'texture' value is the Base64 encoded string of the textures property, or null. (Paper only) If no world is provided and the function is executed by a player, the player's world is used. If the block at the given location isn't a skull, a RangeException is thrown. | Yes |- | [[API/functions/get_sky_light_at|get_sky_light_at]]() | int | locationArray | {{object|CastException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Returns the sky light level for a location. Disregards all block sources of light, where 15 is directly beneath the sky during the day. | No |- | [[API/functions/is_block_lockable|is_block_lockable]]() | boolean | locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Returns whether or not the block is lockable. [[API/functions/is_block_lockable|See more...]]
| Yes |- | [[API/functions/is_block_locked|is_block_locked]]() | boolean | locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Returns whether or not the block is locked if its lockable. [[API/functions/is_block_locked|See more...]]
| Yes |- | [[API/functions/is_block_powered|is_block_powered]]() | boolean | locationArray, [checkMode] | {{object|CastException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Returns whether or not a block is being supplied with power.checkMode can be: "BOTH" (Check both direct and indirect power), "DIRECT_ONLY" (Check direct power only) or "INDIRECT_ONLY" (Check indirect power only). CheckMode defaults to "BOTH". | No |- | [[API/functions/is_sign_at|is_sign_at]]() | boolean | locationArray | {{object|FormatException}} | Returns true if the block at this location is a sign. | Yes |- | [[API/functions/is_sign_text_glowing|is_sign_text_glowing]]() | boolean | locationArray, [side] | {{object|FormatException}}
{{object|InvalidWorldException}} | Returns true if the sign side at this location has glowing text. (MC 1.17+) Side can be FRONT (default) or BACK. (MC 1.20+) | Yes |- | [[API/functions/is_sign_waxed|is_sign_waxed]]() | boolean | locationArray | {{object|FormatException}}
{{object|InvalidWorldException}} | Returns whether a sign is waxed and uneditable. (MC 1.20.1+) | Yes |- | [[API/functions/play_named_sound|play_named_sound]]() | void | source, soundArray[, players] | {{object|InvalidWorldException}}
{{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Plays a sound at the given source. Source can be a location array (or entity UUID on MC 1.19.3+). The soundArray is in an associative array with the keys: 'sound', 'category', 'volume' (float), 'pitch' (float), 'seed' (int; MC 1.20.2+) -- all are optional except sound. Volume, if greater than 1.0 (default), controls the distance players can hear the sound. Pitch has a clamped range of 0.5 - 2.0, where where 1.0 is the middle pitch and default. Seed is an integer that determines which sound variant is played. Players can be a single player or an array of players to play the sound to, if not given, all players can potentially hear it. Sound is a sound path, separated by periods. [[API/functions/play_named_sound|See more...]]
| Yes |- | [[API/functions/play_note|play_note]]() | void | [player], instrument, note, [locationArray] | {{object|CastException}}
{{object|RangeException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Plays a note for the given player, at the given note block location. Player defaults to the current player, and location defaults to the player's location. Instrument may be one of: PIANO, BASS_DRUM, SNARE_DRUM, STICKS, BASS_GUITAR, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING, ZOMBIE, SKELETON, CREEPER, DRAGON, WITHER_SKELETON, PIGLIN, or CUSTOM_HEAD, and note is an associative array with 2 values, array(octave: 0, tone: 'F#') where octave is either 0, 1, or 2, and tone is one of the notes G, A, B, C, D, E, or F, optionally suffixed with a pound symbol, which denotes a sharp. (Not all notes can be sharped.) | Yes |- | [[API/functions/play_sound|play_sound]]() | void | source, soundArray[, players] | {{object|InvalidWorldException}}
{{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Plays a sound at the given source. Source can be a location array (or entity UUID on MC 1.18.1+). The soundArray is in an associative array with the keys: 'sound' 'category', 'volume' (float), 'pitch' (float), 'seed' (int; MC 1.20.2+) -- all are optional except sound. Volume, if greater than 1.0 (default), controls the distance players can hear the sound. Pitch has a clamped range of 0.5 - 2.0, where where 1.0 is the middle pitch and default. Seed is an integer that determines which sound variant is played. Players can be a single player or an array of players to play the sound to, if not given, all players can potentially hear it. [[API/functions/play_sound|See more...]]
| Yes |- | [[API/functions/set_banner_patterns|set_banner_patterns]]() | void | array location, array patterns | {{object|FormatException}} | Overwrites the banner patterns for the standing banner at the given location. Patterns should be an array of associative arrays containing the keys "color" and "shape". [[API/functions/set_banner_patterns|See more...]]
| Yes |- | [[API/functions/set_biome|set_biome]]() | void | x, z, [world], biome
locationArray, biome | {{object|FormatException}}
{{object|CastException}}
{{object|NotFoundException}}
{{object|InvalidWorldException}} | Sets the biome at a block location. Minecraft only provides one quarter precision for three dimensional biomes, so this sets the nearest center of a 4x4x4 region. When not using a location array, the entire column at the x and z coordinates are set. [[API/functions/set_biome|See more...]]
| Yes |- | [[API/functions/set_block|set_block]]() | void | locationArray, blockName, [physics] | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Sets the block at the location. The physics boolean determines whether or not this causes a block update. Defaults to true. | Yes |- | [[API/functions/set_block_command|set_block_command]]() | void | locationArray, [cmd] | {{object|CastException}}
{{object|FormatException}} | Sets a command to a Command Block at the given location.If no command is given or parameter is null, it clears the Command Block. | Yes |- | [[API/functions/set_block_lock|set_block_lock]]() | void | locationArray, string | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Sets the string lock for this block if its lockable. Set an empty string or null to remove lock. [[API/functions/set_block_lock|See more...]]
| Yes |- | [[API/functions/set_blockdata|set_blockdata]]() | void | locationArray, data, [physics] | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}} | Sets the block at the location from a blockdata object. Blockdata can be an associative array or string format. If an array, a 'block' key must exist with the block material. All the other keys must be a blockstate and its value. | Yes |- | [[API/functions/set_blockdata_string|set_blockdata_string]]() | void | locationArray, data, [physics] | {{object|FormatException}}
{{object|CastException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}} | Sets the block at the location from a blockdata string. Forward compatibility is not ensured. | Yes |- | [[API/functions/set_command_block_name|set_command_block_name]]() | void | locationArray, [name] | {{object|CastException}}
{{object|FormatException}} | Sets the name of the Command Block at the given location.If no name is given or name is null, the Command Block's name is reset to @. | Yes |- | [[API/functions/set_decorated_pot_sherds|set_decorated_pot_sherds]]() | void | locationArray, array | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Set the sherds on the sides of a decorated pot. Takes an associative array with a key for each side: 'front', 'back', 'left', and 'right'. Each side accepts a sherd material name, or if no decoration is desired on that side, a brick. Throws a FormatException if a side or material is not valid. | Yes |- | [[API/functions/set_end_gateway_age|set_end_gateway_age]]() | void | gatewayLocation, ticks | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Sets an end gateway's age in ticks. A magenta beam is emitted from 0 to 200 ticks (10 seconds). Also a purple beam is emitted very 2400 positive ticks (2 minutes). Setting this to a negative number, like math_const('LONG_MIN'), can be used to prevent beams. | Yes |- | [[API/functions/set_end_gateway_exit|set_end_gateway_exit]]() | void | gatewayLocation, exitLocation, [exactTeleport] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Sets an end gateways teleport exit location. The exit location must be null or a location array with the same world as the end gateway. Optionally change whether the end gateway teleports to the exact location or finds a nearby one. | Yes |- | [[API/functions/set_sign_text|set_sign_text]]() | void | locationArray, [side], lineArray
locationArray, line1, [line2, [line3, [line4]]] | {{object|RangeException}}
{{object|FormatException}} | Sets the text on the side of a sign at the given location. Side can be FRONT (default) or BACK. (MC 1.20+) If the block at x,y,z isn't a sign, a RangeException is thrown. If a text line cannot fit on the sign, it'll be cut off. | Yes |- | [[API/functions/set_sign_text_glowing|set_sign_text_glowing]]() | void | locationArray, [side], isGlowing | {{object|RangeException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|CastException}} | Sets the text on a sign side to be glowing or not. (MC 1.17+) Side can be FRONT (default) or BACK. (MC 1.20+) | Yes |- | [[API/functions/set_sign_waxed|set_sign_waxed]]() | void | locationArray, boolean | {{object|RangeException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|CastException}} | Sets a sign to be waxed or not. (MC 1.20.1+) If a sign is waxed, it is not editable by players. | Yes |- | [[API/functions/set_skull_owner|set_skull_owner]]() | void | locationArray, owner, [texture] | {{object|RangeException}}
{{object|FormatException}} | Sets the owner of the skull at the given location by name or uuid. Supplying null will clear the skull owner, but due to limitations in Bukkit, clients will only see this change after reloading the block. If owner is not null, the texture value as a Base64 encoded string may be provided. (Paper only) If no world is provided and the function is executed by a player, the player's world is used. If the block at the given location isn't a skull, a RangeException is thrown. | Yes |- | [[API/functions/spawn_particle|spawn_particle]]() | void | location, particle[, players] | {{object|RangeException}}
{{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|LengthException}} | Spawns particles at the specified location. The players parameter can be one player or an array of players. If none is given, all players within 32 meters will see the particle. The particle parameter can be a particle name or an associative array defining the characteristics of the particle to be spawned. The array requires the particle name under the key "particle". [[API/functions/spawn_particle|See more...]]
| Yes |} == EventBinding ==
This class of functions provide methods to hook deep into the server's event architecture
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/bind|bind]]()
| string
| event_name, options, prefilter, event_obj, [custom_params], <code>
| {{object|BindException}}
| Binds some functionality to an event, so that when said event occurs, the event handler will fire. Returns the id of this event, so it can be unregistered later, if need be. See more on the page detailing [[Events]]. The options array can contain "id" and "priority", where priority is one of: LOWEST, LOW, NORMAL, HIGH, HIGHEST, or MONITOR. The prefilters vary from event to event.
| Yes
|-
| [[API/functions/cancel|cancel]]()
| void
| [state]
| {{object|BindException}}
| Cancels the event (if applicable). If the event is not cancellable, or is already set to the specified cancelled state, nothing happens. If called from outside an event handler, a BindException is thrown. By default, state is true, but you can uncancel an event (if possible) by calling cancel(false).
| Yes
|-
| [[API/functions/consume|consume]]()
| void
|
| {{object|BindException}}
| Consumes an event, so that lower priority handlers don't even receive the event. Monitor level handlers will still receive it, however, and they can check to see if the event was consumed.
| Yes
|-
| [[API/functions/dump_events|dump_events]]()
| array
|
|
| Returns an array of all the events currently registered on the server. Mostly meant for debugging, however it would be possible to parse this response to cherry pick events to unregister.
| Yes
|-
| [[API/functions/event_meta|event_meta]]()
| array
|
| {{object|BindException}}
| Returns meta information about the activity in regards to this event. This is meant as a debug tool.
| Yes
|-
| [[API/functions/has_bind|has_bind]]()
| boolean
| id
|
| Returns true if a bind with the specified id exists and is currently bound. False is returned otherwise. This can be used to pre-emptively avoid a BindException if duplicate ids are used.
| Yes
|-
| [[API/functions/is_cancelled|is_cancelled]]()
| boolean
|
| {{object|BindException}}
| Returns whether or not the underlying event is cancelled or not. If the event is not cancellable in the first place, false is returned. If called from outside an event, a BindException is thrown
| Yes
|-
| [[API/functions/is_consumed|is_consumed]]()
| boolean
|
| {{object|BindException}}
| Returns whether or not this event has been consumed. Usually only useful for Monitor level handlers, it could also be used for highly robust code, as an equal priority handler could have consumed the event, but this handler would still receive it.
| Yes
|-
| [[API/functions/is_locked|is_locked]]()
| boolean
| parameter
| {{object|BindException}}
| Returns whether or not a call to modify_event() would fail, based on the parameter being locked by a higher priority handler. If this returns false, it is still not a guarantee that the event would be successfully modified, just that it isn't locked.
| Yes
|-
| [[API/functions/lock|lock]]()
| void
| <none> parameterArray
parameter, [parameter...] | {{object|BindException}} | Locks the specified event parameter(s), or all of them, if specified with no arguments. Locked parameters become read only for lower priority event handlers. | Yes |- | [[API/functions/modify_event|modify_event]]() | boolean | parameter, value, [throwOnFailure] | {{object|CastException}}
{{object|BindException}} | Modifies the underlying event object, if applicable. The documentation for each event will explain what parameters can be modified, and what their expected values are. [[API/functions/modify_event|See more...]]
| Yes |- class="hiddenFunction" | [[API/functions/trigger|trigger]]() | void | eventName, eventObject, [serverWide] | {{object|CastException}}
{{object|BindException}} | Manually triggers bound events. The event object passed to this function is sent directly as-is to the bound events. Check the documentation for each event to see what is required. No checks will be done on the data here, but it is not recommended to fail to send all parameters required. If serverWide is true, the event is triggered directly in the server, unless it is a CommandHelper specific event, in which case, serverWide is irrelevant. Defaults to false, which means that only CommandHelper code will receive the event. Throws a CastException when eventObject is not an array and not null. Throws a BindException when trigger() is not yet supported by the given event. | Yes |- | [[API/functions/unbind|unbind]]() | void | [eventID] | {{object|BindException}} | Unbinds an event, which causes it to not run anymore. If called from within an event handler, eventID is optional, and defaults to the current event id. | Yes |} == Exceptions ==
This class contains functions related to Exception handling in MethodScript
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|- class="hiddenFunction"
| [[API/functions/complex_try|complex_try]]()
| void
| tryBlock, [catchVariable, catchBlock]+, [catchBlock]
|
|
| No
|-
| [[API/functions/get_stack_trace|get_stack_trace]]()
| array
|
|
| Returns an array of stack trace elements. This is the same stack trace that would be generated if one were to throw an exception, then catch it.([[API/functions/get_stack_trace#Examples|Examples...]]) | Yes |- | [[API/functions/set_uncaught_exception_handler|set_uncaught_exception_handler]]() | closure | closure(@ex) | {{object|CastException}} | Sets the uncaught exception handler, returning the currently set one, or null if none has been set yet. If code throws an exception, instead of doing the default (displaying the error to the user/console) it will run your code instead. The exception that was thrown will be passed to the closure, and it is expected that the closure returns either null, true, or false. [[API/functions/set_uncaught_exception_handler|See more...]]
([[API/functions/set_uncaught_exception_handler#Examples|Examples...]]) | Yes |- | [[API/functions/throw|throw]]() | nothing | exceptionType, msg, [causedBy]
exception | {{object|FormatException}} | This function causes an exception to be thrown. The exceptionType may be any valid exception type. [[API/functions/throw|See more...]]
| No |- | [[API/functions/try|try]]() | void | tryCode, [varName, catchCode, [exceptionTypes]]
tryCode, catchCode | {{object|CastException}}
{{object|FormatException}} | This function works similar to a try-catch block in most languages. If the code in tryCode throws an exception, instead of killing the whole script, it stops running, and begins running the catchCode. var should be an ivariable, and it is set to an array containing information about the exception. Consider using try/catch blocks instead of the try function. [[API/functions/try|See more...]]
| No |} == ExecutionQueue ==
An execution queue is a queue of closures, which are queued up to be run in sequence by the engine. Unlike set_timeout and set_interval, there is no time component, it's simply a queue of operations to execute sequentially. See the [[Execution_Queue|article on the learning trail]] for more information.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/queue_clear|queue_clear]]()
| void
| [queue]
|
| Clears out all tasks that are on the queue. If no tasks were on the queue, nothing happens.
| Yes
|-
| [[API/functions/queue_delay|queue_delay]]()
| void
| x, [queue]
| {{object|CastException}}{{object|RangeException}} | Queues up a non-disruptive sleep at the end of the queue. This task will stall the execution thread for x milliseconds. | Yes |- | [[API/functions/queue_delay_front|queue_delay_front]]() | void | x, [queue] | {{object|CastException}}
{{object|RangeException}} | Works like queue_delay, but puts the delay at the front of the queue. | Yes |- | [[API/functions/queue_push|queue_push]]() | void | closure, [queue] | {{object|CastException}} | Queues a task up at the end of the specified queue. | Yes |- | [[API/functions/queue_push_front|queue_push_front]]() | void | closure, [queue] | {{object|CastException}} | Queues a task at the front of the queue. | Yes |- | [[API/functions/queue_remove|queue_remove]]() | void | [queue] | | Removes the last task at the end of the queue from the queue. | Yes |- | [[API/functions/queue_remove_front|queue_remove_front]]() | void | [queue] | | Removes a task from the front of the queue. That is, the next task that would have been run is removed. | Yes |- | [[API/functions/queue_running|queue_running]]() | boolean | [queue] | | Returns true if the specified queue still has tasks running on it. | Yes |} == ExtensionMeta ==
Provides the ability for finding out information about installed extensions, including events and functions.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/event_exists|event_exists]]()
| boolean
| name
|
| Returns true if the event is known to MethodScript. Like function_exists(), this function is resolved at compile time, and allows for conditional uses of events that may or may not exist.
| No
|-
| [[API/functions/extension_exists|extension_exists]]()
| boolean
| name
|
| Returns true if the extension is known to MethodScript and loaded. Like function_exists(), this function is resolved at compile time.
| No
|-
| [[API/functions/extension_info|extension_info]]()
| array
| [extensionName]
|
| Returns extension info for the extensions the system has loaded, or the given extension if extensionName is specified. Included data will be events, functions and version, keyed by the name of the extension (or __unidentified__ if it's an old-style extension).
| No
|-
| [[API/functions/function_exists|function_exists]]()
| boolean
| name
|
| Returns true if the function is known to MethodScript. This is a special function; it is resolved at compile time, and allows for conditional uses of functions that may or may not exist, such as functions that might or might not be loaded in an extension, or from different versions. This is useful for shared code in environments where an extension may or may not be available, or an older version of MethodScript. if(function_exists('my_extension_function')){ my_extension_function() } can then be used to selectively "bypass" the compiler restrictions that would normally cause a fatal compile error, since that function is missing. Therefore, you can wrap extension related code around extension specific blocks, and make that code portable to other installations that may not have the extension installed.([[API/functions/function_exists#Examples|Examples...]]) | No |} == FileHandling ==
This class contains methods that help manage files on the file system. Most are restricted with the base-dir setting in your preferences.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/async_read|async_read]]()
| void
| file, [encoding], callback
| {{object|SecurityException}}
| Asynchronously reads in a file. [[API/functions/async_read|See more...]]| Yes |- | [[API/functions/comp_read|comp_read]]() | string | path, [encoding] | | Returns the value of a file at compile time only. Unlike read, this runs and is fully resolved at compile time. This is useful for optimization reasons, if you have a file that is unchanging, this can be used instead of read(), to prevent a runtime hit each time the code is executed. Otherwise, this method is equivalent to read(). The path must be fully resolved at compile time. Encoding is optional, and defaults to UTF-8. | Yes |- | [[API/functions/file_resolve|file_resolve]]() | string | file | {{object|IOException}} | Returns the canonical, absolute path of the given path. This provides a context independent and unique path which always points to the specified path, and removes any duplicate . or .. parts. | Yes |- | [[API/functions/file_size|file_size]]() | int | path | {{object|IOException}}
{{object|SecurityException}} | Returns the size of a file on the file system. | Yes |- | [[API/functions/read|read]]() | string | file, [encoding] | {{object|IOException}}
{{object|SecurityException}} | Reads in a file from the file system at location var1 and returns it as a string. The path is relative to the file that is being run, not CommandHelper. If the file is not found, or otherwise can't be read in, an IOException is thrown. If the file specified is not within base-dir (as specified in the preferences file), a SecurityException is thrown. The line endings for the string returned will always be \n, even if they originally were \r\n. Encoding defaults to UTF-8 if not specified. | Yes |- | [[API/functions/read_binary|read_binary]]() | byte_array | file | {{object|IOException}} | Reads in a file, and returns a byte_array for it. The file is returned exactly as is on disk, no conversions are done. base-dir restrictions are enforced for the path, the same as read(). If file is relative, it is assumed to be relative to this file. This is useful for managing binary files. | Yes |- | [[API/functions/read_gzip_binary|read_gzip_binary]]() | byte_array | file | {{object|IOException}} | Reads in a gzipped file, and returns a byte_array for it. The file is returned exactly as is on disk, no conversions are done other than unzipping it. base-dir restrictions are enforced for the path, the same as read(). If file is relative, it is assumed to be relative to this file. | Yes |} == InventoryManagement ==
Provides methods for managing inventory related tasks.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/add_to_inventory|add_to_inventory]]()
| int
| mixed specifier, array itemArray
| {{object|CastException}}{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}}
{{object|NotFoundException}}
{{object|RangeException}} | Add to inventory the specified item. The specifier must be a location array, entity UUID, or virtual inventory id. The items are distributed in the inventory, first filling up slots that have the same item type, up to the max stack size, then fills up empty slots, until either the entire inventory is filled, or the entire amount has been given. If the inventory is full, number of items that were not added is returned, which will be less than or equal to the quantity provided. Otherwise, returns 0.
([[API/functions/add_to_inventory#Examples|Examples...]]) | Yes |- | [[API/functions/clear_pinv|clear_pinv]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|NotFoundException}} | Clears a player's entire inventory (including armor). | Yes |- | [[API/functions/close_pinv|close_pinv]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Closes the inventory of the current player, or of the specified player. | Yes |- | [[API/functions/create_virtual_inventory|create_virtual_inventory]]() | void | id, [type/size], [title], [inventory] | {{object|RangeException}}
{{object|CastException}}
{{object|FormatException}}
{{object|IllegalArgumentException}} | Creates a virtual inventory and holds it under the specified id. The string id should not be a UUID. If the id is already in use, an IllegalArgumentException will be thrown. You can use this id in other inventory functions to modify the contents, among other things. If a size is specified instead of a type, it is rounded up to the nearest multiple of 9. Size cannot be higher than 54. A title for the top of the inventory may be given, but it will use the default for that that inventory type if null is specified. An optional inventory array may be specified, otherwise the inventory will start empty. Available inventory types: BREWING, CHEST, DISPENSER, DROPPER, ENDER_CHEST, FURNACE, HOPPER, PLAYER, WORKBENCH, ANVIL, SMITHING, SHULKER_BOX, BARREL, BLAST_FURNACE or SMOKER | Yes |- | [[API/functions/delete_virtual_inventory|delete_virtual_inventory]]() | boolean | id | | Deletes a virtual inventory. The inventory will be closed for all viewers. Returns whether or not an inventory with that id existed and was removed. | Yes |- | [[API/functions/get_inventory|get_inventory]]() | array | specifier, [index] | {{object|CastException}}
{{object|RangeException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Gets an array of the specified inventory. If the block or entity can't have an inventory, an IllegalArgumentException is thrown. If the index is specified, only the slot given will be returned. The max index of the array in the array is different for different types of inventories. If there is no item at the slot specified, null is returned. [[API/functions/get_inventory|See more...]]
| Yes |- | [[API/functions/get_inventory_item|get_inventory_item]]() | array | specifier, slot | {{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|RangeException}}
{{object|IllegalArgumentException}} | If a number is provided, it is assumed to be an entity, and if the entity supports inventories, it will be valid. Otherwise, if a location array is provided, it is assumed to be a block (chest, brewer, etc) and interpreted thusly. Depending on the inventory type, the max index will vary. If the index is too large, a RangeException is thrown, otherwise, the item at that location is returned as an item array, or null, if no item is there. You can determine the inventory type (and thus the max index count) with get_inventory_type(). An itemArray, like the one used by pinv/set_pinv is returned. | Yes |- | [[API/functions/get_inventory_name|get_inventory_name]]() | string | specifier | {{object|BadEntityException}}
{{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Returns the name of the inventory holder specified. If the block or entity can't have an inventory or a name, an IllegalArgumentException is thrown. If the inventory was not given a title, an empty string is returned. | Yes |- | [[API/functions/get_inventory_size|get_inventory_size]]() | int | specifier | {{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|IllegalArgumentException}} | Returns the max size of the inventory specified. If the block or entity can't have an inventory, an IllegalArgumentException is thrown. | Yes |- | [[API/functions/get_inventory_type|get_inventory_type]]() | string | specifier | {{object|CastException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Returns the inventory type at the location specified, or of the entity specified. If the entity or location specified is not capable of having an inventory, an IllegalArgumentException is thrown. [[API/functions/get_inventory_type|See more...]]
| Yes |- | [[API/functions/get_inventory_viewers|get_inventory_viewers]]() | array | specifier | {{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|IllegalArgumentException}} | Gets all players currently viewing this inventory. The specifier can be an entity UUID, block location array, or virtual inventory id. | Yes |- | [[API/functions/get_virtual_inventories|get_virtual_inventories]]() | array | | | Returns an array of virtual inventory ids. | Yes |- | [[API/functions/has_inventory|has_inventory]]() | boolean | specifier | {{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|RangeException}}
{{object|IllegalArgumentException}} | Returns whether the specified entity or location has an inventory. The specifier can be an entity UUID, location array, or virtual inventory ID. If given the id of a virtual inventory that doesn't exist, false will be returned. | Yes |- | [[API/functions/penchanting|penchanting]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Shows an enchanting to the current player, or a specified player. Note that power is defined by how many bookcases are near. | Yes |- | [[API/functions/penderchest|penderchest]]() | array | [player, [index]] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|CastException}}
{{object|RangeException}}
{{object|NotFoundException}} | Gets the inventory for the specified player's enderchest, or the current player if none specified. If the index is specified, only the slot given will be returned. The index of the array in the array is 0 - 26, which corresponds to the slot in the enderchest inventory. If there is no item at the slot specified, null is returned. [[API/functions/penderchest|See more...]]
| Yes |- | [[API/functions/pgive_enderchest_item|pgive_enderchest_item]]() | int | [player], itemArray | {{object|FormatException}}
{{object|CastException}}
{{object|RangeException}}
{{object|PlayerOfflineException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}}
{{object|LengthException}} | Adds the specified item to a player's enderchest. Unlike set_penderchest(), this does not specify a slot. The items are distributed in the player's inventory, first filling up slots that have the same item type, up to the max stack size, then fills up empty slots, until either the entire inventory is filled or the entire amount has been given. If the player's enderchest is full, the number of items that were not added is returned, which will be less than or equal to the quantity provided. Otherwise, returns 0. | Yes |- | [[API/functions/pgive_item|pgive_item]]() | int | [player], itemArray | {{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}}
{{object|LengthException}}
{{object|InsufficientArgumentsException}} | Gives a player the specified item. Unlike set_pinv(), this does not specify a slot. The qty is distributed in the player's inventory, first filling up slots that have the same item type, up to the max stack size, then fills up empty slots, until either the entire inventory is filled, or the entire amount has been given. If the player's inv is full, the number of items that were not added is returned, which will be less than or equal to the quantity provided. Otherwise, returns 0. This function will not touch the player's armor slots however. | Yes |- | [[API/functions/phas_item|phas_item]]() | int | [player], itemArray | {{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|RangeException}}
{{object|CastException}}
{{object|NotFoundException}}
{{object|LengthException}} | Returns the quantity of the specified item that the player is carrying (including armor slots). This counts across all slots in inventory. Recall that 0 is false, and anything else is true, so this can be used to get the total, or just see if they have the item. [[API/functions/phas_item|See more...]]
([[API/functions/phas_item#Examples|Examples...]]) | Yes |- | [[API/functions/pheld_slot|pheld_slot]]() | int | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|NotFoundException}} | Returns the selected quickbar slot of the given or executing player. The slot number is in range of [0-8]. | Yes |- | [[API/functions/pinv|pinv]]() | array | [player, [slot]] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|CastException}}
{{object|RangeException}}
{{object|NotFoundException}} | Gets the inventory for a player, or the current player if none specified. If the slot is specified, only the item in the slot given will be returned. The indexes of the array are 0 - 35, 100 - 103, -106, which corresponds to the slots in the player's inventory. To access armor slots, you may also specify the slot index. (100 - 103). The quick bar is 0 - 8. If slot is null, the item in the player's hand is returned, regardless of what slot is selected. If index is -106, the player's off-hand item is returned. If there is no item at the slot specified, null is returned. [[API/functions/pinv|See more...]]
| Yes |- | [[API/functions/pinv_open|pinv_open]]() | void | [playerToShow,] playerInventory | {{object|PlayerOfflineException}}
{{object|LengthException}} | Opens a player's inventory, shown to the player specified's screen. | Yes |- | [[API/functions/pinventory_holder|pinventory_holder]]() | mixed | [player] | {{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|LengthException}} | Returns the block location, entity UUID, or virtual id of the inventory the player is currently viewing. If the player is viewing their own inventory or no inventory, the player's UUID is returned. When the inventory is virtual but has no id, it will return null. The returned value can be used in other inventory functions unless it is null. | Yes |- | [[API/functions/pitem_slot|pitem_slot]]() | array | [player], itemArray | {{object|CastException}}
{{object|FormatException}}
{{object|LengthException}}
{{object|PlayerOfflineException}}
{{object|NotFoundException}} | Given an item array, returns the slot numbers that the matching item has at least one item in. [[API/functions/pitem_slot|See more...]]
([[API/functions/pitem_slot#Examples|Examples...]]) | Yes |- | [[API/functions/popen_inventory|popen_inventory]]() | void | [player], specifier | {{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|LengthException}}
{{object|IllegalArgumentException}} | Opens an inventory for a player. The specifier must be an entity UUID, location array of a container block, or a virtual inventory id. | Yes |- | [[API/functions/ptake_enderchest_item|ptake_enderchest_item]]() | int | [player], itemArray | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|NotFoundException}}
{{object|RangeException}} | Works in reverse of pgive_enderchest_item(), but returns the number of items actually taken, which will be from 0 to qty. [[API/functions/ptake_enderchest_item|See more...]]
([[API/functions/ptake_enderchest_item#Examples|Examples...]]) | Yes |- | [[API/functions/ptake_item|ptake_item]]() | int | [player], itemArray | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|FormatException}}
{{object|NotFoundException}}
{{object|LengthException}} | Works in reverse of pgive_item(), but returns the number of items actually taken, which will be from 0 to qty. [[API/functions/ptake_item|See more...]]
([[API/functions/ptake_item#Examples|Examples...]]) | Yes |- | [[API/functions/pworkbench|pworkbench]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|InsufficientArgumentsException}} | Shows a workbench to the current player, or a specified player. | Yes |- | [[API/functions/set_inventory|set_inventory]]() | void | specifier, invArray | {{object|CastException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|RangeException}}
{{object|IllegalArgumentException}} | Sets a block or entity inventory to the specified inventory object. The specifier can be an entity UUID, location array, or virtual inventory ID. If the block or entity can't have an inventory, an IllegalArgumentException is thrown. An inventory object invArray is one that matches what is returned by get_inventory(), so set_inventory(123, get_inventory(123)) while pointless, would be a correct call. [[API/functions/set_inventory|See more...]]
| Yes |- | [[API/functions/set_inventory_item|set_inventory_item]]() | void | specifier, index, itemArray | {{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|CastException}}
{{object|RangeException}}
{{object|IllegalArgumentException}} | Sets the specified item in the specified inventory slot. The specifier can be an entity UUID, block location array or virtual inventory id. [[API/functions/set_inventory_item|See more...]]
| Yes |- | [[API/functions/set_penderchest|set_penderchest]]() | void | [player], invArray | {{object|PlayerOfflineException}}
{{object|CastException}}
{{object|FormatException}}
{{object|LengthException}} | Sets a player's enderchest's inventory to the specified inventory object. An inventory object is one that matches what is returned by penderchest(), so set_penderchest(penderchest()), while pointless, would be a correct call. [[API/functions/set_penderchest|See more...]]
| Yes |- | [[API/functions/set_pheld_slot|set_pheld_slot]]() | void | [player], slotNumber | {{object|RangeException}}
{{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|NotFoundException}}
{{object|LengthException}} | Sets the selected quickbar slot of the given or executing player to the given slot. The slot number is in range of [0-8]. | Yes |- | [[API/functions/set_pinv|set_pinv]]() | void | [player, [slot]], array | {{object|PlayerOfflineException}}
{{object|CastException}}
{{object|FormatException}}
{{object|LengthException}} | Sets a player's inventory to the specified inventory array. An inventory array is one that matches what is returned by {{function|pinv}}, so set_pinv(pinv()), while pointless, would be a correct call (though some item meta may not yet be supported). If a slot is specified as the second argument, only that slot is set with the given item array. [[API/functions/set_pinv|See more...]]
| Yes |- | [[API/functions/show_enderchest|show_enderchest]]() | void | [player [, player]] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Shows the enderchest of either the current player or the specified player if given. If a second player is specified, shows the second player the contents of the first player's enderchest. | Yes |- | [[API/functions/take_from_inventory|take_from_inventory]]() | int | specifier, itemArray
specifier, itemID, qty | {{object|CastException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|InvalidWorldException}}
{{object|RangeException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}} | Works in reverse of add_to_inventory(), but returns the number of items actually taken, which will be from 0 to qty. Target must be a location array or entity UUID. [[API/functions/take_from_inventory|See more...]]
([[API/functions/take_from_inventory#Examples|Examples...]]) | Yes |} == ItemMeta ==
These functions manipulate an item's meta data. The items are modified in a player's inventory.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/get_armor_color|get_armor_color]]()
| colorArray
| [player], inventorySlot
| {{object|CastException}}{{object|PlayerOfflineException}} | Returns a color array for the color of the leather armor at the given slot. A CastException is thrown if this is not leather armor at that slot. The color array returned will look like: array(r: 0, g: 0, b: 0) | Yes |- | [[API/functions/get_itemmeta|get_itemmeta]]() | array | [player,] slot | {{object|PlayerOfflineException}}
{{object|CastException}} | Returns an associative array of known item meta for the slot given, or null if there isn't any. [[API/functions/get_itemmeta|See more...]]
([[API/functions/get_itemmeta#Examples|Examples...]]) | Yes |- | [[API/functions/is_leather_armor|is_leather_armor]]() | boolean | [player], itemSlot | {{object|CastException}}
{{object|PlayerOfflineException}} | Returns true if the item at the given slot is a piece of leather armor, that is, if dying it is allowed. | Yes |- | [[API/functions/set_armor_color|set_armor_color]]() | void | [player], slot, colorArray | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|FormatException}} | Sets the color of the leather armor at the given slot. colorArray should be an array that matches one of the formats: array(r: 0, g: 0, b: 0) array(red: 0, green: 0, blue: 0) array(0, 0, 0) | Yes |- | [[API/functions/set_itemmeta|set_itemmeta]]() | void | [player,] slot, ItemMetaArray | {{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|CastException}}
{{object|NotFoundException}} | Applies the data from the given array to the item at the specified slot. Unused fields will be ignored. If null or an empty array is supplied, or if none of the given fields are applicable, the item will become default, as this function overwrites any existing data. See {{function|get_itemmeta}} for available fields. If the item does not yet exist, use {{function|set_pinv}} instead.
([[API/functions/set_itemmeta#Examples|Examples...]]) | Yes |} == Marquee ==
This class provides methods for making a text "marquee", like a stock ticker. Because this is a threading operation, and could be potentially resource intensive, the heavy lifting has been implemented natively.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/marquee|marquee]]()
| void
| [marqueeName], text, stringWidth, delayTime, callback
| {{object|CastException}}
| Sets up a marquee, which will automatically split up a given string for you, and call the callback. The split string will automatically wrap, handle buffering spaces, and scroll through the text. [[API/functions/marquee|See more...]]| Yes |- | [[API/functions/marquee_stop|marquee_stop]]() | void | marqueeName | | Stops a named marquee. | Yes |} == Math ==
Provides mathematical functions to scripts
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/abs|abs]]()
| mixed
| arg
| {{object|CastException}}
| Returns the absolute value of the argument.([[API/functions/abs#Examples|Examples...]]) | No |- | [[API/functions/acos|acos]]() | double | number | {{object|CastException}} | Returns the arc cos of the number | No |- | [[API/functions/add|add]]() | mixed | var1, [var2...] | {{object|CastException}} | Adds all the arguments together, and returns either a double or an integer. Operator syntax is also supported: @a + @b
([[API/functions/add#Examples|Examples...]]) | No |- | [[API/functions/asin|asin]]() | double | number | {{object|CastException}} | Returns the arc sin of the number | No |- | [[API/functions/atan|atan]]() | double | number | {{object|CastException}} | Returns the arc tan of the number | No |- | [[API/functions/atan2|atan2]]() | double | y, x | {{object|CastException}} | Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi. | No |- | [[API/functions/ceil|ceil]]() | int | number | {{object|CastException}} | Returns the ceiling of any given number. For example, ceil(3.2) returns 4, and ceil(-1.1) returns -1 | No |- | [[API/functions/clamp|clamp]]() | float | value, min, max | {{object|CastException}} | Clamps a value between a certain range, inclusive. If the value is less than the min, the min is returned, if it is greater than the max, the max is returned, and if it is between the two values, the original value is returned. Alternatively, if min > max, clamp works in reverse mode. In that case, the value must be less than max (actually the minimum) and greater than min (actually the maximum). If the value is between the two, it is determined which of the two values it is closer to, and then that value is returned. If the value is exactly between both min and max, the minimum (actually the max) is returned. If min == max, then min is returned.
([[API/functions/clamp#Examples|Examples...]]) | No |- | [[API/functions/cos|cos]]() | double | number | {{object|CastException}} | Returns the cos of the number | No |- | [[API/functions/cosh|cosh]]() | double | number | {{object|CastException}} | Returns the hyperbolic cosine of the number | No |- | [[API/functions/dec|dec]]() | ivar | var, [value] | {{object|CastException}} | Subtracts value from var, and stores the new value. Value defaults to 1. Equivalent to --var (or var -= value) in other languages. Expects ivar to be a variable, then returns the ivar, or if var is a constant number, simply adds x to it, and returns the new number. Operator syntax is also supported: --@var
([[API/functions/dec#Examples|Examples...]]) | No |- | [[API/functions/divide|divide]]() | mixed | var1, [var2...] | {{object|CastException}}
{{object|RangeException}} | Divides the arguments from left to right, and returns either a double or an integer. If you divide by zero, a RangeException is thrown. Operator syntax is also supported: 2 / 2
([[API/functions/divide#Examples|Examples...]]) | No |- | [[API/functions/expr|expr]]() | double | expression, [valueArray] | {{object|FormatException}}
{{object|CastException}}
{{object|PluginInternalException}} | Sometimes, when you need to calculate an advanced mathematical expression, it is messy to write out everything in terms of functions. This function will allow you to evaluate a mathematical expression as a string, using common mathematical notation. For example, (2 + 3) * 4 would return 20. Variables can also be included, and their values given as an associative array. expr('(x + y) * z', array(x: 2, y: 3, z: 4)) would be the same thing as the above example. This function requires WorldEdit in plugins, lib, or the server root in order to run. | No |- | [[API/functions/floor|floor]]() | int | number | {{object|CastException}} | Returns the floor of any given number. For example, floor(3.8) returns 3, and floor(-1.1) returns 2 | No |- | [[API/functions/hypot|hypot]]() | number | a, b | {{object|RangeException}}
{{object|CastException}} | Given two sides of a right triangle, returns the length of the hypotenuse, using the equation a² + b² = c², where a and b are the arguments provided.
([[API/functions/hypot#Examples|Examples...]]) | No |- | [[API/functions/inc|inc]]() | ivar | var, [x] | {{object|CastException}} | Adds x to var, and stores the new value. Equivalent to ++var in other languages. Expects ivar to be a variable, then returns the ivar, or, if var is a constant number, simply adds x to it, and returns the new number. Operator syntax is also supported: ++@var
([[API/functions/inc#Examples|Examples...]]) | No |- | [[API/functions/logarithm|logarithm]]() | double | val, [base] | {{object|CastException}}
{{object|RangeException}} | Return the log of a number to the specified base, or the mathematical constant e if no base is provided (or ln). If val is less than or equal to zero, a RangeException is thrown. Mathematically speaking, if val is 0, then the result would be negative infinity, and if it is less than 0 it is undefined (NaN), but since MethodScript has no way of representing either of these, a RangeException is thrown instead.
([[API/functions/logarithm#Examples|Examples...]]) | No |- | [[API/functions/math_const|math_const]]() | number | constant | {{object|CastException}} | Returns the value of various math constants. The constant argument must be one of the following: NaN, NEGATIVE_INFINITY, INFINITY, DOUBLE_MAX, DOUBLE_MIN, LONG_MAX, LONG_MIN, SHORT_MAX, SHORT_MIN, INTEGER_MAX, INTEGER_MIN, FLOAT_MAX, FLOAT_MIN, BYTE_MAX, BYTE_MIN, E, PI, PHI, C, or EULER [[API/functions/math_const|See more...]]
([[API/functions/math_const#Examples|Examples...]]) | No |- | [[API/functions/max|max]]() | number | num1, [num2...] | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Returns the highest number in a given list of numbers. If any of the arguments are arrays, they are expanded into individual numbers, and also compared. | No |- | [[API/functions/min|min]]() | number | num1, [num2...] | {{object|CastException}}
{{object|InsufficientArgumentsException}} | Returns the lowest number in a given list of numbers. If any of the arguments are arrays, they are expanded into individual numbers, and also compared. | No |- | [[API/functions/mod|mod]]() | int | x, n | {{object|CastException}}
{{object|RangeException}} | Returns x modulo n. Throws a RangeException when n is 0. Operator syntax is also supported: @x % @n
([[API/functions/mod#Examples|Examples...]]) | No |- | [[API/functions/multiply|multiply]]() | mixed | var1, [var2...] | {{object|CastException}} | Multiplies the arguments together, and returns either a double or an integer. Operator syntax is also supported: 2 * 2
([[API/functions/multiply#Examples|Examples...]]) | No |- | [[API/functions/neg|neg]]() | number | number | {{object|CastException}} | Negates a number, essentially multiplying the number by -1 | No |- | [[API/functions/postdec|postdec]]() | ivar | var, [x] | {{object|CastException}} | Subtracts x from var, and stores the new value. Equivalent to var-- in other languages. Expects ivar to be a variable, then returns a copy of the old ivar, , or, if var is a constant number, simply adds x to it, and returns the new number. Operator syntax is also supported: @var--
([[API/functions/postdec#Examples|Examples...]]) | No |- | [[API/functions/postinc|postinc]]() | ivar | var, [x] | {{object|CastException}} | Adds x to var, and stores the new value. Equivalent to var++ in other languages. Expects ivar to be a variable, then returns a copy of the old ivar, or, if var is a constant number, simply adds x to it, and returns the new number. Operator notation is also supported: @var++
([[API/functions/postinc#Examples|Examples...]]) | No |- | [[API/functions/pow|pow]]() | double | x, n | {{object|CastException}} | Returns x to the power of n. Operator syntax is also supported: @x ** @n
([[API/functions/pow#Examples|Examples...]]) | No |- | [[API/functions/rand|rand]]() | mixed | []
min/max, [max] | {{object|RangeException}}
{{object|CastException}} | Returns a random number from 0 to max or min to max, depending on usage. Max is exclusive. Min must be less than max. This will return an integer. If no arguments are given, a random double from 0.0 to 1.0 (exclusive) will be returned.
([[API/functions/rand#Examples|Examples...]]) | No |- | [[API/functions/round|round]]() | double | number, [precision] | {{object|CastException}}
{{object|RangeException}} | Unlike floor and ceil, rounds the number to the nearest double that is equal to an integer. Precision defaults to 0, but if set to 1 or more, rounds decimal places. For instance, round(2.29, 1) would return 2.3. If precision is < 0, a RangeException is thrown.
([[API/functions/round#Examples|Examples...]]) | No |- | [[API/functions/round15|round15]]() | double | value | {{object|CastException}} | Rounds value to the 15th place. This is useful when doing math using approximations. For instance, sin(math_const('PI')) returns 1.2246467991473532E-16, but sin of pi is actually 0. This happens because pi cannot be accurately represented on a computer, it is an approximation. Using round15, you can round to the next nearest value, which often time should give a more useful answer to display. For instance, round15(sin(math_const('PI'))) is 0. This functionality is not provided by default in methods like sin(), because it technically makes the result less accurate, given the inputs. In general, you should only use this function just before displaying the value to the user. Internally, you should keep the value returned by the input functions.
([[API/functions/round15#Examples|Examples...]]) | No |- | [[API/functions/sin|sin]]() | double | number | {{object|CastException}} | Returns the sin of the number | No |- | [[API/functions/sinh|sinh]]() | double | number | {{object|CastException}} | Returns the hyperbolic sine of the number | No |- | [[API/functions/sqrt|sqrt]]() | number | number | {{object|RangeException}}
{{object|CastException}} | Returns the square root of a number. Note that this is mathematically equivalent to pow(number, .5). Imaginary numbers are not supported, so number must be positive. | No |- | [[API/functions/subtract|subtract]]() | mixed | var1, [var2...] | {{object|CastException}} | Subtracts the arguments from left to right, and returns either a double or an integer. Operator syntax is also supported: @a - @b
([[API/functions/subtract#Examples|Examples...]]) | No |- | [[API/functions/tan|tan]]() | double | number | {{object|CastException}} | Returns the tan of the number | No |- | [[API/functions/tanh|tanh]]() | double | number | {{object|CastException}} | Returns the hyperbolic tangent of the number | No |- | [[API/functions/to_degrees|to_degrees]]() | double | number | {{object|CastException}} | Converts the number to degrees (which is assumed to have been in radians) | No |- | [[API/functions/to_radians|to_radians]]() | double | number | {{object|CastException}} | Converts the number to radians (which is assumed to have been in degrees) | No |} == Meta ==
These functions provide a way to run other commands, and otherwise interact with the system in a meta way.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/build_date|build_date]]()
| int
|
|
| Returns the compile date of the current script, as a unix time stamp in milliseconds.
| Yes
|-
| [[API/functions/call_alias|call_alias]]()
| boolean
| cmd
|
| Allows a CommandHelper alias to be called from within another alias. Typically this is not possible, as a script that runs "/jail = /jail" for instance, would simply be calling whatever plugin that actually provides the jail functionality's /jail command. However, using this function makes the command loop back to CommandHelper only. [[API/functions/call_alias|See more...]]| No |- | [[API/functions/capture_runas|capture_runas]]() | string | player, command | {{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|PluginInternalException}} | Works like runas, except any messages sent to the command sender during command execution are attempted to be intercepted, and are then returned as a string, instead of being sent to the command sender. Note that this is VERY easy for plugins to get around in such a way that this function will not work, this is NOT a bug in CommandHelper, nor is it necessarily a problem in the other plugin either, but the other plugin will have to make changes for it to work properly. A PluginInternalException is thrown if something goes wrong. Any number of things may go wrong that aren't necessarily this function's fault, and in those cases, this exception is thrown. | Yes |- | [[API/functions/engine_build_date|engine_build_date]]() | int | | | Returns the compile date, in a millisecond unit time stamp, of when MethodScript was compiled, or null, if that can't be computed for various reasons. | Yes |- | [[API/functions/engine_location|engine_location]]() | string | | | Returns the location of the currently running engine binary. | Yes |- | [[API/functions/get_cmd|get_cmd]]() | string | | | Gets the command (as a string) that ended up triggering this script, exactly how it was entered by the player. This could be null, if for instance it is called from within an event. | No |- | [[API/functions/get_cmd_completions|get_cmd_completions]]() | array | [player], command, args | {{object|FormatException}}
{{object|PluginInternalException}}
{{object|NotFoundException}} | Runs a plugin command's tab completer and returns an array of possible completions for the final argument. [[API/functions/get_cmd_completions|See more...]]
| Yes |- | [[API/functions/get_command_block|get_command_block]]() | locationArray | | | If this command was being run from a command block block or minecart, this will return the location of the block or minecart. The yaw and pitch will only be included in the locationArray for minecart command blocks. If a player or console ran this command (or any other command sender), this will return null. | No |- | [[API/functions/get_compiler_options|get_compiler_options]]() | array | | | Returns a list of all defined compiler options, which can be set using the compilerOptions file option | No |- | [[API/functions/get_compiler_warnings|get_compiler_warnings]]() | array | | | Returns a list of all defined compiler warnings, which can be suppressed using the suppressWarnings file option | No |- | [[API/functions/get_locales|get_locales]]() | array | | | Returns a list of locales on this system.
([[API/functions/get_locales#Examples|Examples...]]) | No |- | [[API/functions/get_script_environment|get_script_environment]]() | Resource | | | Returns a copy of the underlying engine's environment object. This is only useful to embedded scripting engines that are attempting to call back into MethodScript. The object returned is a CResource. | Yes |- | [[API/functions/has_runtime_setting|has_runtime_setting]]() | boolean | name | {{object|CastException}} | Returns true if the runtime setting is set. This will also return true if the value of the setting is null. | Yes |- | [[API/functions/is_alias|is_alias]]() | boolean | cmd | {{object|IOException}} | Returns true if using call_alias with this cmd would trigger an alias. | Yes |- | [[API/functions/nameof|nameof]]() | string | component | {{object|CastException}} | Returns the name of the item. For now, only works with variables. For instance, nameof(@var) returns the string "@var". This is useful for avoiding hardcoding of strings of items that are refactorable. This allows tools to properly refactor, without needing to manually update strings that contain the names of variables or other refactorable items. This is a meta function, and is fully resolved at compile time. | No |- | [[API/functions/psetop|psetop]]() | string | [player], status | {{object|PlayerOfflineException}} | Sets whether or not a player has operator status. If no player is specified the player running the script is given. | Yes |- | [[API/functions/remove_runtime_setting|remove_runtime_setting]]() | void | name | {{object|CastException}} | Removes the previously set runtime setting. If the setting wasn't already set, then a warning is issued, unless 'function.remove_runtime_setting.no_warn_on_removing_blank' is set to true. | Yes |- | [[API/functions/run|run]]() | void | string command | {{object|FormatException}}
{{object|PluginInternalException}} | Runs a command as the current player. Useful for running commands in a loop. Note that this accepts commands like from the chat; with a forward slash in front. | No |- | [[API/functions/run_cmd|run_cmd]]() | void | cmd | {{object|FormatException}} | Runs a command regardless of whether or not it is an alias or a builtin command. Essentially, this works like checking if(is_alias(@cmd)){ call_alias(@cmd) } else { run(@cmd) }. Be careful with this command, as like call_alias(), you could accidentally create infinite loops. The command must start with a / or this will throw a FormatException. | No |- | [[API/functions/runas|runas]]() | void | player, command | {{object|FormatException}}
{{object|PlayerOfflineException}} | Runs a command as a particular online player. The special name '~console' can be used to run it as console. If you want to run the command as if the player was op, use {{function|sudo}} instead. If the first argument is an array of usernames, the command will be run in the context of each user in the array. | Yes |- | [[API/functions/scriptas|scriptas]]() | void | sender, [label], script | {{object|PlayerOfflineException}} | Runs the specified script in the context of a given player or ~console. A script that runs player(), for instance, would return the specified player's name, not the player running the command. Setting the label allows you to dynamically set the label this script is run under as well (in regards to permission checking) | Yes |- | [[API/functions/set_runtime_setting|set_runtime_setting]]() | void | name, setting | {{object|CastException}} | Sets the value of a particular runtime setting. Various system components can define these differently, so see the documentation for a particular component to see if it has a runtime setting that can be changed, and what the name and setting should be. Note that there is intentionally no mechanism provided to get the value of a setting, as this is not meant to be used for user settings, just system level settings. To set your own user based settings, use {{function|import}}/{{function|export}}. | Yes |- | [[API/functions/sudo|sudo]]() | void | [player], command | {{object|FormatException}} | Runs a single command for the current or provided player, as op. [[API/functions/sudo|See more...]]
| Yes |} == Minecraft ==
These functions provide a hook into game functionality.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/all_materials|all_materials]]()
| array
|
|
| Returns an array of all material names.
| No
|-
| [[API/functions/convert_legacy_item|convert_legacy_item]]()
| array
| itemArray
| {{object|CastException}}{{object|FormatException}}
{{object|RangeException}}
{{object|NotFoundException}} | Converts old pre-1.13 item arrays to new item arrays. Almost all item arrays will be converted successfully when passing them to a function that accepts item arrays. However, if the array is missing the 'type' key, several item types might not convert accurately due to name conflicts. This function offers convenience and ensures better conversion accuracy. Use this if you have item arrays stored in a database and want to convert them all at once. Passing new item arrays to this function is not supported. Conversions may not be supported in far future versions of Minecraft. | No |- | [[API/functions/data_name|data_name]]() | string | item | {{object|CastException}}
{{object|FormatException}} | Returns a modern material for the a legacy item id, name, notation, or array. If an invalid argument is passed in, null is returned. Given 1 or '1:0', returns 'STONE'. Given an item array with {name: STONE, data: 1}, returns 'GRANITE'. | No |- class="hiddenFunction" | [[API/functions/data_values|data_values]]() | int | var1 | | Does a lookup to return the legacy data value of a name. For instance, returns 1 for 'stone'. If the data value cannot be found, null is returned. This function is deprecated and should only be used to convert legacy data that used CommandHelper's old material aliases. To be removed in version 3.3.6. | No |- | [[API/functions/get_banned_players|get_banned_players]]() | array | | | An array of players banned on the server. | No |- | [[API/functions/get_ip_bans|get_ip_bans]]() | array | | | Returns an array of entries from banned-ips.txt. | Yes |- | [[API/functions/get_server_info|get_server_info]]() | mixed | [value] | {{object|CastException}}
{{object|RangeException}}
{{object|NotFoundException}} | Returns various information about server.If value is set, it should be an integer of one of the following indexes, and only that information for that index will be returned. [[API/functions/get_server_info|See more...]]
| No |- | [[API/functions/get_spawner_type|get_spawner_type]]() | string | locationArray | {{object|FormatException}} | Gets the entity type that will spawn from the specified mob spawner. | Yes |- | [[API/functions/get_whitelisted_players|get_whitelisted_players]]() | array | | | An array of players whitelisted on the server. | No |- | [[API/functions/make_effect|make_effect]]() | void | locationArray, effect, [radius] | {{object|CastException}}
{{object|FormatException}} | Plays the specified effect at the given location for all players within the radius (or 64 by default). [[API/functions/make_effect|See more...]]
| Yes |- | [[API/functions/material_info|material_info]]() | mixed | material, [trait] | {{object|CastException}}
{{object|FormatException}}
{{object|IllegalArgumentException}} | Returns an array of info about the material. If a trait is specified, it returns only that trait. Available traits: hasGravity, isBlock, isItem, isBurnable, isEdible, isFlammable, isOccluding, isRecord, isSolid, isTransparent, isInteractable, maxDurability, hardness (for block materials only), blastResistance (for block materials only), and maxStacksize. The accuracy of these values depend on the server implementation. | No |- | [[API/functions/max_stack_size|max_stack_size]]() | integer | itemArray | {{object|CastException}}
{{object|FormatException}}
{{object|RangeException}}
{{object|NotFoundException}} | Given an item array, returns the maximum allowed stack size. This method will accept an item array like is returned from pinv(). | No |- | [[API/functions/monitor_redstone|monitor_redstone]]() | void | location, [isMonitored] | {{object|CastException}}
{{object|FormatException}} | Sets up a location to be monitored for redstone changes. If a location is monitored, it will cause redstone_changed events to be triggered. By default, isMonitored is true, however, setting it to false will remove the previously monitored location from the list of monitors. | Yes |- | [[API/functions/select_entities|select_entities]]() | array | [player], selector | {{object|FormatException}}
{{object|LengthException}}
{{object|PlayerOfflineException}} | Returns an array of all matching entities for a Minecraft target selector. The selector will use the current command sender context unless a player is specified. Selector must be a valid vanilla target selector for the current version of Minecraft or a FormatException will be thrown. | Yes |- | [[API/functions/send_resourcepack|send_resourcepack]]() | void | player, url | {{object|PlayerOfflineException}} | Sends a resourcepack URL to the player's client. If the client has not been requested to change resources in the past, they will receive a confirmation dialog before downloading and switching to the new pack. Clients that ignore server resources will not receive the request, so this function will not affect them. | Yes |- | [[API/functions/set_ip_banned|set_ip_banned]]() | void | address, banned | | If banned is true, address is added to banned-ips.txt, if false, the address is removed. | Yes |- | [[API/functions/set_spawner_type|set_spawner_type]]() | void | locationArray, type | {{object|FormatException}} | Sets the mob spawner's entity type at the location specified. If the location is not a mob spawner, or if the type is invalid, a FormatException is thrown. [[API/functions/set_spawner_type|See more...]]
| Yes |- | [[API/functions/shutdown_server|shutdown_server]]() | void | | | Shuts down the minecraft server instance. | Yes |} == MobManagement ==
These functions manage specifically living entities. If the entity specified is not living, a BadEntityTypeException will be thrown.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/add_entity_attribute_modifier|add_entity_attribute_modifier]]()
| void
| entityUUID, modifier
| {{object|CastException}}{{object|LengthException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Adds an attribute modifier to an entity. Throws BadEntityTypeException if the attribute type does not apply to this entity type. See {{function|get_itemmeta}} for how to define an attribute modifier array. | Yes |- | [[API/functions/can_pickup_items|can_pickup_items]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether the specified living entity can pick up items. | Yes |- | [[API/functions/damage_entity|damage_entity]]() | void | entityUUID, amount, [sourceEntityUUID] | {{object|CastException}}
{{object|LengthException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Damage an entity. If given, the source entity will be attributed as the damager. | Yes |- | [[API/functions/entity_air|entity_air]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the amount of air the specified living entity has remaining. | Yes |- | [[API/functions/entity_attribute_base|entity_attribute_base]]() | double | entityUUID, attribute | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Gets the base value for the given attribute of this entity. [[API/functions/entity_attribute_base|See more...]]
| Yes |- | [[API/functions/entity_attribute_default|entity_attribute_default]]() | double | entityUUID, attribute | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Gets the default value for the attribute of this entity's type. [[API/functions/entity_attribute_default|See more...]]
| Yes |- | [[API/functions/entity_attribute_modifiers|entity_attribute_modifiers]]() | array | entityUUID, attribute | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Gets an array of modifier arrays for this entity's attribute. [[API/functions/entity_attribute_modifiers|See more...]]
| Yes |- | [[API/functions/entity_attribute_value|entity_attribute_value]]() | double | entityUUID, attribute | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Gets the effective value for the attribute of this entity after all modifiers have been applied to the base value. [[API/functions/entity_attribute_value|See more...]]
| Yes |- | [[API/functions/entity_can_see|entity_can_see]]() | boolean | entityUUID, otherEntityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether or not the first entity can have the other entity in an unimpeded line of sight, ignoring the direction it's facing. For instance, for players this mean that it can have the other entity on its screen and that this one is not hidden by opaque blocks. This uses the same algorithm that hostile mobs use to find the closest player. | Yes |- | [[API/functions/entity_line_of_sight|entity_line_of_sight]]() | array | entityUUID, [transparents, [maxDistance]] | {{object|CastException}}
{{object|LengthException}}
{{object|BadEntityException}} | Returns an array containing all blocks along the living entity's line of sight. transparents is an array of block IDs, only air by default. maxDistance represents the maximum distance to scan. The server may cap the scan distance, but probably by not any less than 100 meters. | Yes |- | [[API/functions/entity_max_air|entity_max_air]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the maximum amount of air the specified living entity can have. | Yes |- | [[API/functions/get_entity_ai|get_entity_ai]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if the given entity has AI. | Yes |- | [[API/functions/get_entity_breedable|get_entity_breedable]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns if an entity is set to be breedable. | Yes |- | [[API/functions/get_entity_gliding|get_entity_gliding]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns true if the given entity is gliding. | Yes |- | [[API/functions/get_entity_health|get_entity_health]]() | double | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the entity's health as a percentage of its maximum health. If the specified entity doesn't exist, or is not a LivingEntity, a format exception is thrown. | Yes |- | [[API/functions/get_entity_immunity_ticks|get_entity_immunity_ticks]]() | int | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Gets the number of immunity ticks a living entity has remaining. After being damaged, an entity is given 10 ticks of immunity from equal or lesser damage. | Yes |- | [[API/functions/get_entity_persistence|get_entity_persistence]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether the specified living entity will despawn. True means it will not. | Yes |- | [[API/functions/get_equipment_droprates|get_equipment_droprates]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an associative array of the drop rate for each equipment slot. If the rate is 0.0, the equipment will not drop. A rate of 1.0 will guarantee a drop if the entity is killed by a player. A rate above 1.0 will guarantee a drop by any cause. Non-mobs, like players and armor stands, cannot have their drop-rates modified. | Yes |- | [[API/functions/get_leashholder|get_leashholder]]() | string | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the UUID of the entity that is holding the given living entity's leash, or null if it isn't being held. | Yes |- | [[API/functions/get_max_health|get_max_health]]() | double | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns the maximum health of this living entity. | Yes |- | [[API/functions/get_mob_age|get_mob_age]]() | int | entityUUID | {{object|UnageableMobException}}
{{object|LengthException}}
{{object|BadEntityException}} | Returns the mob's age as an integer. Zero represents the point of adulthood. Throws an UnageableMobException if the mob is not a type that ages | Yes |- | [[API/functions/get_mob_effects|get_mob_effects]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an array of potion effect arrays showing the effects on this mob.
([[API/functions/get_mob_effects#Examples|Examples...]]) | Yes |- | [[API/functions/get_mob_equipment|get_mob_equipment]]() | array | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns an associative array showing the equipment this mob is wearing. This only works on mobs and armor stands.
([[API/functions/get_mob_equipment#Examples|Examples...]]) | Yes |- | [[API/functions/get_mob_love_ticks|get_mob_love_ticks]]() | int | entityUUID | {{object|BadEntityTypeException}}
{{object|LengthException}}
{{object|BadEntityException}} | Returns the number of ticks remaining that this mob will be in love mode. | Yes |- | [[API/functions/get_mob_owner|get_mob_owner]]() | string | entityUUID | {{object|UntameableMobException}}
{{object|LengthException}}
{{object|BadEntityException}}
{{object|IllegalArgumentException}} | Returns the owner's name, or null if the mob is unowned.An UntameableMobException is thrown if mob isn't tameable to begin with. | Yes |- | [[API/functions/get_mob_target|get_mob_target]]() | string | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Gets the mob's target if it has one, and returns the target's entityUUID. If there is no target, null is returned instead. Not all mobs will have a returnable target. | Yes |- | [[API/functions/is_entity_sleeping|is_entity_sleeping]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Gets if a living entity is sleeping or not. Only some entity types can sleep. | Yes |- | [[API/functions/is_mob_collidable|is_mob_collidable]]() | boolean | entityUUID | {{object|LengthException}}
{{object|BadEntityException}} | Returns whether another entity, like an arrow, will collide with this mob. | Yes |- | [[API/functions/remove_entity_attribute_modifier|remove_entity_attribute_modifier]]() | void | entityUUID, modifier
entityUUID, attribute, id | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Removes an attribute modifier from an entity. Can provide either a modifier array or just the attribute and namespaced id of the modifier. | Yes |- | [[API/functions/reset_entity_attribute_base|reset_entity_attribute_base]]() | void | entityUUID, attribute | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Resets the base attribute value to the default for this entity. [[API/functions/reset_entity_attribute_base|See more...]]
| Yes |- | [[API/functions/set_can_pickup_items|set_can_pickup_items]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets a living entity's ability to pick up items. | Yes |- | [[API/functions/set_entity_ai|set_entity_ai]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | enables or disables the entity AI. | Yes |- | [[API/functions/set_entity_air|set_entity_air]]() | void | entityUUID, int | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the amount of air the specified living entity has remaining. | Yes |- | [[API/functions/set_entity_attribute_base|set_entity_attribute_base]]() | void | entityUUID, attribute, value | {{object|CastException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityTypeException}}
{{object|BadEntityException}} | Sets the base value for the entity attribute. Accepts a double as the value. [[API/functions/set_entity_attribute_base|See more...]]
| Yes |- | [[API/functions/set_entity_breedable|set_entity_breedable]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Set an entity to be breedable. | Yes |- | [[API/functions/set_entity_gliding|set_entity_gliding]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | If possible, makes the entity glide. | Yes |- | [[API/functions/set_entity_health|set_entity_health]]() | void | entityUUID, healthPercent | {{object|CastException}}
{{object|BadEntityException}}
{{object|RangeException}}
{{object|LengthException}} | Sets the specified entity's health as a percentage, where 0 kills it and 100 gives it full health. An exception is thrown if the entity by that UUID doesn't exist or isn't a LivingEntity. | Yes |- | [[API/functions/set_entity_immunity_ticks|set_entity_immunity_ticks]]() | void | entityUUID, int | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the number of immunity ticks a living entity has remaining. | Yes |- | [[API/functions/set_entity_max_air|set_entity_max_air]]() | void | entityUUID, int | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the maximum amount of air the specified living entity can have. | Yes |- | [[API/functions/set_entity_persistence|set_entity_persistence]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets whether a living entity will despawn. True means it will not. | Yes |- | [[API/functions/set_equipment_droprates|set_equipment_droprates]]() | void | entityUUID, array | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the drop chances for each equipment slot on a mob, but does not work on players. Passing null instead of an array will automatically set all rates to 0.0, which will cause nothing to drop. A rate of 1.0 will guarantee a drop if the entity is killed by a player. A rate above 1.0 will guarantee a drop by any cause. Non-mobs, like players and armor stands, cannot have their drop-rates modified. | Yes |- | [[API/functions/set_leashholder|set_leashholder]]() | void | entityUUID, entityUUID | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | The first argument is the entity to be held on a leash, and must be living. The second is the holder of the leash. This does not have to be living, but the only non-living entity that will persist as a holder across restarts is the leash hitch. Players, bats, enderdragons, withers and certain other entities can not be held by leashes due to minecraft limitations. | Yes |- | [[API/functions/set_max_health|set_max_health]]() | void | entityUUID, double | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets the max health of a living entity, players included. This value is persistent, and will not reset even after server restarts.
([[API/functions/set_max_health#Examples|Examples...]]) | Yes |- | [[API/functions/set_mob_age|set_mob_age]]() | void | entityUUID, int[, lockAge] | {{object|UnageableMobException}}
{{object|CastException}}
{{object|BadEntityException}}
{{object|LengthException}} | sets the age of the mob to the specified int, and locks it at that age if lockAge is true, but by default it will not. (locking only applies to breedable mobs) Throws a UnageableMobException if the mob does not age naturally. | Yes |- | [[API/functions/set_mob_collidable|set_mob_collidable]]() | void | entityUUID, boolean | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets whether or not other entities will collide with this mob. | Yes |- | [[API/functions/set_mob_effect|set_mob_effect]]() | boolean | entityUUID, potionEffect, [strength], [seconds], [ambient], [particles] | {{object|LengthException}}
{{object|FormatException}}
{{object|BadEntityException}}
{{object|RangeException}} | Adds one, or modifies an existing, potion effect on a mob. The potionEffect can be SLOWNESS, INVISIBILITY, SLOW_FALLING, BAD_OMEN, WEAKNESS, DOLPHINS_GRACE, INSTANT_DAMAGE, MINING_FATIGUE, TRIAL_OMEN, SPEED, WITHER, LUCK, FIRE_RESISTANCE, WIND_CHARGED, WATER_BREATHING, GLOWING, OOZING, ABSORPTION, HUNGER, BAD_LUCK, HERO_OF_THE_VILLAGE, REGENERATION, INFESTED, WEAVING, STRENGTH, BLINDNESS, LEVITATION, CONDUIT_POWER, RAID_OMEN, JUMP_BOOST, POISON, NAUSEA, RESISTANCE, HEALTH_BOOST, DARKNESS, NIGHT_VISION, INSTANT_HEALTH, HASTE, or SATURATION. It also accepts an integer corresponding to the effect id listed on the Minecraft wiki. Strength is an integer representing the power level of the effect, starting at 0. Seconds defaults to 30.0. To remove an effect, set the seconds to 0. If seconds is greater than 107374182 a RangeException is thrown. Negative seconds makes the effect infinite. (or max in versions prior to 1.19.4) Ambient takes a boolean of whether the particles should be more transparent. Particles takes a boolean of whether the particles should be visible at all. The function returns whether or not the effect was modified. | Yes |- | [[API/functions/set_mob_equipment|set_mob_equipment]]() | void | entityUUID, array | {{object|FormatException}}
{{object|LengthException}}
{{object|BadEntityException}} | Takes an associative array with keys representing equipment slots and values of itemArrays, the same used by set_pinv(). This only works on mobs and armor stands. Unless a mod, plugin, or future update changes vanilla functionality, only humanoid mobs will render their equipment slots. The equipment slots are: WEAPON, OFF_HAND, BOOTS, LEGGINGS, CHESTPLATE, or HELMET
([[API/functions/set_mob_equipment#Examples|Examples...]]) | Yes |- | [[API/functions/set_mob_love_ticks|set_mob_love_ticks]]() | void | entityUUID, int | {{object|BadEntityTypeException}}
{{object|CastException}}
{{object|BadEntityException}}
{{object|LengthException}} | Sets the number of ticks that this mob will be in love mode. | Yes |- | [[API/functions/set_mob_owner|set_mob_owner]]() | void | entityUUID, player | {{object|UntameableMobException}}
{{object|LengthException}}
{{object|BadEntityException}}
{{object|IllegalArgumentException}} | Sets the tameable mob to the specified player. Offline players are supported, but this means that partial matches are NOT supported. You must type the player's name exactly. Setting the player to null will untame the mob. | Yes |- | [[API/functions/set_mob_target|set_mob_target]]() | void | entityUUID, entityUUID | {{object|BadEntityException}}
{{object|LengthException}} | The first is the entity that is targeting, the second is the target. It can also be set to null to clear the current target. Not all mobs can have their target set. | Yes |} == OAuth ==
This class provides methods for interfacing with OAuth providers.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/clear_oauth_tokens|clear_oauth_tokens]]()
| void
| [clientId]
|
| Clears the oauth tokens (refresh token and access token) for the given client ID. If the client ID is not specified, all tokens are deleted. This is useful if various oath tokens have been revoked, or you would specifically like to prevent caching of those tokens.
| Yes
|- class="hiddenFunction"
| [[API/functions/x_get_oauth_token|x_get_oauth_token]]()
| void
|
|
|
| Yes
|}
== OS ==
Contains various methods for interacting with the Operating System. Some of the functions deal with OS specific mechanisms.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/get_pid|get_pid]]()
| int
|
| {{object|UnsupportedOperationException}}
| Returns the process id (pid) of the current process. In some implementations of Java, this cannot be relied on, and in those cases, an UnsupportedOperationException is thrown. In Java 9 and above, this can generally be relied upon to work correctly, however.
| Yes
|}
== ObjectManagement ==
Provides functions for creating and using objects. None of these methods should normally be used, all of them provide easier to use compiler support.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|- class="hiddenFunction"
| [[API/functions/define_object|define_object]]()
| void
| AccessModifier accessModifier, arrayThis class provides functions for hooking into CommandHelper's powerful Performance measuring. To use the functions, you must have allow-profiling option set to true in your preferences file.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/enable_performance_logging|enable_performance_logging]]()
| void
| boolean
| {{object|SecurityException}}
| Enables performance logging. The allow-profiling option must be set to true in your preferences file, and play-dirty mode must be active. If allow-profiling is set to false, a SecurityException is thrown. The debug filters are used by the performance logger, if you choose to filter through the events. See the documentation for more details on performance logging.
| Yes
|}
== Permissions ==
Provides access to the server's underlying permissions system. Permissions functionality is only as good as the management system in place, however, and so not all functions may be supported on a given system.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/has_permission|has_permission]]()
| boolean
| [player], permissionName
| {{object|InsufficientPermissionException}}{{object|PlayerOfflineException}} | Using the built in permissions system, checks to see if the player has a particular permission. This is simply passed through to the permissions system. This function is only restricted if the player attempts to check another player's permissions. If run from the console or a CommandBlock, will always return true unless a value has been explicitly set for them. | No |} == Persistence ==
Allows scripts to store data from execution to execution. See the guide on [[Persistence_Network|persistence]] for more information. In all the functions, you may send multiple arguments for the key, which will automatically be concatenated with a period (the namespace separator). No magic happens here, you can put periods yourself, or combine manually namespaced values or automatically namespaced values with no side effects. All the functions in the Persistence API are threadsafe (though not necessarily process safe).
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/clear_value|clear_value]]()
| void
| [namespace, ...,] key
| {{object|IOException}}{{object|FormatException}} | Completely removes a value from storage. Calling has_value(key) after this call will return false. | Yes |- | [[API/functions/get_value|get_value]]() | mixed | [namespace, ...,] key | {{object|IOException}}
{{object|FormatException}} | Returns a stored value stored with store_value. If the key doesn't exist in storage, null is returned. On a more detailed note: If the value stored in the persistence database is not actually a construct, then null is also returned. | Yes |- | [[API/functions/get_values|get_values]]() | array | name[, space, ...] | {{object|IOException}}
{{object|FormatException}} | Returns all the values in a particular namespace as an associative array(key: value, key: value). Only full namespace matches are considered, so if the key 'users.data.username.hi' existed in the database, and you tried get_values('users.data.user'), nothing would be returned. The last segment in a key is also considered a namespace, so 'users.data.username.hi' would return a single value (in this case).
([[API/functions/get_values#Examples|Examples...]]) | Yes |- | [[API/functions/has_value|has_value]]() | boolean | [namespace, ...,] key | {{object|IOException}}
{{object|FormatException}} | Returns whether or not there is data stored at the specified key in the Persistence database. | Yes |- | [[API/functions/store_value|store_value]]() | void | [namespace, ...,] key, value | {{object|FormatException}}
{{object|IOException}}
{{object|FormatException}} | Allows you to store a value, which can then be retrieved later. key must be a string containing only letters, numbers, underscores. Periods may also be used, but they form a namespace, and have special meaning. (See get_values()) | Yes |} == PlayerManagement ==
This class of functions allow players to be managed. Functions that accept an online player's name will also accept their UUID.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/all_players|all_players]]()
| array
| [world]
| {{object|InvalidWorldException}}
| Returns an array of all the player names of all the online players on the server. If world is given only the name of the players in this world will be returned.([[API/functions/all_players#Examples|Examples...]]) | Yes |- | [[API/functions/clear_peffects|clear_peffects]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Removes all potion effects from a player. | Yes |- | [[API/functions/display_name|display_name]]() | string | [player] | {{object|LengthException}}
{{object|PlayerOfflineException}} | Returns the display name of the player.
([[API/functions/display_name#Examples|Examples...]]) | No |- | [[API/functions/get_compass_target|get_compass_target]]() | array | [player] | {{object|PlayerOfflineException}} | Gets the compass target location for the specified player. | Yes |- | [[API/functions/get_list_name|get_list_name]]() | string | [player] | {{object|PlayerOfflineException}} | Returns the name of the player that's display on the player list. | Yes |- | [[API/functions/get_offline_players|get_offline_players]]() | array | | | Returns an array of every player who has played on this server.
([[API/functions/get_offline_players#Examples|Examples...]]) | Yes |- | [[API/functions/get_peffect|get_peffect]]() | array | [player] | {{object|PlayerOfflineException}} | Returns an array of potion effects that are currently active on a given player. The array can contain potion effect objects, with the key defining the type of potion effect. The arrays contain the following fields: "id", "strength", "seconds" remaining, whether the effect is "ambient", whether "particles" are enabled, and whether the "icon" is shown to the player. | Yes |- | [[API/functions/get_pflyspeed|get_pflyspeed]]() | double | [player] | {{object|PlayerOfflineException}}
{{object|FormatException}} | Gets a player's fly speed. The speed will be between -1.0 and 1.0. | Yes |- | [[API/functions/get_player_input|get_player_input]]() | array | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Returns a player's current input. (MC 1.21.3+) This can be used to detect which movement keys the player is pressing. Array contains the following keys: forward, backward, left, right, jump, sneak, and sprint. | Yes |- | [[API/functions/get_player_ping|get_player_ping]]() | int | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Returns a player's average response time to ping packets in milliseconds. This is an indicator of the quality of the player's connection, as represented in the tab list. | No |- | [[API/functions/get_plist_footer|get_plist_footer]]() | string | [player] | {{object|LengthException}}
{{object|PlayerOfflineException}} | Gets the player list footer for a player. This is the text that appears below the player list that appears when hitting the tab key. | Yes |- | [[API/functions/get_plist_header|get_plist_header]]() | string | [player] | {{object|LengthException}}
{{object|PlayerOfflineException}} | Gets the player list header for a player. This is the text that appears above the player list that appears when hitting the tab key. | Yes |- | [[API/functions/get_pwalkspeed|get_pwalkspeed]]() | double | [player] | {{object|PlayerOfflineException}}
{{object|FormatException}} | Gets a player's walk speed. The speed will be between -1.0 and 1.0. | Yes |- | [[API/functions/give_pexp|give_pexp]]() | void | [player], exp | {{object|PlayerOfflineException}}
{{object|CastException}} | Gives the player the specified amount of experience. | Yes |- | [[API/functions/pattack_cooldown|pattack_cooldown]]() | double | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Gets the charge value of the player's attack cooldown. This is a double with range 0.0-1.0 inclusive. 1.0 is fully charged, while 0.0 is no charge. | Yes |- | [[API/functions/pbanned|pbanned]]() | boolean | player | {{object|NotFoundException}} | Returns whether or not this player is banned. This will work with offline players, but the name must be exact. At this time, this function only works with the vanilla ban system. If you use a third party ban system, you should instead run the command for that plugin instead. [[API/functions/pbanned|See more...]]
| Yes |- | [[API/functions/pbed_location|pbed_location]]() | array | [playerName] | {{object|InsufficientArgumentsException}}
{{object|NotFoundException}} | Returns a location array of the bed block the player last slept in. The player will normally respawn next to this bed if they die. However, this respawn location can be forcibly be set by plugins or commands to any location, like when using set_pbed_location(). | Yes |- | [[API/functions/pblocking|pblocking]]() | boolean | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Gets if a player is blocking or not. | Yes |- | [[API/functions/pborder|pborder]]() | array | [player] | {{object|PlayerOfflineException}} | Returns an associative array for the player's virtual world border. (MC 1.18.2+) The keys are 'width', 'center', 'warningtime', and 'warningdistance'. Returns null if the player is using the existing border for the world that they're in. | Yes |- | [[API/functions/pcan_see_entity|pcan_see_entity]]() | boolean | [player], entityUUID | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|BadEntityException}} | Gets whether the entity is known by the player's client or hidden by a plugin. (MC 1.18+) | Yes |- | [[API/functions/pcooldown|pcooldown]]() | int | [player], material | {{object|LengthException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Gets the time left on the player's cooldown for the specified item type. This returns an integer representing the time in server ticks until any items of this material can be used again by this player. | Yes |- | [[API/functions/pcursor|pcursor]]() | array | [player], [array] | {{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|FormatException}}
{{object|CastException}}
{{object|PluginInternalException}} | Returns a location array with the coordinates of the block the player has highlighted in their crosshairs. If player is omitted, the current player is used. If the block is too far, a RangeException is thrown. An array of block types to be considered transparent can be supplied, otherwise only air will be considered transparent. Providing an empty array will cause air to be considered a potential target, allowing a way to get the block containing the player's head. On paper servers, this teleports passengers of the player as well.
([[API/functions/pcursor#Examples|Examples...]]) | Yes |- | [[API/functions/pexp|pexp]]() | int | [player] | {{object|CastException}}
{{object|PlayerOfflineException}} | Gets the experience of a player within this level, as a percentage, from 0 to 99. (100 would be next level, therefore, 0.) | Yes |- | [[API/functions/pfacing|pfacing]]() | mixed | F
yaw, pitch
player, F
player, yaw, pitch
player
<none> | {{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|CastException}}
{{object|NotFoundException}} | Gets or sets the direction the player is facing. [[API/functions/pfacing|See more...]]
| Yes |- | [[API/functions/pfirst_played|pfirst_played]]() | int | [player] | | Returns the unix time stamp, in milliseconds, that this player first logged onto this server, or 0 if they never have. The player argument can be a UUID or a name. But if given a name, it must be exact.
([[API/functions/pfirst_played#Examples|Examples...]]) | Yes |- | [[API/functions/pflying|pflying]]() | boolean | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Gets the flying state for the player. | Yes |- | [[API/functions/pfood|pfood]]() | int | [player] | {{object|PlayerOfflineException}} | Returns the player's current food level. | Yes |- | [[API/functions/pforce_respawn|pforce_respawn]]() | void | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Forces a player to respawn immediately if they're currently dead. | Yes |- | [[API/functions/pget_time|pget_time]]() | int | [player] | {{object|PlayerOfflineException}} | Returns the time of the specified player, as an integer from 0 to 24000-1 | Yes |- | [[API/functions/pgive_recipe|pgive_recipe]]() | int | [player], recipeKey(s) | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|FormatException}} | Adds one or more recipes to a player's recipe book. Can take a single recipe key or an array of keys. Returns how many recipes were newly discovered. | Yes |- | [[API/functions/pgroup|pgroup]]() | array | [playerName] | {{object|PlayerOfflineException}} | Returns an array of the groups a player is in. If playerName is omitted, the current player is used. This relies on "group.groupname" permission nodes in your permissions plugin. Otherwise an extension is required to get the groups from the plugin. | Yes |- | [[API/functions/phas_flight|phas_flight]]() | boolean | [player] | {{object|PlayerOfflineException}} | Returns whether or not the player has the ability to fly. | Yes |- | [[API/functions/phas_played|phas_played]]() | boolean | player | | Returns whether the given player has ever been on this server. The player argument can be a UUID or a name. But if given a name, it must be exact.
([[API/functions/phas_played#Examples|Examples...]]) | Yes |- | [[API/functions/phas_recipe|phas_recipe]]() | boolean | [player], recipeKey | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|FormatException}} | Gets whether a player has a recipe in their recipe book. | Yes |- | [[API/functions/phas_storm|phas_storm]]() | boolean | [player] | {{object|PlayerOfflineException}} | Returns true if the given player is experiencing a storm, as set by set_pstorm(). (ignores world weather) | Yes |- | [[API/functions/phealth|phealth]]() | double | [player] | {{object|LengthException}}
{{object|PlayerOfflineException}} | Gets the player's health. | Yes |- | [[API/functions/phide_entity|phide_entity]]() | void | [player], entityUUID | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets an entity to no longer be seen or tracked by the player's client. Resets to default on player rejoin. (MC 1.18+) | Yes |- | [[API/functions/phunger|phunger]]() | int | [player] | {{object|PlayerOfflineException}} | Returns the player's hunger level. | Yes |- | [[API/functions/pinfo|pinfo]]() | mixed | [player], [value] | {{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|CastException}}
{{object|NotFoundException}} | Returns various information about the player specified, or the current player if no argument was given. [[API/functions/pinfo|See more...]]
| Yes |- | [[API/functions/pisop|pisop]]() | boolean | [player] | {{object|PlayerOfflineException}} | Returns whether or not the player is op. | Yes |- | [[API/functions/pkick|pkick]]() | void | [playerName], [message] | {{object|PlayerOfflineException}} | Kicks the specified player with an optional message. If no message is specified, "You have been kicked" is used. If no player is specified, the current player is used with the default message. | Yes |- | [[API/functions/pkill|pkill]]() | void | [playerName] | {{object|PlayerOfflineException}} | Kills the specified player, or the current player if a name is omitted. | Yes |- | [[API/functions/plast_known_name|plast_known_name]]() | string | uuid | {{object|LengthException}} | Returns the name for this player the last time they were on the server. Return null if the player has never been on the server. This is not guaranteed to be their current player name. This is read directly from the player data file for offline players. | Yes |- | [[API/functions/plast_played|plast_played]]() | int | [player] | | Returns the unix time stamp, in milliseconds, that this player was last seen on this server, or 0 if they never were. The player argument can be a UUID or a name. But if given a name, it must be exact.
([[API/functions/plast_played#Examples|Examples...]]) | Yes |- | [[API/functions/player|player]]() | string | [playerName]
[uuid] | {{object|PlayerOfflineException}} | Returns a player's name. If a string is specified, it will attempt to find a complete match for a partial name. If no string is specified, the current player is returned. UUIDs are also accepted for this and other functions that apply to online players. If the command is being run from the console, then the string '~console' is returned. If the command came from a CommandBlock, the block's name prefixed with # is returned. If the command is coming from elsewhere, returns a string chosen by the sender of this command (or null). Note that most functions won't support console or block names (they'll throw a PlayerOfflineException), but you can use this to determine where a command is being run from. | No |- | [[API/functions/players_in_radius|players_in_radius]]() | array | [locationArray], distance | {{object|CastException}}
{{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|NotFoundException}} | Returns an array of all the players within the given radius. | Yes |- | [[API/functions/plevel|plevel]]() | int | [player] | {{object|CastException}}
{{object|PlayerOfflineException}} | Gets the player's level. | Yes |- | [[API/functions/ploc|ploc]]() | array | [playerName] | {{object|PlayerOfflineException}}
{{object|NotFoundException}} | Returns a location array of the coordinates of the player specified, or the player running the command if no player is specified. Note that unlike entity_loc() the y coordinate will be for the block the player is standing on, which is one meter lower. The array returned also includes the player's world, yaw and pitch. | Yes |- | [[API/functions/plocale|plocale]]() | string | [player] | {{object|PlayerOfflineException}} | Gets the player's locale. | Yes |- | [[API/functions/pmode|pmode]]() | string | [player] | {{object|PlayerOfflineException}}
{{object|NotFoundException}} | Returns the player's game mode. It will be one of SURVIVAL, CREATIVE, ADVENTURE, or SPECTATOR. | Yes |- | [[API/functions/ponfire|ponfire]]() | int | [player] | {{object|PlayerOfflineException}} | Returns the number of ticks remaining that this player will be on fire for. If the player is not on fire, 0 is returned, which evaluates as false. | Yes |- | [[API/functions/ponline|ponline]]() | boolean | player | | Returns whether or not the specified player is online. Note that the name must match exactly, but it will not throw a PlayerOfflineException if the player is not online, or if the player doesn't even exist. | Yes |- | [[API/functions/preset_time|preset_time]]() | void | [player] | {{object|InvalidWorldException}}
{{object|PlayerOfflineException}} | Resets the visible time for the player to the time of the world. | Yes |- | [[API/functions/psaturation|psaturation]]() | double | [player] | {{object|RangeException}}
{{object|PlayerOfflineException}} | Returns the player's food saturation level. | Yes |- | [[API/functions/psend_block_change|psend_block_change]]() | void | [player], locationArray, block | {{object|FormatException}}
{{object|PlayerOfflineException}} | Changes a block temporarily for the specified player. This can be used to "fake" blocks for a player. These illusory blocks will disappear when the client updates them, most often by clicking on them or reloading the chunks. Sending null will reset the block to its existing state in the world. A block type or blockdata format is supported. (see set_blockdata_string()) | Yes |- | [[API/functions/psend_block_damage|psend_block_damage]]() | void | [player], locationArray, progress, [entity] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|LengthException}}
{{object|PlayerOfflineException}}
{{object|RangeException}} | Sends the player fake block damage progress. Progress is a percentage from 0.0 to 1.0, with 0.0 clearing any block damage. Alternatively you can specify the discrete damage state as an integer from 0 to 10. If a source entity UUID is specified, it will be as if that entity is damaging the block, otherwise the player will be used. If given null, damage will disregard source entity. If that entity damages a different block, the previous block's damage will be cleared. If unchanged, the damage will clear on its own after 20 seconds. On versions prior to Spigot 1.19.4 or Paper 1.19.2, the source entity will always be the player this block damage is being sent to. | Yes |- | [[API/functions/psend_equipment|psend_equipment]]() | void | [player], entityUUID, equipmentArray | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|BadEntityException}}
{{object|FormatException}} | Changes a living entity's equipment only for the specified player. (MC 1.18+) Equipment array can be null to make all equipment not visible. Otherwise equipment array must be an associative array where the keys are equipment slots and the values are item arrays or null. The equipment slots are: WEAPON, OFF_HAND, BOOTS, LEGGINGS, CHESTPLATE, or HELMET | Yes |- | [[API/functions/psend_sign_text|psend_sign_text]]() | void | [player], locationArray, 1, 2, 3, 4
[player], locationArray, array | {{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|CastException}} | Changes a sign's text only for the specified player. This will not change the sign in the world. If a normal array is used it cannot have more than 4 elements. If a line is null, the existing line will still be displayed. An associative array of sign data may be sent instead. This is the same as sign item meta, and can include the keys: 'signtext', 'color', 'glowing' (MC 1.17.1+), 'backtext' (MC 1.20.1+), 'backcolor' (MC 1.20.1+), and 'backglowing' (MC 1.20.1+). | Yes |- | [[API/functions/pshow_entity|pshow_entity]]() | void | [player], entityUUID | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|BadEntityException}} | Sets an entity to be sent to the player's client again. (MC 1.18+) | Yes |- | [[API/functions/psneaking|psneaking]]() | boolean | [player] | {{object|LengthException}}
{{object|PlayerOfflineException}} | Returns whether or not the player is sneaking. | Yes |- | [[API/functions/pspectator_target|pspectator_target]]() | string | [player] | {{object|PlayerOfflineException}}
{{object|IllegalArgumentException}} | Gets the entity UUID that a spectator is viewing. If the player isn't spectating from an entity, null is returned. If the player isn't in spectator mode, an IllegalArgumentException is thrown. | Yes |- | [[API/functions/psprinting|psprinting]]() | boolean | [player] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Gets if a player is sprinting or not. | Yes |- | [[API/functions/pstatistic|pstatistic]]() | int | [player], statistic, [type] | {{object|IllegalArgumentException}}
{{object|PlayerOfflineException}} | Returns the specified statistic for the player. Some statistics require a block, item or entity type. An IllegalArgumentException will be thrown if the statistic is invalid, or if the type is invalid for that statistic. The player argument is required before the type argument is. [[API/functions/pstatistic|See more...]]
| Yes |- | [[API/functions/ptarget_space|ptarget_space]]() | array | [player] | {{object|PlayerOfflineException}}
{{object|RangeException}} | Returns a location array of the space that the player is currently looking at. This is the space where if they placed a block (and were close enough), it would end up going. | Yes |- | [[API/functions/ptellraw|ptellraw]]() | void | [string selector], array raw | {{object|CastException}} | A thin wrapper around the tellraw command from player context, this simply passes the input to the command. The raw is passed in as a normal (possibly associative) array, and json encoded. No validation is done on the input, so the command may fail. If not provided, the selector defaults to @s. Do not use double quotes (smart string) when providing the selector. See {{function|tellraw}} if you don't need player context. [[API/functions/ptellraw|See more...]]
([[API/functions/ptellraw#Examples|Examples...]]) | Yes |- | [[API/functions/ptexp|ptexp]]() | int | [player] | {{object|CastException}}
{{object|PlayerOfflineException}} | Gets the total experience of a player. | Yes |- | [[API/functions/puuid|puuid]]() | string | [player], [dashless] | {{object|PlayerOfflineException}}
{{object|NotFoundException}} | Returns the UUID of the current player or the specified player. This will attempt to find an offline player, but if that also fails, a PlayerOfflineException will be thrown. [[API/functions/puuid|See more...]]
| No |- | [[API/functions/pvehicle|pvehicle]]() | string | [player] | {{object|PlayerOfflineException}} | Returns the UUID of the vehicle which the player is riding, or null if player is not riding a vehicle. | Yes |- | [[API/functions/pvehicle_leave|pvehicle_leave]]() | boolean | [player] | {{object|PlayerOfflineException}} | Forces a player to leave their vehicle. This returns false if the player is not riding a vehicle. | Yes |- | [[API/functions/pvelocity|pvelocity]]() | array | [player] | {{object|PlayerOfflineException}}
{{object|NotFoundException}} | Returns an associative array that represents the player's velocity. The array contains the following items: magnitude, x, y, z. These represent a 3 dimensional Vector. The important part is x, y, z, however, the magnitude is provided for you as a convenience. (It should equal sqrt(x ** 2 + y ** 2 + z ** 2)) | Yes |- | [[API/functions/pwhitelisted|pwhitelisted]]() | boolean | player | | Returns whether or not this player is whitelisted. This will work with offline players, but the name must be exact. [[API/functions/pwhitelisted|See more...]]
| Yes |- | [[API/functions/pworld|pworld]]() | string | [playerName] | {{object|PlayerOfflineException}} | Gets the world of the player specified, or the current player if playerName isn't specified. | Yes |- | [[API/functions/reset_display_name|reset_display_name]]() | void | [playerName] | {{object|PlayerOfflineException}} | Resets a player's display name to their real name. If playerName isn't specified, defaults to the player running the command.
([[API/functions/reset_display_name#Examples|Examples...]]) | Yes |- | [[API/functions/save_players|save_players]]() | void | | {{object|CastException}} | Saves current players to disk. | Yes |- | [[API/functions/set_compass_target|set_compass_target]]() | array | [player], locationArray | {{object|PlayerOfflineException}}
{{object|FormatException}} | Sets the player's compass target, and returns the old location. | Yes |- | [[API/functions/set_display_name|set_display_name]]() | void | [playerName], newDisplayName | {{object|PlayerOfflineException}} | Sets a player's display name. If the first name isn't provided, it sets the display name of the player running the command. See reset_display_name() also. All player functions expect the player's real name, not their display name.
([[API/functions/set_display_name#Examples|Examples...]]) | Yes |- | [[API/functions/set_list_name|set_list_name]]() | void | [player], [listName] | {{object|PlayerOfflineException}}
{{object|LengthException}} | Sets the player's list name. Colors are supported and setting the name to null resets it. | Yes |- | [[API/functions/set_pbanned|set_pbanned]]() | void | player, isBanned, [reason], [source] | {{object|NotFoundException}} | Sets the ban flag for the specified player. This will work with offline players, but the name must be exact. When banning, a reason message may be provided that the player will see when attempting to login. An optional source may also be provided that indicates who or what banned the player. At this time, this function only works with the vanilla ban system. If you use a third party ban system, you should instead run the command for that plugin instead. [[API/functions/set_pbanned|See more...]]
| Yes |- | [[API/functions/set_pbed_location|set_pbed_location]]() | void | [player], locationArray, [forced]
[player], x, y, z, [forced] | {{object|CastException}}
{{object|LengthException}}
{{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|NullPointerException}} | Sets the respawn location of a player. If player is omitted, the current player is used. The specified location should be the block below the respawn location. If forced is false, it will respawn the player next to that location only if a bed found is found there. (forced defaults to true) | Yes |- | [[API/functions/set_pborder|set_pborder]]() | void | player, paramArray | {{object|PlayerOfflineException}}
{{object|CastException}}
{{object|FormatException}}
{{object|RangeException}}
{{object|InvalidWorldException}} | Creates or updates a player's virtual world border. (MC 1.18.2+) In addition to the keys returned by pborder(), you can also specify 'seconds'. This is the time in which the border will move from the previous width to the new 'width'. If give null instead of an array, this resets the player's visible world border to the one of the world that they're in. | Yes |- | [[API/functions/set_pcooldown|set_pcooldown]]() | int | [player], material, cooldown | {{object|LengthException}}
{{object|FormatException}}
{{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|CastException}} | Sets the player's cooldown time for the specified item type. The cooldown must be a positive integer representing server ticks. | Yes |- | [[API/functions/set_peffect|set_peffect]]() | boolean | player, potionEffect, [strength], [seconds], [ambient], [particles], [icon] | {{object|PlayerOfflineException}}
{{object|CastException}}
{{object|RangeException}} | Adds one, or modifies an existing, potion effect on a mob. The potionEffect can be SLOWNESS, INVISIBILITY, SLOW_FALLING, BAD_OMEN, WEAKNESS, DOLPHINS_GRACE, INSTANT_DAMAGE, MINING_FATIGUE, TRIAL_OMEN, SPEED, WITHER, LUCK, FIRE_RESISTANCE, WIND_CHARGED, WATER_BREATHING, GLOWING, OOZING, ABSORPTION, HUNGER, BAD_LUCK, HERO_OF_THE_VILLAGE, REGENERATION, INFESTED, WEAVING, STRENGTH, BLINDNESS, LEVITATION, CONDUIT_POWER, RAID_OMEN, JUMP_BOOST, POISON, NAUSEA, RESISTANCE, HEALTH_BOOST, DARKNESS, NIGHT_VISION, INSTANT_HEALTH, HASTE, or SATURATION. It also accepts an integer corresponding to the effect id listed on the Minecraft wiki. Strength is an integer representing the power level of the effect, starting at 0. Seconds defaults to 30.0. To remove an effect, set the seconds to 0. If seconds is greater than 107374182 a RangeException is thrown. Negative seconds makes the effect infinite. (or max in versions prior to 1.19.4) Ambient takes a boolean of whether the particles should be more transparent. Particles takes a boolean of whether the particles should be visible at all. Icon argument takes a boolean of whether the effect icon should be displayed. The function returns whether or not the effect was modified.
([[API/functions/set_peffect#Examples|Examples...]]) | Yes |- | [[API/functions/set_pexp|set_pexp]]() | void | [player], xp | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|RangeException}} | Sets the experience of a player within the current level, as a percentage, from 0 to 99. 100 resets the experience to zero and adds a level to the player. | Yes |- | [[API/functions/set_pflight|set_pflight]]() | void | [player], flight | {{object|PlayerOfflineException}} | Sets whether or not this player is allowed to fly. | Yes |- | [[API/functions/set_pflying|set_pflying]]() | void | [player], flying | {{object|PlayerOfflineException}}
{{object|IllegalArgumentException}} | Sets the flying state for the player.Requires player to have the ability to fly, which is set with set_pflight(). | Yes |- | [[API/functions/set_pflyspeed|set_pflyspeed]]() | void | [player], speed | {{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|CastException}} | Sets a player's fly speed. The speed must be between -1.0 and 1.0. The default player fly speed is 0.1. | Yes |- | [[API/functions/set_pfood|set_pfood]]() | void | [player], level | {{object|PlayerOfflineException}}
{{object|CastException}} | Sets the player's food level. This is an integer from 0-? | Yes |- | [[API/functions/set_phealth|set_phealth]]() | void | [player], health | {{object|CastException}}
{{object|RangeException}}
{{object|PlayerOfflineException}} | Sets the player's health. Health should be a double between 0 and their max health, which is 20.0 by default. | Yes |- | [[API/functions/set_phunger|set_phunger]]() | void | [player], hunger | {{object|RangeException}}
{{object|PlayerOfflineException}}
{{object|CastException}} | Sets a player's hunger level, where 0 is empty and 20 is full. | Yes |- | [[API/functions/set_plevel|set_plevel]]() | void | [player], level | {{object|CastException}}
{{object|PlayerOfflineException}} | Sets the level of a player. | Yes |- | [[API/functions/set_plist_footer|set_plist_footer]]() | void | [player], footer | {{object|LengthException}}
{{object|PlayerOfflineException}} | Sets the player list footer for a player. This is the text that appears below the player list that appears when hitting the tab key. Colors and new lines are accepted. Only the given player (or current player if none is given) will see these changes. | Yes |- | [[API/functions/set_plist_header|set_plist_header]]() | void | [player], header | {{object|LengthException}}
{{object|PlayerOfflineException}} | Sets the player list header for a player. This is the text that appears above the player list that appears when hitting the tab key. Colors and new lines are accepted. Only the given player (or current player if none is given) will see these changes. | Yes |- | [[API/functions/set_ploc|set_ploc]]() | boolean | [player], locationArray
[player], x, y, z | {{object|CastException}}
{{object|LengthException}}
{{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Sets the location of the player to the specified coordinates. If the coordinates are not valid, or the player was otherwise prevented from teleporting, false is returned, otherwise true. If player is omitted, the current player is used. Note that 1 is automatically added to the y coordinate. | Yes |- | [[API/functions/set_pmode|set_pmode]]() | void | [player], mode | {{object|PlayerOfflineException}}
{{object|FormatException}} | Sets the player's game mode. Mode must be one of: SURVIVAL, CREATIVE, ADVENTURE, or SPECTATOR | Yes |- | [[API/functions/set_ponfire|set_ponfire]]() | void | [player], ticks | {{object|PlayerOfflineException}}
{{object|CastException}} | Sets the player on fire for the specified number of ticks. If a boolean is given for ticks, false is 0, and true is 20. | Yes |- | [[API/functions/set_psaturation|set_psaturation]]() | void | [player], saturation | {{object|RangeException}}
{{object|PlayerOfflineException}}
{{object|CastException}} | Set's the player's food saturation level. If this is above 0.0 and the player's health is below max, the player will experience fast health regeneration. | Yes |- | [[API/functions/set_pspectator_target|set_pspectator_target]]() | void | [player], entity | {{object|PlayerOfflineException}}
{{object|IllegalArgumentException}}
{{object|BadEntityException}} | Sets the entity for the player to spectate. If set to null, the spectator will stop following an entity. If the player is not in spectator mode an IllegalArgumentException is thrown. | Yes |- | [[API/functions/set_pstatistic|set_pstatistic]]() | void | [player], statistic, [type], amount | {{object|RangeException}}
{{object|PlayerOfflineException}}
{{object|CastException}}
{{object|IllegalArgumentException}} | Sets the specified statistic for the player. Some statistics require a block, item or entity type. An IllegalArgumentException will be thrown if the statistic is invalid, or if the type is invalid for that statistic. The player argument is required before the type argument is. [[API/functions/set_pstatistic|See more...]]
| Yes |- | [[API/functions/set_pstorm|set_pstorm]]() | void | [player], downFall | {{object|PlayerOfflineException}} | Sets the weather for the given player only. If downFall is true, the player will experience a storm. If downFall is null, it will reset the player's visible weather to that which the player's world is experiencing. | Yes |- | [[API/functions/set_ptexp|set_ptexp]]() | void | [player], exp | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|RangeException}} | Sets the total experience of a player. | Yes |- | [[API/functions/set_ptime|set_ptime]]() | void | [player], time, [relative] | {{object|PlayerOfflineException}}
{{object|FormatException}} | Sets the time of a given player. Relative defaults to false, but if true, the time will be an offset and the player's time will still progress. Otherwise it will be locked and should be a number from 0 to 24000, else it is modulo scaled. Alternatively, common time notation (9:30pm, 4:00 am) is acceptable, and convenient english mappings also exist:<ul><li>afternoon = 8000</li><li>dawn = 22500</li><li>day = 2000</li><li>dusk = 13500</li><li>earlymorning = 20000</li><li>evening = 12000</li><li>midday = 6000</li><li>midnight = 18000</li><li>morning = 0</li><li>night = 14000</li><li>noon = 6000</li><li>sunrise = 23000</li><li>sunset = 13000</li></ul> | Yes |- | [[API/functions/set_pvelocity|set_pvelocity]]() | boolean | [player], vector
[player], x, y, z | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|FormatException}}
{{object|IllegalArgumentException}} | Sets a player's velocity. vector must be an associative array with x, y, and z keys defined (if magnitude is set, it is ignored). If the vector's magnitude is greater than 10, the command is cancelled, because the server won't allow the player to move faster than that. A warning is issued, and false is returned if this happens, otherwise, true is returned. | Yes |- | [[API/functions/set_pwalkspeed|set_pwalkspeed]]() | void | [player], speed | {{object|PlayerOfflineException}}
{{object|RangeException}}
{{object|CastException}} | Sets a player's walk speed. The speed must be between -1.0 and 1.0. The default player walk speed is 0.2. | Yes |- | [[API/functions/set_pwhitelisted|set_pwhitelisted]]() | void | player, isWhitelisted | {{object|NotFoundException}} | Sets the whitelist flag of the specified player. This will work with offline players, but the name must be exact. [[API/functions/set_pwhitelisted|See more...]]
| Yes |- | [[API/functions/stop_named_sound|stop_named_sound]]() | void | player, sound, [category] | {{object|InvalidWorldException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Stops the specified sound for the given player. | Yes |- | [[API/functions/stop_sound|stop_sound]]() | void | player, sound, [category] | {{object|InvalidWorldException}}
{{object|LengthException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Stops the specified sound for a player. | Yes |- | [[API/functions/stop_sound_category|stop_sound_category]]() | void | player, category | {{object|LengthException}}
{{object|FormatException}}
{{object|PlayerOfflineException}} | Stops all sounds in a category for a player. (MC 1.19+) | Yes |} == PluginMeta ==
This class contains the functions use to communicate with other plugins and the server in general.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/fake_incoming_plugin_message|fake_incoming_plugin_message]]()
| void
| [player,] channel, message
| {{object|CastException}}{{object|PlayerOfflineException}}
{{object|IllegalArgumentException}} | Fakes an incoming plugin message from the player. Channel should be a string (the channel name) and message should be a byte_array primitive. Depending on the plugin, these parameters will vary. If message is null an empty byte_array is sent. | Yes |- | [[API/functions/get_registered_channels|get_registered_channels]]() | array | | {{object|NotFoundException}}
{{object|IllegalArgumentException}} | Returns an array of strings containing the channels CommandHelper is listening on. | Yes |- | [[API/functions/is_channel_registered|is_channel_registered]]() | boolean | channel | {{object|NotFoundException}}
{{object|IllegalArgumentException}} | Returns true if commandhelper is listening to the given plugin channel. | Yes |- | [[API/functions/register_channel|register_channel]]() | void | channel | {{object|PluginChannelException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}} | Registers a plugin channel for CommandHelper to listen on. Channel name should be a string that is all lower-case, no longer than 32 characters, and contain a colon, or it will throw an IllegalArgumentException. Incoming messages can be inspected by binding to 'plugin_message_received'. | Yes |- | [[API/functions/send_plugin_message|send_plugin_message]]() | void | [player,] channel, message | {{object|CastException}}
{{object|PlayerOfflineException}}
{{object|IllegalArgumentException}} | Sends a plugin message to the player. Channel name should be a string that is all lower-case, no longer than 32 characters, and contain a colon, or it will throw an IllegalArgumentException. The message should be a byte_array primitive. Depending on the plugin, these parameters will vary. If message is null an empty byte_array is sent. | Yes |- | [[API/functions/unregister_channel|unregister_channel]]() | void | channel | {{object|PluginChannelException}}
{{object|NotFoundException}}
{{object|IllegalArgumentException}} | Unregisters a plugin channel CommandHelper is listening on, if any. | Yes |} == Recipes ==
This class of functions allows recipes to be managed.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/add_recipe|add_recipe]]()
| boolean
| recipeArray
| {{object|CastException}}{{object|FormatException}}
{{object|IllegalArgumentException}} | Adds a recipe to the server and returns whether it was added or not. [[API/functions/add_recipe|See more...]]
([[API/functions/add_recipe#Examples|Examples...]]) | Yes |- | [[API/functions/clear_recipes|clear_recipes]]() | void | | | Clears all recipes. | Yes |- | [[API/functions/get_all_recipes|get_all_recipes]]() | array | | | Gets all recipes on the server. | Yes |- | [[API/functions/get_recipes_for|get_recipes_for]]() | array | itemArray | {{object|FormatException}}
{{object|CastException}} | Gets all recipes that have a result of the given item. NOTE: Gets all recipes for result item regardless of meta and enchants, although the array has correct data. | Yes |- | [[API/functions/remove_recipe|remove_recipe]]() | boolean | recipe_key | | Remove a certain recipe by its registered key. Returns whether the recipe was removed successfully or not. | Yes |- | [[API/functions/reset_recipes|reset_recipes]]() | void | | | Resets all recipes to the default recipes. | Yes |} == Reflection ==
This class of functions allows scripts to hook deep into the interpreter itself, and get meta information about the operations of a script. This is useful for debugging, testing, and ultra dynamic scripting. See the [[Reflection|guide to reflection]] on the wiki for more details. In order to make the most of these functions, you should familiarize yourself with the general workings of the language. These functions explore extremely advanced concepts, and should normally not be used; especially if you are not familiar with the language.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/class_type|class_type]]()
| ClassType
| string name
| {{object|CastException}}{{object|NotFoundException}} | Returns a ClassType object for the given fully qualified class name. If the given class doesn't exist, a NotFoundException is thrown. | Yes |- | [[API/functions/get_aliases|get_aliases]]() | array | | | Returns an array of the defined alias signatures (The part left of the = sign). | Yes |- | [[API/functions/get_classes|get_classes]]() | array | | | Returns a list of all known classes. This may not be completely exhaustive, but will at least contain all system defined classes. The returned value is an array of ClassType objects. | Yes |- | [[API/functions/get_events|get_events]]() | array | | | Returns an array of all registered event names. | Yes |- | [[API/functions/get_functions|get_functions]]() | array | | | Returns an associative array of all loaded functions. The keys of this array are the names of the classes containing the functions (which you know as the sections of the API page), and the values are arrays of the names of the functions within those classes. | Yes |- | [[API/functions/get_procedures|get_procedures]]() | array | | | Returns an array of procedures callable in the current scope.
([[API/functions/get_procedures#Examples|Examples...]]) | Yes |- | [[API/functions/reflect_docs|reflect_docs]]() | string |
element, docField | {{object|FormatException}} | Returns the documentation for an element. There are 4 things that an element might have, and one of these should be passed as the docField argument: type, return, args, description. A valid element is either the name of an ivariable, or a function/proc. For instance, reflect_docs('reflect_docs', 'description') would return what you are reading right now. User defined variables and procs may not have any documentation, in which case null is returned. If the specified argument cannot be found, a FormatException is thrown. If no arguments are passed in, it returns the documentation for reflect_docs, that is, what you're reading right now.
([[API/functions/reflect_docs#Examples|Examples...]]) | Yes |- | [[API/functions/reflect_pull|reflect_pull]]() | mixed | param, [args, ...] | {{object|FormatException}}
{{object|IOException}} | Returns information about the runtime in a usable format. Depending on the information returned, it may be usable directly, or it may be more of a referential format. [[API/functions/reflect_pull|See more...]]
| Yes |- | [[API/functions/reflect_type|reflect_type]]() | array | type | {{object|CastException}} | Returns information about the given ClassType. [[API/functions/reflect_type|See more...]]
([[API/functions/reflect_type#Examples|Examples...]]) | Yes |- | [[API/functions/reflect_value_source|reflect_value_source]]() | string | persistenceKey | | Returns the source file that this key will store a value to in the Persistence Network. For instance, in your persistence.ini file, if you have the entry "storage.test.**=json:///path/to/file.json", then reflect_value_source('storage.test.testing') would return 'json:///path/to/file.json'. This is useful for debugging, as it will definitively trace back the source/destination of a value. Note that unlike get and store_value, the "storage" prefix is required, if you're searching for values that are stored using these functions. | Yes |} == Regex ==
This class provides regular expression functions. For more details, please see the page on [[Regex|regular expressions]]. Note that all the functions are just passthroughs to the Java regex mechanism. If you need to set a flag on the regex, where the api calls for a pattern, instead send array('pattern', 'flags') where flags is any of i, m, or s. Alternatively, using the embedded flag system that Java provides is also valid.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/reg_count|reg_count]]()
| int
| pattern, subject
| {{object|FormatException}}
| Counts the number of occurrences in the subject.([[API/functions/reg_count#Examples|Examples...]]) | No |- | [[API/functions/reg_escape|reg_escape]]() | string | arg | | Escapes arg so that it may be used directly in a regular expression, without fear that it will have special meaning; that is, it escapes all special characters. Use this if you need to use user input or similar as a literal search index.
([[API/functions/reg_escape#Examples|Examples...]]) | No |- | [[API/functions/reg_match|reg_match]]() | array | pattern, subject | {{object|FormatException}} | Searches for the given pattern, and returns an array with the results. Captures are supported. If the pattern is not found anywhere in the subject, an empty array is returned. The indexes of the array follow typical regex fashion; the 0th element is the whole match, and 1-n are the captures specified in the regex.
([[API/functions/reg_match#Examples|Examples...]]) | No |- | [[API/functions/reg_match_all|reg_match_all]]() | array | pattern, subject | {{object|FormatException}} | Searches subject for all matches to the regular expression given in pattern, unlike reg_match, which just returns the first match.
([[API/functions/reg_match_all#Examples|Examples...]]) | No |- | [[API/functions/reg_replace|reg_replace]]() | string | pattern, replacement, subject | {{object|FormatException}}
{{object|CastException}} | Replaces any occurrences of pattern with the replacement in subject. Back references are allowed. 'replacement' can be a string, or a closure that accepts a found occurrence of 'pattern' and returns the replacement string value.
([[API/functions/reg_replace#Examples|Examples...]]) | No |- | [[API/functions/reg_split|reg_split]]() | array | pattern, subject, [limit] | {{object|FormatException}}
{{object|CastException}} | Splits a string on the given regex, and returns an array of the parts. If nothing matched, an array with one element, namely the original subject, is returned. Limit defaults to infinity, but if set, only that number of splits will occur.
([[API/functions/reg_split#Examples|Examples...]]) | No |} == ResourceManager ==
This class contains functions for resource management. This entire class of functions WILL be deprecated at some point in the future, so don't rely too heavily on it.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/res_create_resource|res_create_resource]]()
| Resource
| type, [data]
| {{object|CastException}}{{object|FormatException}} | Creates a new resource, which is stored in memory. Various functions require resources of certain types, which are created with this function. Barring resources that you intend on keeping around indefinitely, each call to res_create_resource should be paired with a res_free_resource, being careful to catch any exceptions and still calling res_free_resource anyways. Each resource has its own data to create the resource. Type may be one of: XML_DOCUMENT, STRING_BUILDER, or RANDOM It's worth noting that this function (and any function that relies on it) is a stopgap measure, and will eventually be deprecated and removed. For certain types of operations, it's completely unwieldy to implement them in a procedural manner, so this is a temporary alternative to proper object support. | Yes |- | [[API/functions/res_free_resource|res_free_resource]]() | void | Resource | {{object|CastException}}
{{object|NotFoundException}} | Frees the given resource. This should ALWAYS be called at some point after creating a resource with res_create_resource, once you are done with the resource. | Yes |} == SQL ==
This class of functions provides methods for accessing various SQL servers.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/query|query]]()
| mixed
| profile, query, [parameters...]
| {{object|SQLException}}
| Executes an SQL query, and returns various data depending on the query type.
See the extended information for more details. [[API/functions/query|See more...]]| Yes |- | [[API/functions/query_async|query_async]]() | void | profile, query, [params...], callback | {{object|CastException}} | Asynchronously makes a query to an SQL server. The profile, query, and params arguments work the same as {{function|query}}, so see the documentation of that function for details about those parameters. The callback should have the following signature: closure(@contents, @exception){ <code> }. @contents will contain the return value that query would normally return. If @exception is not null, then an exception occurred during the query, and that exception will be passed in. If @exception is null, then no error occurred, though @contents may still be null if query() would otherwise have returned null. | Yes |- | [[API/functions/unsafe_query|unsafe_query]]() | mixed | profile, query, [parameters...] | {{object|SQLException}} | Executes a query, just like the {{function|query}} function, however, no validation is done to ensure that SQL injections might occur (essentially allowing for concatenation directly in the query). Otherwise, functions exactly the same as query(). | Yes |} == Sandbox ==
This class is for functions that are experimental. They don't actually get added to the documentation, and are subject to removal at any point in time, nor are they likely to have good documentation.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/raw_pcan_see|raw_pcan_see]]()
| boolean
| [player], other
| {{object|PlayerOfflineException}}
| Returns a boolean stating if the other player can see this player or not. This is the raw access function, you probably shouldn't use this, as the CommandHelper vanish api functions will probably be easier to use.
| Yes
|-
| [[API/functions/raw_set_pvanish|raw_set_pvanish]]()
| void
| [player], isVanished, otherPlayer
| {{object|PlayerOfflineException}}
| Sets the visibility of the current player (or the one specified) to visible or invisible (based on the value of isVanished) from the view of the otherPlayer. This is the raw access function, you probably shouldn't use this, as the CommandHelper vanish api functions will probably be easier to use.
| Yes
|-
| [[API/functions/srand|srand]]()
| double
| Resource
| {{object|CastException}}
| Returns a new rand value using the provided a RANDOM Resource. If the seed used to create the resource is the same, each resulting series of numbers will be the same.
| No
|-
| [[API/functions/super_cancel|super_cancel]]()
| void
|
| {{object|BindException}}
| "Super Cancels" an event. This only will work if play-dirty is set to true. If an event is super cancelled, not only is the cancelled flag set to true, the event stops propagating down, so no other plugins (as in other server plugins, not just CH scripts) will receive the event at all (other than monitor level plugins). This is useful for overriding event handlers for plugins that don't respect the cancelled flag. This function hooks into the play-dirty framework that injects custom event handlers into bukkit.
| Yes
|-
| [[API/functions/test_composite_function|test_composite_function]]()
| boolean
| a, b
| {{object|CastException}}
| This is a test function, which demonstrates to extension authors how to make a composite function. It returns true if a and b added together are greater than 0, false otherwise.
| No
|-
| [[API/functions/x_recompile_includes|x_recompile_includes]]()
| int
| path
| {{object|IOException}}{{object|IncludeException}} | Recompiles specified files already compiled with include(). If there's no compile errors, scripts that then include() these files will use the updated code. Note that this bypasses Static Analysis, even if you have it enabled. The path can be a directory or file. It is executed recursively through all subdirectories. If there's a compile error in any of the files, the function will throw an exception and other scripts will continue to use the previous version of the code when included. Returns number of files recompiled. | Yes |- | [[API/functions/x_write|x_write]]() | void | path, content, [mode] | {{object|SecurityException}}
{{object|IOException}} | Writes a file to the file system. This method only works from the cmdline, if not in cmdline, a SecurityException is thrown. Because of this, there is no check against the base-dir path. [[API/functions/x_write|See more...]]
| Yes |} == Scheduling ==
This class contains methods for dealing with time and server scheduling.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/clear_cron|clear_cron]]()
| void
| [cronID]
| {{object|RangeException}}{{object|CastException}} | Clears the previously registered cron job from the registered list. This will prevent the task from running again in the future. If run from within a cron task, the id is optional, and the current task will be prevented from running again in the future. If the ID provided is invalid, a RangeException is thrown. | Yes |- | [[API/functions/clear_task|clear_task]]() | void | [id] | {{object|CastException}}
{{object|InsufficientArgumentsException}}
{{object|NullPointerException}} | Stops the interval or timeout that is specified. The id can be gotten by storing the integer returned from either set_timeout or set_interval. An invalid id is simply ignored. The clear_task function is more useful for set_timeout, where you may queue up some task to happen in the far future, yet have some trigger to prevent it from happening. ID is optional, but only if called from within a set_interval or set_timeout closure, in which case it defaults to the id of that particular task.
([[API/functions/clear_task#Examples|Examples...]]) | Yes |- | [[API/functions/get_system_timezones|get_system_timezones]]() | array<string> | | | Returns a list of time zones registered on this system. | Yes |- | [[API/functions/nano_time|nano_time]]() | int | | | Returns an arbitrary number based on the most accurate clock available on this system. Only useful when compared to other calls to nano_time(). The return is in nano seconds. See the Java API on System.nanoTime() for more information on the usage of this function. | No |- | [[API/functions/parse_date|parse_date]]() | int | dateFormat, dateString, [locale] | {{object|FormatException}} | Parses a date string, and returns an integer timestamp representing that time. This essentially works in reverse of {{function|simple_date}}. The dateFormat string is the same as simple_date, see the documentation for that function to see full details on that. The dateString is the actual date to be parsed. The dateFormat should be the equivalent format that was used to generate the dateString. In general, this function is fairly lenient, and will still try to parse a dateString that doesn't necessarily conform to the given format, but it shouldn't be relied on to work with malformed data. Various portions of the date may be left off, in which case the missing portions will be assumed, for instance, if the time is left off completely, it is assumed to be midnight, and if the minutes are left off, it is assumed to be on the hour, if the date is left off, it is assumed to be today, etc.
([[API/functions/parse_date#Examples|Examples...]]) | No |- | [[API/functions/set_cron|set_cron]]() | int | cronFormat, closure | {{object|CastException}}
{{object|FormatException}} | Sets a task to occur at a regular interval, given a cron style interval. This allows for an easier way to specify that a task should happen, for instance, every hour on the hour. Unlike set_interval, this uses absolute wall clock time, not relative times. The task id is returned, so it can be cleared later with clear_cron if needed. If clear_cron is run from within the task itself, the id is optional. See more information for a detailed description of cron format. [[API/functions/set_cron|See more...]]
| Yes |- | [[API/functions/set_interval|set_interval]]() | int | int timeInMS, [int initialDelayInMS,] Callable task | {{object|CastException}}
{{object|RangeException}} | Sets a task to run every so often. This works similarly to set_timeout, except the task will automatically re-register itself to run again. Note that the resolution of the time is in ms, however, the server will only have a resolution of up to 50 ms, meaning that a time of 1-50ms is essentially the same as 50ms. The initial delay defaults to the same thing as timeInMS, that is, there will be a pause between registration and initial firing. However, this can be set to 0 (or some other number) to adjust how long of a delay there is before it begins.
([[API/functions/set_interval#Examples|Examples...]]) | Yes |- | [[API/functions/set_timeout|set_timeout]]() | int | timeInMS, closure | {{object|CastException}}
{{object|RangeException}} | Sets a task to run in the specified number of ms in the future. The task will only run once. Note that the resolution of the time is in ms, however, the server will only have a resolution of up to 50 ms, meaning that a time of 1-50ms is essentially the same as 50ms.
([[API/functions/set_timeout#Examples|Examples...]]) | Yes |- | [[API/functions/simple_date|simple_date]]() | mixed | format, [time, [timezone, [locale]]] | {{object|CastException}}
{{object|FormatException}} | Returns a date of the current time (or the time specified) in the format you give. [[API/functions/simple_date|See more...]]
([[API/functions/simple_date#Examples|Examples...]]) | No |- class="hiddenFunction" | [[API/functions/sleep|sleep]]() | void | seconds | {{object|CastException}}
{{object|InterruptedException}} | Sleeps the script for the specified number of seconds, up to the maximum time limit defined in the preferences file. Seconds may be a double value, so 0.5 would be half a second. If the "interrupt status" is true then throw InterruptedException PLEASE NOTE: Sleep times are NOT very accurate, and should not be relied on for preciseness. | Yes |- | [[API/functions/time|time]]() | int | | | Returns the current unix time stamp, in milliseconds. The resolution of this is not guaranteed to be extremely accurate. If you need extreme accuracy, use nano_time() | No |} == Scoreboards ==
A class of functions for manipulating the server scoreboard.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/create_objective|create_objective]]()
| void
| name, [criteria, [scoreboard]]
| {{object|ScoreboardException}}
| Adds a new objective to the scoreboard, throwing a CREScoreboardException if the name is already in use or is too long. The vanilla criteria names are DEATHCOUNT, HEALTH, PLAYERKILLCOUNT, TOTALKILLCOUNT, and DUMMY. You can put anything, but if none of the other values match, 'dummy' will be used. Those values which are not 'dummy' are server-managed.Scoreboard defaults to 'main' if not given.
| Yes
|-
| [[API/functions/create_scoreboard|create_scoreboard]]()
| void
| name
| {{object|NullPointerException}}{{object|ScoreboardException}} | Creates a new scoreboard identified by the given name, and stores it internally for later use. Throws a ScoreboardException if the name is already in use. | Yes |- | [[API/functions/create_team|create_team]]() | void | name, [scoreboard] | {{object|ScoreboardException}} | Adds a new team to the scoreboard. Throws a ScoreboardException if that team name already exists or is too long.Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/get_objectives|get_objectives]]() | array | [scoreboard], [criteria] | {{object|ScoreboardException}} | Returns an array of arrays about the objectives on the given scoreboard, which defaults to 'main' if not given. If criteria is given, only objectives with that criteria will be returned. The arrays contain the keys name, displayname, slot, modifiable, and criteria. | Yes |- | [[API/functions/get_pscore|get_pscore]]() | int | objectiveName, name, [scoreboard] | {{object|LengthException}}
{{object|ScoreboardException}} | Returns the player's score for the given objective. A LengthException is thrown if the name is too long.Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/get_pscoreboard|get_pscoreboard]]() | string | player | {{object|PlayerOfflineException}}
{{object|ScoreboardException}} | Returns the id of the scoreboard a player is assigned to. If it is not already cached, it will be added using the player's name. Using this method, it should be possible to import scoreboards created by other plugins. | Yes |- | [[API/functions/get_pteam|get_pteam]]() | array | player, [scoreboard] | {{object|ScoreboardException}} | Returns a team array for this player, or null if not in a team. Contains the keys name, displayname, color, prefix, suffix, size, options, and players.Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/get_scoreboard_entries|get_scoreboard_entries]]() | array | [scoreboardName] | {{object|ScoreboardException}} | Gets a list of all the entries in the given scoreboard. | Yes |- | [[API/functions/get_scoreboards|get_scoreboards]]() | array | | | Returns an array of the registered scoreboard ID's. The special scoreboard 'main' represents the server's main scoreboard which can be managed by the vanilla /scoreboard command. | Yes |- | [[API/functions/get_teams|get_teams]]() | array | [scoreboard] | {{object|ScoreboardException}} | Returns an array of arrays about the teams on the given scoreboard, which defaults to 'main' if not given. The array keys are the team names, and each value is a team array containing the keys: name, displayname, prefix, suffix, size, color, options, and players. | Yes |- | [[API/functions/remove_objective|remove_objective]]() | void | objectivename, [scoreboard] | {{object|ScoreboardException}} | Unregisters an objective from the scoreboard. Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/remove_scoreboard|remove_scoreboard]]() | void | scoreboard, [nullify] | {{object|ScoreboardException}} | Stops tracking the given scoreboard, unless it is 'main', because that never goes away. If nullify is true (defaults to true), all scores, teams, and objectives will be cleared, and all tracked players currently online will be switched to the main scoreboard, essentially removing all references to the board so it can be garbage-collected. | Yes |- | [[API/functions/remove_team|remove_team]]() | void | teamname, [scoreboard] | {{object|ScoreboardException}} | Unregisters a team from the scoreboard. Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/reset_all_pscores|reset_all_pscores]]() | void | player, [scoreboard] | {{object|ScoreboardException}} | Resets all scores for a player tracked by the given scoreboard. This means they will not be show up on any displays. Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/set_objective_display|set_objective_display]]() | void | objectiveName, array, [scoreboard]
objectiveName, displayname, [scoreboard] | {{object|FormatException}}
{{object|LengthException}}
{{object|ScoreboardException}} | Sets the display name and/or slot of the given objective. If arg 2 is not an array, it is assumed to be the displayname, otherwise arg 2 should be an array with keys 'displayname' and/or 'slot', affecting their respective properties. A null displayname resets it to the actual name, and a null slot removes it from all displays. Slot can be one of: BELOW_NAME, PLAYER_LIST, SIDEBAR, SIDEBAR_TEAM_BLACK, SIDEBAR_TEAM_DARK_BLUE, SIDEBAR_TEAM_DARK_GREEN, SIDEBAR_TEAM_DARK_AQUA, SIDEBAR_TEAM_DARK_RED, SIDEBAR_TEAM_DARK_PURPLE, SIDEBAR_TEAM_GOLD, SIDEBAR_TEAM_GRAY, SIDEBAR_TEAM_DARK_GRAY, SIDEBAR_TEAM_BLUE, SIDEBAR_TEAM_GREEN, SIDEBAR_TEAM_AQUA, SIDEBAR_TEAM_RED, SIDEBAR_TEAM_LIGHT_PURPLE, SIDEBAR_TEAM_YELLOW, or SIDEBAR_TEAM_WHITE [[API/functions/set_objective_display|See more...]]
| Yes |- | [[API/functions/set_pscore|set_pscore]]() | void | objectiveName, name, int, [scoreboard] | {{object|LengthException}}
{{object|ScoreboardException}} | Sets the player's score for the given objective. The name can be anything, not just player names. A LengthException is thrown if it's too long.Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/set_pscoreboard|set_pscoreboard]]() | void | player, [scoreboard] | {{object|PlayerOfflineException}}
{{object|ScoreboardException}} | Sets the scoreboard to be used by a player. The scoreboard argument is the id of a registered scoreboard. Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/set_team_display|set_team_display]]() | void | teamName, array, [scoreboard]
teamName, displayname, [scoreboard] | {{object|LengthException}}
{{object|ScoreboardException}}
{{object|IllegalArgumentException}} | Sets the display name, color, prefix, and/or suffix of the given team. If arg 2 is not an array, it is assumed to be the displayname, otherwise arg 2 should be an array with keys 'displayname', 'color', 'prefix', and/or 'suffix', affecting their respective properties. A null displayname resets it to the actual name, and a null prefix or suffix removes it from all displays. Color can be one of BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE, RANDOM, BOLD, STRIKETHROUGH, UNDERLINE, ITALIC or PLAIN_WHITE. [[API/functions/set_team_display|See more...]]
| Yes |- | [[API/functions/set_team_options|set_team_options]]() | void | teamName, array, [scoreboard] | {{object|ScoreboardException}}
{{object|FormatException}} | Sets various options about the team from an array. The keys 'friendlyfire' and 'friendlyinvisibles' must be booleans. The keys 'collisionrule', 'nametagvisibility', and 'deathmessagevisibility' must be one of ALWAYS, FOR_OTHER_TEAMS, FOR_OWN_TEAM, or NEVER.Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/team_add_player|team_add_player]]() | void | teamName, player, [scoreboard] | {{object|ScoreboardException}} | Adds a player to a team, given the team exists. The player will be removed from any other team on the same scoreboard. Scoreboard defaults to 'main' if not given. | Yes |- | [[API/functions/team_remove_player|team_remove_player]]() | boolean | teamname, player, [scoreboard] | {{object|ScoreboardException}} | Attempts to remove a player from a team, and returns true if successful, for false if the player was not part of the team.Scoreboard defaults to 'main' if not given. | Yes |} == Statistics ==
Provides a set of functions that deal with statistical analysis of numbers.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/average|average]]()
| number
| arraynumber input... | {{object|CastException}}
{{object|IndexOverflowException}} | Returns the average (also known as the arithmetic mean) across all the numbers in the set. The input may be an array of numbers, or individual numbers as arguments. The average of a set of numbers is the result of adding all the numbers in the set, and dividing it by the number of values in the set. If an empty array is provided, a IndexOverflowException is thrown.
([[API/functions/average#Examples|Examples...]]) | No |- | [[API/functions/median|median]]() | number | array
number input... | {{object|CastException}}
{{object|IndexOverflowException}} | Returns the median across all the numbers in the set. The input may be an array of numbers, or individual numbers as arguments. The median is the number that is in the center of set, once the values in the set are ordered from least to greatest. That is, in the set [1, 2, 3], 2 is the median. If there is an even number of value in the set, the middle two values are averaged, and that value is returned. If an empty array is provided, a IndexOverflowException is thrown.
([[API/functions/median#Examples|Examples...]]) | No |- | [[API/functions/mode|mode]]() | array
number input... | {{object|CastException}}
{{object|IndexOverflowException}} | Returns the mode across all the numbers in the set. The input may be an array of numbers, or individual numbers as arguments. The mode of a set of numbers is the values that occur most in the set. This function supports bimodal (and generally n-modal sets), as well as fully unique sets, by returning an array. If the set is fully unique, i.e. [1, 2, 3], then the original set will be returned all values occur once). If there are more than one modes, i.e. [1, 1, 2, 3, 3], then an array of both 1 and 3 will be returned. The values will not necessarily be returned in any particular order. If an empty array is provided, a IndexOverflowException is thrown.
([[API/functions/mode#Examples|Examples...]]) | No |- | [[API/functions/percentile|percentile]]() | number | number percentile, array
number percentile, number input... | {{object|CastException}}
{{object|IndexOverflowException}}
{{object|RangeException}} | Returns the nth-percentile across all the numbers in the set. The input may be an array of numbers, or individual numbers as arguments. A percentile is a measure indicating the value below which a given percentage of observations in a group of observations falls. For example, the 20th percentile is the value (or score) below which 20% of the observations may be found. If an empty array is provided, a IndexOverflowException is thrown. If the percentile is not within the range of 0 or 1, a RangeException is thrown.
([[API/functions/percentile#Examples|Examples...]]) | No |- | [[API/functions/sum|sum]]() | number | array
number input... | {{object|CastException}}
{{object|IndexOverflowException}} | Returns the sum across all the numbers in the set. The input may be an array of numbers, or individual numbers as arguments. The sum is the result of adding all the numbers in the set together. If an empty array is provided, a IndexOverflowException is thrown.
([[API/functions/sum#Examples|Examples...]]) | No |} == StringHandling ==
These class provides functions that allow strings to be manipulated
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/char_from_unicode|char_from_unicode]]()
| string
| unicode
| {{object|CastException}}{{object|RangeException}} | Returns the unicode character for a given unicode value. This is meant for dynamic input that needs converting to a unicode character, if you're hardcoding it, you should just use '\u1234' syntax instead, however, this is the dynamic equivalent of the \u string escape, so '\u1234' == char_from_unicode(parse_int('1234', 16)) == char_from_unicode(0x1234). Despite the name, certain unicode escapes may return multiple characters, so there is no guarantee that length(char_from_unicode(@val)) will equal 1.
([[API/functions/char_from_unicode#Examples|Examples...]]) | No |- | [[API/functions/char_is_uppercase|char_is_uppercase]]() | boolean | char | {{object|FormatException}}
{{object|CastException}} | Determines if the character provided is uppercase or not. The string must be exactly 1 character long and a letter, otherwise a FormatException is thrown.
([[API/functions/char_is_uppercase#Examples|Examples...]]) | No |- | [[API/functions/concat|concat]]() | string | var1, [var2...] | | Concatenates any number of arguments together, and returns a string
([[API/functions/concat#Examples|Examples...]]) | No |- | [[API/functions/decrypt_secure_string|decrypt_secure_string]]() | array | string | {{object|CastException}} | Decrypts a secure_string into a char array. To keep backwards compatibility with strings in general, this function also accepts normal strings, which are not decrypted, but instead simply returned in the same format as if it were a secure_string. See the examples in {{function|secure_string}}.
([[API/functions/decrypt_secure_string#Examples|Examples...]]) | Yes |- | [[API/functions/length|length]]() | int | str
Sizeable | | Returns the character length of str, if the value is castable to a string, or the length of the ms.lang.Sizeable object, if an array or other Sizeable object is given.
([[API/functions/length#Examples|Examples...]]) | No |- | [[API/functions/levenshtein|levenshtein]]() | int | string1, string2 | | Returns the levenshtein distance of two character sequences. For instance, "123" and "133" would have a string distance of 1, while "123" and "123" would be 0, since they are the same string.
([[API/functions/levenshtein#Examples|Examples...]]) | No |- | [[API/functions/lsprintf|lsprintf]]() | string | locale, formatString, parameters...
locale, formatString, array(parameters...) | {{object|FormatException}}
{{object|InsufficientArgumentsException}}
{{object|CastException}} | Returns a string formatted to the given formatString specification, using the parameters passed in. Locale should be a string in format, for instance, en_US, nl_NL, no_NO... Which locales are available depends on your system. Use null to use the system's locale. The formatString should be formatted according to [http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax this standard], with the caveat that the parameter types are automatically cast to the appropriate type, if possible. Calendar/time specifiers, (t and T) expect an integer which represents unix time, but are otherwise valid. All format specifiers in the documentation are valid.
([[API/functions/lsprintf#Examples|Examples...]]) | No |- | [[API/functions/parse_args|parse_args]]() | array | string, [useAdvanced] | | Parses string into an array, where string is a space seperated list of arguments. Handy for turning $ into a usable array of items with which to script against. Extra spaces are ignored, so you would never get an empty string as an input. useAdvanced defaults to false, but if true, uses a basic argument parser that supports quotes for allowing arguments with spaces.
([[API/functions/parse_args#Examples|Examples...]]) | No |- | [[API/functions/replace|replace]]() | string | subject, search, replacement | | Replaces all instances of 'search' with 'replacement' in 'subject'
([[API/functions/replace#Examples|Examples...]]) | No |- | [[API/functions/sconcat|sconcat]]() | string | var1, [var2...] | | Concatenates any number of arguments together, but puts a space between elements
([[API/functions/sconcat#Examples|Examples...]]) | No |- | [[API/functions/secure_string|secure_string]]() | secure_string | charArray
string | {{object|FormatException}} | Constructs a secure_string from a given char array or string. [[API/functions/secure_string|See more...]]
([[API/functions/secure_string#Examples|Examples...]]) | No |- | [[API/functions/split|split]]() | array | split, string, [limit] | {{object|CastException}} | Splits a string into parts, using the split as the index. Though it can be used in every single case you would use reg_split, this does not use regex, and therefore can take a literal split expression instead of needing an escaped regex, and *may* perform better than the regex versions, as it uses an optimized tokenizer split, instead of Java regex. Limit defaults to infinity, but if set, only that number of splits will occur.
([[API/functions/split#Examples|Examples...]]) | No |- | [[API/functions/sprintf|sprintf]]() | string | formatString, parameters...
formatString, array(parameters...) | {{object|FormatException}}
{{object|InsufficientArgumentsException}}
{{object|CastException}} | Returns a string formatted to the given formatString specification, using the parameters passed in. The formatString should be formatted according to [http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax this standard], with the caveat that the parameter types are automatically cast to the appropriate type, if possible. Calendar/time specifiers, (t and T) expect an integer which represents unix time, but are otherwise valid. All format specifiers in the documentation are valid. This works the same as lsprintf with the locale set to "DEFAULT".
([[API/functions/sprintf#Examples|Examples...]]) | No |- | [[API/functions/string_append|string_append]]() | void | Resource, toAppend... | {{object|CastException}} | Appends any number of values to the underlying string builder. This is much more efficient than doing normal concatenation with a string when building a string in a loop. The underlying resource may be converted to a string via a cast, string(@res).
([[API/functions/string_append#Examples|Examples...]]) | Yes |- | [[API/functions/string_compare|string_compare]]() | int | string s1, string s2 | | Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. Returns 0 if s1 is equal to s2, a negative value if s1 is lexographically less than s2, and a positive value if s1 is lexigraphically greater than s2. The magnitude of non-zero return values is the difference between the char values at the first index at which a different char was found in both strings. If all chars match but the strings differ in length, then the magnitude is this difference.
([[API/functions/string_compare#Examples|Examples...]]) | No |- | [[API/functions/string_compare_ic|string_compare_ic]]() | int | string s1, string s2 | | Compares two strings lexicographically ignoring casing. The comparison is based on the Unicode value of each character in the strings. Returns 0 if s1 is equal to s2, a negative value if s1 is lexographically less than s2, and a positive value if s1 is lexigraphically greater than s2. The magnitude of non-zero return values is the difference between the char values at the first index at which a different char was found in both strings. If all chars match but the strings differ in length, then the magnitude is this difference.
([[API/functions/string_compare_ic#Examples|Examples...]]) | No |- | [[API/functions/string_contains|string_contains]]() | boolean | haystack, needle | {{object|NullPointerException}} | Returns true if the string needle is found anywhere within the string haystack. This is functionally equivalent to string_position(@haystack, @needle) != -1, but is generally clearer.
([[API/functions/string_contains#Examples|Examples...]]) | No |- | [[API/functions/string_contains_ic|string_contains_ic]]() | boolean | haystack, needle | {{object|NullPointerException}}
{{object|FormatException}} | Returns true if the string needle is found anywhere within the string haystack (while ignoring case). This is functionally equivalent to string_position(to_lower(@haystack), to_lower(@needle)) != -1, but is generally clearer. | No |- | [[API/functions/string_ends_with|string_ends_with]]() | boolean | teststring, keyword | {{object|NullPointerException}} | Determines if the provided teststring ends with the provided keyword. Note that this will cast both arguments to strings. This means that the boolean true will match the string 'true' or the integer 1 will match the string '1'. If an empty string is provided for the keyword, it will always return true.
([[API/functions/string_ends_with#Examples|Examples...]]) | No |- | [[API/functions/string_from_bytes|string_from_bytes]]() | string | byte_array, [encoding] | {{object|CastException}}
{{object|FormatException}} | Returns a new string, given the byte array encoding provided. The encoding defaults to UTF-8, but may be specified. A FormatException is thrown if the encoding type is invalid. | No |- | [[API/functions/string_get_bytes|string_get_bytes]]() | byte_array | string, [encoding] | {{object|CastException}}
{{object|FormatException}} | Returns this string as a byte_array, encoded using the specified encoding, or UTF-8 if no encoding is specified. Valid encodings are the encoding types that java supports. If the encoding is invalid, a FormatException is thrown. | No |- | [[API/functions/string_multiply|string_multiply]]() | string | string, times | {{object|RangeException}}
{{object|CastException}} | Multiplies a string the given number of times. For instance, string_multiply('a', 3) returns 'aaa'. If the string is empty, an empty string is returned. If the string is null, null is returned. If times is 0, an empty string is returned. All other string values are multiplied accordingly. Providing a value less than 0 for times results in a RangeException. When the maximum string size of 2147483647 characters would be exceeded, a RangeException is thrown.
([[API/functions/string_multiply#Examples|Examples...]]) | No |- | [[API/functions/string_position|string_position]]() | int | haystack, needle | {{object|NullPointerException}} | Finds the numeric position of the first occurrence of needle in haystack. haystack is the string to search in, and needle is the string to search with. Returns the position of the needle (starting with 0) or -1 if the string is not found at all.
([[API/functions/string_position#Examples|Examples...]]) | No |- | [[API/functions/string_starts_with|string_starts_with]]() | boolean | teststring, keyword | {{object|NullPointerException}} | Determines if the provided teststring starts with the provided keyword. This could be used to find the prefix of a line, for instance. Note that this will cast both arguments to strings. This means that the boolean true will match the string 'true' or the integer 1 will match the string '1'. If an empty string is provided for the keyword, it will always return true.
([[API/functions/string_starts_with#Examples|Examples...]]) | No |- | [[API/functions/substr|substr]]() | string | str, begin, [end] | {{object|RangeException}}
{{object|CastException}} | Returns a substring of the given string str, starting from index begin, to index end, or the end of the string, if no index is given. If either begin or end are out of bounds of the string, an exception is thrown. substr('hamburger', 4, 8) returns "urge", substr('smiles', 1, 5) returns "mile", and substr('lightning', 5) returns "ning". See also length().
([[API/functions/substr#Examples|Examples...]]) | No |- | [[API/functions/to_lower|to_lower]]() | string | str | {{object|FormatException}} | Returns an all lower case version of str
([[API/functions/to_lower#Examples|Examples...]]) | No |- | [[API/functions/to_upper|to_upper]]() | string | str | {{object|FormatException}} | Returns an all caps version of str
([[API/functions/to_upper#Examples|Examples...]]) | No |- | [[API/functions/trim|trim]]() | string | s | | Returns the string s with leading and trailing whitespace cut off
([[API/functions/trim#Examples|Examples...]]) | No |- | [[API/functions/triml|triml]]() | string | s | | Returns the string s with leading whitespace cut off
([[API/functions/triml#Examples|Examples...]]) | No |- | [[API/functions/trimr|trimr]]() | string | s | | Returns the string s with trailing whitespace cut off
([[API/functions/trimr#Examples|Examples...]]) | No |- | [[API/functions/unicode_from_char|unicode_from_char]]() | int | character | {{object|CastException}}
{{object|RangeException}} | Returns the unicode code point for a given character. The character is a string, but it should only be 1 code point character (which may be length(@character) == 2).
([[API/functions/unicode_from_char#Examples|Examples...]]) | No |- | [[API/functions/uuid|uuid]]() | string | type, arg | {{object|CastException}} | Returns a UUID (also known as a GUID). Different types of UUIDs can be generated, by default, if no parameters are provided, a random uuid is returned (version 4). For full details on what exactly a uuid is, and what the different versions are, see https://en.wikipedia.org/wiki/Universally_unique_identifier. The arg varies depending on the type, some types do not require an argument, in which case, this parameter will be ignored. <code>type</code> may be one of: - RANDOM - Returns a random UUID. This type takes 0 arguments. - NIL - Returns the nil UUID, that is 00000000-0000-0000-0000-000000000000. This type takes 0 arguments.
([[API/functions/uuid#Examples|Examples...]]) | No |} == TaskHandling ==
This class is used to manage various tasks throughout MethodScript. It is a task manager of sorts.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|- class="hiddenFunction"
| [[API/functions/tm_get_tasks|tm_get_tasks]]()
| array
|
|
| Returns an array of currently running tasks. [[API/functions/tm_get_tasks|See more...]]| Yes |- class="hiddenFunction" | [[API/functions/tm_kill_task|tm_kill_task]]() | void | taskType, id | {{object|CastException}} | Attempts to kill the specified task. The taskType and id will be listed with the task in the task manager. If the task is already finished, doesn't exist, or already in the process of finishing, nothing happens. | Yes |} == Threading ==
This experimental and private API is subject to removal, or incompatible changes, and should not be yet heavily relied on in normal development.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/synchronized|synchronized]]()
| void
| syncObject, code
| {{object|NullPointerException}}
| Synchronizes access to the code block for all calls (from different threads) with the same syncObject argument. This means that if two threads will call synchronized('example', <code>), the second call will hang the thread until the passed code of the first call has finished executing. If you call this function from within this function on the same thread using the same syncObject, the code will simply be executed. Note that this uses the same pool of lock objects as x_get_lock, except this is preferred to be used off the main thread, whereas x_get_lock is preferred on the main thread. Generally speaking, it is almost always incorrect to use this on the main thread, though there is no technical restriction to doing so. Other than strings, ValueTypes cannot be used as the lock object, and reference types such as an array or other object is required. For more information about synchronization, see: https://en.wikipedia.org/wiki/Synchronization_(computer_science)([[API/functions/synchronized#Examples|Examples...]]) | Yes |- | [[API/functions/x_clear_interrupt|x_clear_interrupt]]() | boolean | | | Clears the interrupt status of the current thread. If this call actually cleared the interrupt status, true is returned, if the thread was already not interrupted, false is returned. | Yes |- | [[API/functions/x_get_current_thread|x_get_current_thread]]() | string | | | Returns the thread id (thread name) of the currently running thread.
([[API/functions/x_get_current_thread#Examples|Examples...]]) | Yes |- | [[API/functions/x_get_lock|x_get_lock]]() | void | mixed lock, Callable action | {{object|NullPointerException}} | Runs the specified action once the lock is obtained. Note that this lock is the same underlying lock object as used in synchronized(). The action is run on the main thread (or a timer thread in cmdline). [[API/functions/x_get_lock|See more...]]
([[API/functions/x_get_lock#Examples|Examples...]]) | Yes |- | [[API/functions/x_interrupt|x_interrupt]]() | void | [string id] | | Interrupts the thread with the given id, or the current thread if no id is given. When a thread is interrupted, its interrupt status is set to true. This status can be checked using the x_is_interrupted and x_clear_interrupt function. Note that some blocking functions will throw an InterruptedException when the thread on which they are executed is interrupted. | Yes |- | [[API/functions/x_is_interrupted|x_is_interrupted]]() | boolean | [string id] | | Tests whether the thread with the given id (or the current thread if none is provided) is interrupted via x_interrupt. If the thread doesn't exist, or is not alive, false is returned. | Yes |- | [[API/functions/x_new_thread|x_new_thread]]() | void | id, closure | {{object|CastException}} | Creates a new thread, named id, and runs the closure on that thread. Note that many operations are not advisable to be run on other threads, and unless otherwise stated, functions are generally not thread safe. You can use x_run_on_main_thread_later() and x_run_on_main_thread_now() to ensure operations will be run correctly, however.
([[API/functions/x_new_thread#Examples|Examples...]]) | Yes |- | [[API/functions/x_run_on_main_thread_later|x_run_on_main_thread_later]]() | void | closure | | Runs the closure on the main thread later. If the function call is itself being run from the main thread, then the function still will not block, but it is not an error to call this from the main thread. If an exception is thrown from the closure, it is handled using the uncaught exception handler. | Yes |- | [[API/functions/x_run_on_main_thread_now|x_run_on_main_thread_now]]() | mixed | closure | | Runs the closure on the main thread now, blocking the current thread until it is finished. If the function call is itself being run from the main thread, then the function still will block as expected; it is not an error to call this from the main thread. Unlike running on the main thread later, if the underlying code throws an exception, it is thrown as a normal part of the execution. If the closure returns a value, it is returned by x_run_on_main_thread_now. | Yes |- | [[API/functions/x_thread_is_alive|x_thread_is_alive]]() | boolean | string id | | Tests if this thread with the given id is alive. A thread is alive if it has been started and has not yet died. | Yes |- | [[API/functions/x_thread_join|x_thread_join]]() | void | string id, [int maxWait] | {{object|InterruptedException}} | Waits for the thread with the given id to exit. By default, we wait potentially forever, but if maxWait is specified, we will only wait that many milliseconds. (Sending 0 for this value causes an infinite wait.) If the timeout occurs or thread interrupted, an InterruptedException is thrown. If the id is unknown, this function will directly return | Yes |} == Trades ==
Functions related to the management of trades and merchants. A trade is a special kind of recipe accessed through the merchant interface. A merchant is a provider of trades, which may or may not be attached to a Villager or Wandering Trader.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/create_virtual_merchant|create_virtual_merchant]]()
| void
| ID, title
| {{object|IllegalArgumentException}}
| Creates a merchant that can be traded with by players but is not attached to a physical entity. The ID given should not be a UUID. The title is the text that will display at the top of the window while a player is trading with it. Created merchants will persist across recompiles, but not across server restarts. An exception will be thrown if a merchant already exists using the given ID.
| Yes
|-
| [[API/functions/delete_virtual_merchant|delete_virtual_merchant]]()
| boolean
| string
|
| Deletes a virtual merchant if one by the given ID exists. Returns true if one was removed, or false if there was no match for the ID.
| Yes
|-
| [[API/functions/get_merchant_trades|get_merchant_trades]]()
| array
| specifier
| {{object|IllegalArgumentException}}{{object|FormatException}}
{{object|BadEntityException}} | Returns a list of trades used by the specified merchant. Specifier can be the UUID of an entity or a virtual merchant ID. | Yes |- | [[API/functions/get_virtual_merchants|get_virtual_merchants]]() | array | | | Returns an array where the keys are currently registered merchant IDs and the values are the corresponding window titles of those merchants. | Yes |- | [[API/functions/merchant_trader|merchant_trader]]() | UUID | specifier | {{object|BadEntityException}}
{{object|FormatException}}
{{object|FormatException}}
{{object|IllegalArgumentException}}
{{object|LengthException}} | Returns the UUID of the user trading with the merchant, or null if no one is. | Yes |- | [[API/functions/popen_trading|popen_trading]]() | boolean | specifier, [player], [force] | {{object|PlayerOfflineException}}
{{object|LengthException}}
{{object|IllegalArgumentException}}
{{object|BadEntityException}}
{{object|FormatException}} | Opens a trading interface for the current player, or the one specified. Only one player can trade with a merchant at a time. If the merchant is already being traded with, the function will do nothing. When true, force will make the merchant trade with the player, closing the trade with the previous player if there was one. Function returns true if trading was successfully opened, and false if not. | Yes |- | [[API/functions/set_merchant_trades|set_merchant_trades]]() | void | specifier, array | {{object|IllegalArgumentException}}
{{object|FormatException}}
{{object|CastException}}
{{object|BadEntityException}}
{{object|NotFoundException}} | Sets the list of trades the specified merchant can use to the provided array of TradeArrays. The specifier can be the UUID of a physical entity or the ID of a user-created virtual merchant. [[API/functions/set_merchant_trades|See more...]]
| Yes |} == Weather ==
Provides functions to control the weather
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/has_storm|has_storm]]()
| boolean
| [world]
| {{object|InvalidWorldException}}
| Returns whether the world (defaults to player's world) has a storm.
| No
|-
| [[API/functions/has_thunder|has_thunder]]()
| boolean
| [world]
| {{object|InvalidWorldException}}
| Returns whether the world (defaults to player's world) has thunder.
| No
|-
| [[API/functions/lightning|lightning]]()
| string
| locationArray, [safe] x, y, z, [safe] | {{object|CastException}}
{{object|LengthException}}
{{object|InvalidWorldException}}
{{object|FormatException}} | Makes lightning strike at the x y z coordinates specified in the array or arguments. Safe defaults to false, but if true, lightning striking a player will not hurt them. Returns the UUID of the lightning bolt entity. | Yes |- | [[API/functions/set_thunder|set_thunder]]() | void | boolean, [world], [int] | {{object|InvalidWorldException}}
{{object|CastException}} | Sets whether or not the weather can have thunder. The third argument can specify how long the thunder should last in server ticks. | Yes |- | [[API/functions/storm|storm]]() | void | isStorming, [world], [int] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Creates a (rain) storm if isStorming is true, stops a storm if isStorming is false. The second argument can be a world name or the duration in ticks of the given weather setting. The third argument allows specifying both a world and a duration. The second param is required to be the world if the function is run from console. | Yes |} == Web ==
Contains various methods to make HTTP requests.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/email|email]]()
| void
| [profile], options
| {{object|FormatException}}{{object|PluginInternalException}}
{{object|IOException}} | Sends an email. See the extended description for more information. [[API/functions/email|See more...]]
([[API/functions/email#Examples|Examples...]]) | Yes |- | [[API/functions/http_clear_session_cookies|http_clear_session_cookies]]() | void | cookieJar | {{object|CastException}} | Clears out "session" cookies, that is cookies that weren't set with an expiration (which translates to 0 in an individual cookie). | No |- | [[API/functions/http_request|http_request]]() | void | url, callback
url, settings | {{object|FormatException}} | Makes an HTTP request to the given url. [[API/functions/http_request|See more...]]
([[API/functions/http_request#Examples|Examples...]]) | Yes |- | [[API/functions/url_decode|url_decode]]() | string | param | | Decodes a previously url encoded string.
([[API/functions/url_decode#Examples|Examples...]]) | No |- | [[API/functions/url_encode|url_encode]]() | string | param | | URL Encodes the parameter given. This escapes all special characters per the x-www-form-urlencoded format.
([[API/functions/url_encode#Examples|Examples...]]) | No |} == World ==
Provides functions for manipulating a world
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|-
| [[API/functions/create_world|create_world]]()
| void
| name, type, environment, [seed, [generator]]
| {{object|FormatException}}{{object|CastException}} | Creates or loads a world. The 'name' is the same as the directory name for the world. If a world directory by that name already exists, it will be loaded. The 'type' is one of NORMAL, FLAT, LARGE_BIOMES, AMPLIFIED. However, if level.dat exists in the world directory, the type from that will be used instead. The 'environment' is one of NORMAL, NETHER, THE_END, CUSTOM. This affects which regions directory is used in the world directory. The 'seed' can be an integer, a string (will be the hashcode), or null (will be random int). The 'generator' is the name of a custom world generator loaded on the server. | Yes |- | [[API/functions/distance|distance]]() | double | locationA, locationB | {{object|RangeException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|IllegalArgumentException}} | Returns the distance between two locations. | No |- | [[API/functions/get_chunk_loc|get_chunk_loc]]() | array | [locationArray] | {{object|FormatException}}
{{object|InsufficientArgumentsException}}
{{object|NotFoundException}} | Returns an array of (x, z, world) coordinates of the chunk of either the location specified or the location of the player running the command. | No |- | [[API/functions/get_difficulty|get_difficulty]]() | string | world | {{object|InvalidWorldException}} | Returns the difficulty of the world, It will be one of PEACEFUL, EASY, NORMAL, or HARD. | Yes |- | [[API/functions/get_force_loaded_chunks|get_force_loaded_chunks]]() | array | [world] | {{object|InvalidWorldException}} | Gets an array of all chunk coordinates that are persistently loaded. | No |- | [[API/functions/get_gamerule|get_gamerule]]() | mixed | world, [gameRule] | {{object|InvalidWorldException}}
{{object|FormatException}} | Returns an associative array containing the values of all existing gamerules for the given world. If the gameRule parameter is specified, the function only returns that one value instead of an array. [[API/functions/get_gamerule|See more...]]
| Yes |- | [[API/functions/get_loaded_chunks|get_loaded_chunks]]() | array | [world] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|NotFoundException}} | Gets an array of all currently loaded chunks for a world. The current player's world is used if one is not provided. The chunk objects are associative arrays with the keys: x, z, and world. | Yes |- | [[API/functions/get_pitch|get_pitch]]() | double | location_from, location_to | {{object|InvalidWorldException}}
{{object|FormatException}} | Calculate pitch from one location to another. This will be from -90.0 to 90.0, which is up and down respectively. | Yes |- | [[API/functions/get_pvp|get_pvp]]() | boolean | world | {{object|InvalidWorldException}} | Returns if PVP is allowed in the world. | Yes |- | [[API/functions/get_spawn|get_spawn]]() | array | [world] | {{object|InvalidWorldException}}
{{object|FormatException}} | Returns a location array for the specified world, or the current player's world if one is not specified. | Yes |- | [[API/functions/get_temperature|get_temperature]]() | double | locationArray | {{object|FormatException}} | Returns the current temperature at the location given. | No |- | [[API/functions/get_vector|get_vector]]() | array | locationArray, [magnitude] | {{object|RangeException}}
{{object|FormatException}} | Returns a vector from the yaw and pitch in a location array. Only the yaw and pitch keys are required in the array. The second parameter, that defines the magnitude of the vector, defaults to 1.0. | No |- | [[API/functions/get_world_autosave|get_world_autosave]]() | boolean | world_name | {{object|InvalidWorldException}} | Fetch the world's current auto-save state. | Yes |- | [[API/functions/get_world_border|get_world_border]]() | array | world_name | {{object|InvalidWorldException}} | Returns an associative array of all information about the world's border. The keys are width, center, damagebuffer, damageamount, warningtime, warningdistance. | Yes |- | [[API/functions/get_world_day|get_world_day]]() | int | [world] | {{object|InvalidWorldException}} | Returns the current day number of the specified world | Yes |- | [[API/functions/get_world_time|get_world_time]]() | int | [world] | {{object|InvalidWorldException}} | Returns the time of the specified world, as an integer from 0 to 24000-1 | Yes |- | [[API/functions/get_worlds|get_worlds]]() | array | | | Returns a list of all currently loaded worlds. | Yes |- | [[API/functions/get_yaw|get_yaw]]() | double | location_from, location_to | {{object|InvalidWorldException}}
{{object|FormatException}} | Calculate yaw from one location to another on the X-Z plane. The rotation is measured in degrees (0-359.99...) relative to the (x=0,z=1) vector, which points south. Throws a FormatException if locations have differing worlds. Can return 'NaN' if the x and z coordinates are identical. | Yes |- | [[API/functions/is_slime_chunk|is_slime_chunk]]() | boolean | x, z, [world]
locationArray, [world] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Returns if the chunk is a slime spawning chunk. The current player's world is used if one is not provided. | Yes |- | [[API/functions/load_chunk|load_chunk]]() | void | [world], x, z
[world], locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Loads a chunk for a world using the x and z coordinates. The current player's world is used if one isn't provided. | Yes |- | [[API/functions/location_shift|location_shift]]() | array | origin, target, [distance], [clamp]
origin, direction, [distance] | {{object|InvalidWorldException}}
{{object|FormatException}} | Returns a location array that is the specified distance from the origin location along a vector. [[API/functions/location_shift|See more...]]
([[API/functions/location_shift#Examples|Examples...]]) | Yes |- class="hiddenFunction" | [[API/functions/refresh_chunk|refresh_chunk]]() | void | [world], x, z
[world], locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | This is not guaranteed to work reliably! Resends the chunk data to all clients, using the specified world or current player's world. | Yes |- | [[API/functions/regen_chunk|regen_chunk]]() | boolean | x, z, [world]
locationArray, [world] | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Regenerate the chunk for a world. The current player's world is used if one is not provided. Beware that this is destructive! Any data in this chunk will be lost! Returns true if the operation was successful. This function is deprecated. Results will vary per platform and may not work at all. | Yes |- | [[API/functions/save_world|save_world]]() | void | world_name | {{object|InvalidWorldException}} | Saves the specified world. | Yes |- | [[API/functions/set_chunk_force_loaded|set_chunk_force_loaded]]() | void | [world], x, z, forced
locationArray, forced | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Sets a chunk to be persistently loaded. | Yes |- | [[API/functions/set_difficulty|set_difficulty]]() | void | [world], difficulty | {{object|InvalidWorldException}}
{{object|FormatException}} | Sets the difficulty of the world with the given name, or all worlds if the name is not given. The difficulty can be PEACEFUL, EASY, NORMAL, or HARD. | Yes |- | [[API/functions/set_gamerule|set_gamerule]]() | boolean | [world], gameRule, value | {{object|InvalidWorldException}}
{{object|FormatException}}
{{object|CastException}} | Sets the value of the gamerule for the specified world. If world is not given the value is set for all worlds. Returns true if successful. [[API/functions/set_gamerule|See more...]]
| Yes |- | [[API/functions/set_keep_spawn_loaded|set_keep_spawn_loaded]]() | void | world, boolean | {{object|InvalidWorldException}} | Sets whether or not the spawn chunks in the given world should stay loaded. | Yes |- | [[API/functions/set_pvp|set_pvp]]() | void | [world], boolean | {{object|InvalidWorldException}} | Sets if PVP is allowed in the world with the given name, or all worlds if the name is not given. | Yes |- | [[API/functions/set_spawn|set_spawn]]() | void | locationArray
[world], x, y, z | {{object|InvalidWorldException}}
{{object|CastException}}
{{object|FormatException}} | Sets the spawn of the world. Note that in some cases a plugin may override the spawn, and this method will do nothing. In that case, you should use the plugin's commands to set the spawn. | Yes |- | [[API/functions/set_world_autosave|set_world_autosave]]() | void | [world_name], newState | | Updates the world's auto-save state. If no world is specified, set the option for all worlds. | Yes |- | [[API/functions/set_world_border|set_world_border]]() | void | world_name, paramArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}}
{{object|RangeException}} | Updates the world's border with the given values. In addition to the keys returned by get_world_border(), you can also specify the "seconds". This is time in which the border will move from the previous width to the new "width". | Yes |- | [[API/functions/set_world_day|set_world_day]]() | void | [world], day | {{object|InvalidWorldException}} | Set the current day number of a given world | Yes |- | [[API/functions/set_world_time|set_world_time]]() | void | [world], time | {{object|InvalidWorldException}}
{{object|FormatException}} | Sets the time of a given world. Should be a number from 0 to 24000, if not, it is modulo scaled. [[API/functions/set_world_time|See more...]]
| Yes |- | [[API/functions/spawn_falling_block|spawn_falling_block]]() | string | locationArray, blockName, [vectorArray] | {{object|FormatException}} | Spawns a falling block entity of the specified block type at the specified location, applying the vector array as a velocity if given. Values for the vector array are doubles, and 1.0 seems to imply about 3 times walking speed. Gravity applies for y. | Yes |- | [[API/functions/unload_chunk|unload_chunk]]() | void | [world], x, z
[world], locationArray | {{object|CastException}}
{{object|FormatException}}
{{object|InvalidWorldException}} | Unloads a chunk for a world using the x and z coordinates. The current player's world is used if one is not provided. | Yes |- | [[API/functions/unload_world|unload_world]]() | boolean | world, [save] | {{object|InvalidWorldException}} | Unloads a world, and saves it if save is true (defaults true), and returns whether or not the operation was successful. | Yes |- | [[API/functions/world_info|world_info]]() | array | world | {{object|InvalidWorldException}} | Returns an associative array of all the info needed to duplicate the world. The keys are name, seed, environment, generator, worldtype, sealevel and maxheight. [[API/functions/world_info|See more...]]
| Yes |} == XGUI ==
This provides extremely limited gui control functions. This entire class is experimental, and will probably be removed at some point.
{| class="sticky"
|-
! scope="col" width="8%" | Function Name
! scope="col" width="4%" | Returns
! scope="col" width="16%" | Arguments
! scope="col" width="8%" | Throws
! scope="col" width="62%" | Description
! scope="col" width="2%" | Res
|- class="hiddenFunction"
| [[API/functions/x_launch_browser|x_launch_browser]]()
| void
| url
| {{object|IOException}}
| Launches the desktop's default browser with the given url. On headless systems, this will throw an exception.
| Yes
|}
Find a bug in this page? Edit this page yourself, then submit a pull request.