Code:Builtin Reference

From Warlords Wiki
Jump to: navigation, search

This is a reference of all builtins.

Player

These are builtins that manipulate players.

send-message

Signature

(player: Player, messages: Any...) -> Unit

Description

Concatenates all values in messages and sends it as a message to player.

give-item

Signature

(player: Player, items: Item...) -> Unit

Description

Gives all items to player.

remove-item

Signature

(player: Player, items: Item...) -> Unit

Description

Removes all items from player.

main-hand-item

Signature

(player: Player) -> Item

Description

Returns the item that player is holding in their main hand.

off-hand-item

Signature

(player: Player) -> Item

Description

Returns the item that player is holding in their off hand.

player-by-name

Signature

(name: String) -> Player | Unit

Description

Gets a player by the name

player-by-uuid

Signature

(uuid: String) -> Player | Unit

Description

Gets a player by a UUID

Errors

  • If the UUID is invalid.

uuid-of

Signature

(entity: Entity) -> String

Description

Gets the UUID of an entity.

name-of

Signature

(uuid: String) -> String

Description

Gets the name from a UUID. Note that entities, when coerced to a string, are converted into their UUID. This means that you can directly pass a player entity into this builtin.

Errors

  • If a player with the given UUID never joined the server.

set-gamemode

Signature

(player: Player, gamemode: GameMode)

Description

Changes the gamemode of a player.

subscribed?

Signature

(player: Player) -> Bool

Description

Returns true if a player is subscribed to the current code unit.

sneaking?

Signature

(player: Player) -> Bool

Description

Returns true if a player is sneaking.

sprinting?

Signature

(player: Player) -> Bool

Description

Returns true if a player is sprinting.

flying?

Signature

(player: Player) -> Bool

Description

Returns true if a player is flying.

selection

Signature

(player: Player) -> List<Location>

Description

Returns a list of every location within a player's selection (selected with `/wlmisc select`).

clear-inventory

Signature

(player: Player) -> Unit

Description

Clears a player's inventory.


Entity

These are builtins that manipulate entities.

teleport

Signature

(entity: Entity, location: Location) -> Unit

Description

Teleports entity to location.

spawn

Signature

(type: EntityType, location: Location) -> Entity

Description

Spawns an entity and returns it.

launch-projectile

Signature

(source: Entity, type: EntityType) -> Entity

Description

Launches a projectile from source and returns it.

Errors

  • If type is not a projectile entity.

damage

Signature

(entity: Entity, amount: Number) -> Unit

Description

Damages entity by amount.

Errors

  • If entity is not damageable.

effect

Signature

(entity: Entity, effect: PotionEffect, duration: Number, amplifier: Number, ambient: Bool?, particles: Bool?, icon: Bool?) -> Unit

Description

Applies a potion effect to an entity.

Errors

  • If the entity can not be given a potion effect.

location-of

Signature

(entity: Entity) -> Location

Description

Gets the location of entity.

kill

Signature

(entity: Entity) -> Unit

Description

Kills or despawns entity.

entity-get-armor

Signature

(entity: Entity) -> List<Item>

Description

Returns the armor an entity is wearing in the following order: Helmet, Chestplate, Leggings, Boots

entity-set-armor

Signature

(entity: Entity, armor: List<Item>) -> Unit

Description

Sets the armor of an entity in the following order: Helmet, Chestplate, Leggings, Boots

Operators

These implement simple operations on values.

+

Signature

(numbers: Number...) -> Number

Description

Adds all given numbers together.

-

Signature

(numbers: Number...) -> Number

Description

Subtracts all given numbers together.

*

Signature

(numbers: Number...) -> Number

Description

Multiplies all given numbers together.

/

Signature

(numbers: Number...) -> Number

Description

Divides all given numbers together. Note: You need to type \/ in order to type this character (a backslash before a name is ignored.)

%

Signature

(numbers: Number...) -> Number

Description

Modulos all given numbers together.

^

Signature

(numbers: Number...) -> Number

Description

Exponentiates all given numbers together.

<

Signature

(numbers: Number...) -> Bool

Description

Computes whether each number is less than the one before it.

<=

Signature

(numbers: Number...) -> Bool

