Events
Every script starts with one of these. The blocks under it run each time that thing happens in the game.
when the server starts
Runs when the scripts are loaded: when the server starts, after /denovo reload, and whenever a script is switched on from the /denovos menu. Each time, every start script that is switched on runs again, not only the new one.
| Event value | Type | What it is |
|---|---|---|
event.world | World | The server's first world, usually the overworld. |
def onStart(event) { }when the command /[text] is run
Runs when a player types the command. The command exists for as long as the script is loaded, so there is nothing else to set up. Only players can use it, not the server console.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | text | The command name without the slash. Letters, numbers, - and _ only, up to 32 characters. |
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who typed the command. |
event.args | text | Everything typed after the command, as one text with the words separated by spaces. Empty when nothing was typed. |
@command("mycommand")
def onCommand(event) { }when a player joins
Runs when a player joins the server.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who joined. |
event.joinMessage | Component | The join message shown in chat, as styled text. Use plain text of to read it as text. |
def onPlayerJoin(event) { }when a player leaves
Runs when a player leaves the server, just before they are removed from it.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who is leaving. |
event.quitMessage | Component | The leave message shown in chat, as styled text. |
def onPlayerQuit(event) { }when a player chats
Runs when a player sends a chat message. The blocks under it run on the next tick, after the message has been handled.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who wrote the message. |
event.message | Component | What they wrote, as styled text. Use plain text of to turn it into text you can compare. |
def onChat(event) { }when a player runs a command
Runs when a player types any command, before the command itself runs.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who typed the command. |
event.message | text | The whole line they typed, slash included, for example /home 2. |
def onPlayerCommandPreprocess(event) { }when a player moves
Runs every time a player moves or turns their head, which can be many times a second, so keep the blocks under it short. Offset by changes the location it is given, so use it on location of the player rather than on from or to.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who is moving. |
event.from | Location | Where the player was before this move. |
event.to | Location | Where the player is moving to. |
def onPlayerMove(event) { }when a player teleports
Runs when a player is teleported, whether by a command, an ender pearl, a portal or a script.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player being teleported. |
event.from | Location | Where they are teleported from. |
event.to | Location | Where they are teleported to. |
def onPlayerTeleport(event) { }when a player changes world
Runs after a player has moved into another world, for example through a nether portal.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who changed world. |
event.from | World | The world they came from. |
def onPlayerChangedWorld(event) { }when a player dies
Runs when a player dies.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who died. |
event.deathMessage | Component | The death message shown in chat, as styled text. |
event.droppedExp | number | How much experience the player drops. |
event.newLevel | number | The experience level the player will have after respawning. |
def onPlayerDeath(event) { }when a player respawns
Runs when a player respawns after dying, just before they appear in the world.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who is respawning. |
event.respawnLocation | Location | Where the player will appear. |
def onPlayerRespawn(event) { }when a player interacts
Runs when a player clicks with either mouse button, on a block or into the air, and when they step on something like a pressure plate. A right click can run it twice, once for each hand, so check hand or material when that matters.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player who clicked. |
event.action | Action | What kind of click it was: LEFT_CLICK_BLOCK, RIGHT_CLICK_BLOCK, LEFT_CLICK_AIR, RIGHT_CLICK_AIR, or PHYSICAL for stepping on something. |
event.clickedBlock | Block | The block that was clicked. It is empty when the player clicked into the air, and using an empty block stops the script, so check action first. |
event.blockFace | BlockFace | Which side of the block was clicked. |
event.hand | EquipmentSlot | Which hand this run is for: HAND or OFF_HAND. |
event.material | Material | The material of the item in that hand. AIR when the hand is empty. |
def onPlayerInteract(event) { }when a player eats or drinks
Runs when a player finishes eating food or drinking a potion or milk.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player eating or drinking. |
event.hand | EquipmentSlot | The hand holding the item. |
def onPlayerItemConsume(event) { }when a player enters a bed
Runs when a player tries to get into a bed.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player getting into bed. |
event.bed | Block | The bed block. |
def onPlayerBedEnter(event) { }when a player starts or stops sneaking
Runs when a player starts or stops sneaking.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player. |
event.sneaking | true/false | true when they start sneaking, false when they stop. |
def onPlayerToggleSneak(event) { }when a player starts or stops sprinting
Runs when a player starts or stops sprinting.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player. |
event.sprinting | true/false | true when they start sprinting, false when they stop. |
def onPlayerToggleSprint(event) { }when a player's level changes
Runs when a player's experience level goes up or down.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player. |
event.oldLevel | number | The level they had before. |
event.newLevel | number | The level they have now. |
def onPlayerLevelChange(event) { }when a player gains experience
Runs when a player is about to get experience, for example from an orb.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player. |
event.amount | number | How much experience they are getting. |
def onPlayerExpChange(event) { }when a player's game mode changes
Runs when a player's game mode is about to change.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player. |
event.newGameMode | GameMode | The game mode they are switching to. |
def onPlayerGameModeChange(event) { }when a block is broken
Runs when a player breaks a block.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player breaking the block. |
event.block | Block | The block being broken. It still has its old material while the blocks under this event run. |
event.expToDrop | number | How much experience the block will drop. |
def onBlockBreak(event) { }when a block is placed
Runs when a player places a block.
| Event value | Type | What it is |
|---|---|---|
event.player | Player | The player placing the block. |
event.block | Block | The block that was placed, already of its new material. |
event.blockAgainst | Block | The block it was placed against. |
event.hand | EquipmentSlot | The hand the block was placed from. |
def onBlockPlace(event) { }