Description

Computes whether each number is less than or equal to the one before it.

>

Signature

(numbers: Number...) -> Bool

Description

Computes whether each number is greater than the one before it.

>=

Signature

(numbers: Number...) -> Bool

Description

Computes whether each number is greater than or equal to the one before it.

=

Signature

(values: Any...) -> Bool

Description

Computes whether every value is equal.

!=

Signature

(values: Any...) -> Bool

Description

Computes whether every value is not equal.

!

Signature

(bool: Bool) -> Bool

Description

Inverts a boolean

&

Signature

(bools: Bool...) -> Bool

Description

Logically ANDs all arguments together.

|

Signature

(bools: Bool...) -> Bool

Description

Logically ORs all arguments together.

Number

Builtins that produce numbers.

rand-float

Signature

() -> Number

Description

Returns a random value anywhere between 0 and 1.

rand-int

Signature

(min: Number?, max: Number) -> Number

Description

Returns a random integer within the given range

Location

Builtins for location manipulation.

location-shift

Signature

(location: Location, x: Number, y: Number, z: Number, yaw: Number?, pitch: Number?) -> Location

Description

Returns location location but shifted by the given amounts.

location-shift-forwards

Signature

(location: Location, amt: Number) -> Location

Description

Returns location shifted by the given amount forwards.

location-x

Signature

(location: Location) -> Number

Description

Returns the x-coordinate of the location.

location-y

Signature

(location: Location) -> Number

Description

Returns the y-coordinate of the location.

location-z

Signature

(location: Location) -> Number

Description

Returns the z-coordinate of the location.

List

Builtins for manipulating and creating lists.

list-get

Signature

(list: List, idx: Number) -> Any

Description

Indexes list by idx

Errors

  • If idx is out of bounds.

list-set

Signature

(list: List, idx: Number, value: Any) -> Any

Description

Sets the value at index idx to value

Errors

  • If idx is out of bounds.

list-push

Signature

(list: List, values: Any...) -> List

Description

Pushes all values to list, and then returns the list.

list-cat

Signature

(list: List, lists: List...) -> List

Description

Concatenates all lists to list

list-remove

Signature

(list: List, idx: Number) -> Any

Description

Removes the value at idx and returns it.

Errors

  • If idx is out of bounds.

list-length

Signature

(list: List) -> Number

Description

Returns the length of list

list-slice

Signature

(list: List, start: Number, end: Number) -> List

Description

Creates a new list that contains the items between start (inclusive) and end (exclusive) of list.

list-has

Signature

(list: List, value: Any) -> Bool

Description

Returns whether a list has a given value.

range

Signature

(min: Number?, max: Number) -> List<Number>

Description

Creates a list containing elements of the given range, excluding the maximum. (e.g. range[10] -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

index-of

Signature

(haystack: List, needle: Any) -> Number | Unit

Description

Gets the index of needle inside haystack. Returns Unit if it can't be found.

Map

Builtins for manipulating maps.

map-get

Signature

(map: Map, key: String) -> Any

Description

Returns the value in map at index key.

Errors

  • If map does not have key.

map-set

Signature

(map: Map, key: String, value: Any) -> Unit

Description

Sets key to value in map

map-has

Signature

(map: Map, key: String) -> Bool

Description

Returns whether or not map has key

map-delete

Signature

(map: Map, key: String) -> Unit

Description

Deletes key from map

Errors

If key is not in map

String

Operations on strings.

string-cat

Signature

(string: String...) -> String

Description

Concatenates all the given strings together

string-length

Signature

(string: String) -> Number

Description

Returns the length of the string.

string-slice

Signature

(string: String, start: Number, end: Number) -> String

Description

Gets a slice of the string starting at start (inclusive) and ending at end (exclusive)

Errors

  • If start or end are out of bounds

string-split

Signature

(string: String, separator: String) -> List<String>

Description

Splits a string into a list around the occurrences of the specified separator.

string-capitalize

Signature

(string: String) -> String

Description

Converts a string to title case. (e.g. "foo BAR bAZ Qux" -> "Foo Bar Baz Qux")

string-chunked

Signature

(string: String, size: Number) -> List<String>

Description

Splits string into a list of strings each not exceeding size.

string-ends-with

Signature

(string: String, suffix: String) -> Bool

Description

Returns true if the string ends with the given suffix.

string-starts-with

Signature

(string: String, prefix: String) -> Bool

Description

Returns true if the string starts with the given prefix.

string-replace

Signature

(string: String, from: String, to: String) -> String

Description

Replaces from with to in string (e.g. replace [ "foo bar foo baz bar" "foo" "qux" ] returns "quz bar quz baz bar")

string-reverse

Signature

(string: String) -> String

Description

Reverses a string

string-uppercase

Signature

(string: String) -> String

Description

Uppercases a string (i.e "fOo" -> "FOO")

string-lowercase

Signature

(string: String) -> String

Description

Lowercases a string (i.e. "FOo" -> "foo")

string-contains

Signature

(string: String, substring: String) -> Bool

Description

Returns true if string contains substring somewhere in it.

Item

These do operations on items.

item-name

Signature

(item: Item) -> String

Description

Returns the name of the item.

item-set-name

Signature

(item: Item, name: String) -> Item

Description

Sets the name of the item, and returns it.

item-clone

Signature

(item: Item) -> Item

Description

Clones the item.

item-lore

Signature

(item: Item) -> List<String>

Description

Returns an item's lore. If the item does not have lore, this returns an empty list.

item-set-lore

Signature

(item: Item, lore: List<String>) -> Item

Description

Sets the lore of an item. Returns the same item.

item-material

Signature

(item: Item) -> Material

Description

Returns the material of an item.

item-set-material

Signature

(item: Item, material: Material) -> Item

Description

Sets the material of an item. Returns the same item.

Conversions

These convert from one type to another.

to-string

Signature

(value: Any) -> String

Description

Converts value to a string.

to-number

Signature

(value: Any) -> Number | Unit

Description

Attempts to convert value to a number, and returns Unit on failure.

Cache

Builtins for manipulating the Cache.

cache-set

Signature

(key: String, value: Any) -> Unit

Description

Sets a value in the cache.

cache-get

Signature

(key: String) -> Any

Description

Gets a value from the cache. Returns Unit if the value is not present.

World

set-block

Signature

(location: Location, block: Item) -> Unit

Description

Sets a block at a location.

get-block

Signature

(location: Location) -> Item

Description

Gets a block at a location

Enums

entity-type?

Signature

(enum: String) -> Bool

Description

Returns whether enum is a valid EntityType

game-mode?

Signature

(enum: String) -> Bool

Description

Returns whether enum is a valid GameMode

potion-effect?

Signature

(enum: String) -> Bool

Description

Returns whether enum is a valid PotionEffect

sound?

Signature

(enum: String) -> Bool

Description

Returns whether enum is a valid Sound

material?

Signature

(enum: String) -> Bool

Description

Returns whether enum is a valid Material

Miscellaneous

These don't fit nicely into any of the other categories.

log

Signature

(messages: Any...) -> Unit

Description

Logs all given messages to the Code Unit's log.

set-cancelled

Signature

(cancelled: Boolean) -> Unit

Description

Sets the cancelled status of the event.

Errors

  • If the event is not cancellable
  • If there is no event.

broadcast

Signature

(messages: Any...) -> Unit

Description

Broadcasts all messages to all players online.

channel-braodcast

Signature

(channel: String, messages: Any...) -> Unit

Description

Broadcasts all messages to players in the given channel.

spawn-particle

Signature

(type: Particle, location: Location, count: Number, speed: Number)

Description

Spawns count particles of type type at location

online-players

Signature

() -> List<Player>

Description

Returns a list of all online players

play-sound

Signature

(sound: Sound, location: Location, volume: Number, pitch: Number, player: Player?) -> Unit

Description

Plays a sound. If player is specified, it only plays it for that player.

run-command

Signature

(command: String) -> Unit

Description

Runs a command.

perlin

Signature

(x: Number, y: Number, z: Number, octaves: Number, frequency: Number, amplitude: Number) -> Number

Description

Returns 3-dimensional perlin noise at the given position and with the given parameters. One or more coordinates can be set to 0 for lower dimensional noise.