![]() |
FourKit 29eeeb8
The LCE C# Server Plugin API
|
This page covers every event that FourKit provides, with descriptions of what they do and code examples showing how to use them. Every event handler method must be public, return void, take a single event parameter, and be annotated with [EventHandler] inside a class that implements Listener.
Events that implement Cancellable can be cancelled by calling setCancelled(true). A cancelled event will not execute its default server action (such as preventing chatting), but will still be passed to other plugins (unless IgnoreCancelled is set to true for a certain event handler)
Theres no guarantee this will be fully up to date as new events get added. Be sure to check the actual API documentation. Also some of these functions may not work as intended, as we are still in the process of rewriting everything. If something doesnt work, let us know on github.
PlayerLoginEvent is fired when a player is about to log in, after pre-login checks but before the join event. You can inspect or modify the player's XUIDs, name, and IP address, and cancel the login. The XUID API is experimental: you can set and get the raw XUID values. The offline XUID is the main XUID used by the client; the online XUID is used for guests (splitscreen users).
| Method | Description |
|---|---|
| getName() | The player's username attempting to log in. |
| getAddress() | The InetSocketAddress of the connection. |
| getLoginType() | The login type (e.g. online, offline). |
| getOfflineXuid() | Experimental. The main XUID used by the client. |
| setOfflineXuid(ulong) | Experimental. Set the offline XUID. |
| getOnlineXuid() | Experimental. The XUID used for guests (splitscreen users). |
| setOnlineXuid(ulong) | Experimental. Set the online XUID. |
| hasChangedXuidValues() | Experimental. True if XUID values were changed. |
| isCancelled() | Whether the login is cancelled. |
| setCancelled(bool) | Cancel or allow the login. |
Cancellable: Yes
PlayerPreLoginEvent is fired before a player is allowed to join the server. You can inspect the players name and IP address, and cancel the event to prevent them from joining (such as for bans, whitelists, etc).
| Method | Description |
|---|---|
| getName() | The player's username attempting to join. |
| getAddress() | The InetSocketAddress of the connection. |
| isCancelled() | Whether the login is cancelled. |
| setCancelled(bool) | Cancel or allow the login. |
Cancellable: Yes
PlayerJoinEvent is fired when a player joins the server. You can read or change the join message that is broadcast to all online players.
| Method | Description |
|---|---|
| getPlayer() | The player who joined. |
| getJoinMessage() | The join message that will be broadcast. |
| setJoinMessage(string) | Change or suppress the join message. Pass null to suppress. |
Cancellable: No
PlayerQuitEvent is fired when a player disconnects from the server. You can change the quit message or suppress it.
| Method | Description |
|---|---|
| getPlayer() | The player who left. |
| getQuitMessage() | The quit message that will be broadcast. |
| setQuitMessage(string) | Change or suppress the quit message. Pass null to suppress. |
Cancellable: No
PlayerKickEvent is fired when a player is about to be kicked. Cancelling this event keeps the player connected.
| Method | Description |
|---|---|
| getPlayer() | The player being kicked. |
| getReason() | The DisconnectReason. |
| setReason(DisconnectReason) | Change the kick reason. |
| getLeaveMessage() | The message broadcast to other players. |
| setLeaveMessage(string) | Change the broadcast message. |
Cancellable: Yes
PlayerChatEvent is fired when a player sends a chat message. You can modify the message, change the format, or cancel it entirely.
Format is the same as bukkit, with %1$s being the player name and %2$s being the message.
| Method | Description |
|---|---|
| getPlayer() | The player who sent the message. |
| getMessage() | The chat message. |
| setMessage(string) | Change the chat message. |
| getFormat() | The format string (e.g. "<%1$s> %2$s"). |
| setFormat(string) | Change the format string. |
Cancellable: Yes
PlayerMoveEvent is fired whenever a player moves. You can redirect the player or cancel the movement.
| Method | Description |
|---|---|
| getPlayer() | The player who moved. |
| getFrom() | The location the player moved from. |
| getTo() | The location the player is moving to. |
| setFrom(Location) | Override the from location. |
| setTo(Location) | Redirect the player to a different destination. |
Cancellable: Yes
PlayerTeleportEvent extends PlayerMoveEvent and is fired when a player teleports. It includes a TeleportCause describing why the teleport happened.
| Method | Description |
|---|---|
| getPlayer() | The player who teleported. |
| getFrom() | The origin location. |
| getTo() | The destination location. |
| setTo(Location) | Redirect the teleport destination. |
| getCause() | The TeleportCause (ENDER_PEARL, COMMAND, PLUGIN, NETHER_PORTAL, END_PORTAL, UNKNOWN). |
Cancellable: Yes (inherited from PlayerMoveEvent)
PlayerPortalEvent extends PlayerTeleportEvent and is fired when a player enters a portal (nether or end). You can cancel it to prevent dimension travel.
| Method | Description |
|---|---|
| getPlayer() | The player entering the portal. |
| getFrom() | Where the player is coming from. |
| getTo() | Where the player will arrive. |
| setTo(Location) | Override the destination. |
| getCause() | The teleport cause. |
Cancellable: Yes (inherited)
PlayerDropItemEvent is fired when a player drops an item from their inventory. You can cancel it or change what item is dropped.
| Method | Description |
|---|---|
| getPlayer() | The player who dropped the item. |
| getItemDrop() | The ItemStack being dropped. |
| setItemDrop(ItemStack) | Change which item is dropped. |
Cancellable: Yes
PlayerPickupItemEvent is fired when a player picks up an item from the ground.
| Method | Description |
|---|---|
| getPlayer() | The player picking up the item. |
| getItem() | The Item entity on the ground. |
Cancellable: Yes
PlayerInteractEvent is fired when a player interacts with an object, block, or air. The Action enum tells you what kind of click it was.
| Method | Description |
|---|---|
| getPlayer() | The player who interacted. |
| getAction() | The Action (LEFT_CLICK_AIR, LEFT_CLICK_BLOCK, RIGHT_CLICK_AIR, RIGHT_CLICK_BLOCK, PHYSICAL). |
| getItem() | The ItemStack in the player's hand, or null. |
| getMaterial() | CONVENIENCE. the Material of the held item, or AIR. |
| hasBlock() | Whether a block was involved. |
| hasItem() | Whether an item was in hand. |
| isBlockInHand() | Whether the held item is a block (id 1-255). |
| getClickedBlock() | The Block that was clicked, or null. |
| getBlockFace() | The BlockFace that was clicked. |
| useItemInHand() | Whether the item in hand should be used. |
| setUseItemInHand(bool) | Override whether the item in hand is used. |
Cancellable: Yes
PlayerInteractEntityEvent is fired when a player right-clicks an entity.
| Method | Description |
|---|---|
| getPlayer() | The player who interacted. |
| getRightClicked() | The entity that was right-clicked. |
Cancellable: Yes
PlayerBedEnterEvent is fired when a player is about to enter a bed.
| Method | Description |
|---|---|
| getPlayer() | The player entering the bed. |
| getBed() | The bed Block. |
Cancellable: Yes
PlayerBedLeaveEvent is fired when a player leaves a bed.
| Method | Description |
|---|---|
| getPlayer() | The player leaving the bed. |
| getBed() | The bed Block. |
Cancellable: No
PlayerCommandPreprocessEvent is fired early in the command handling process when a player sends a command. You can modify the command, cancel it, or use it for logging. This fires before the command is dispatched to any command handler.
| Method | Description |
|---|---|
| getPlayer() | The player who issued the command. |
| getMessage() | The full command string the player is sending. |
| setMessage(string) | Change the command that will be processed. |
| isCancelled() | Whether the command is cancelled. |
| setCancelled(bool) | Cancel or allow the command. |
Cancellable: Yes
EntityDamageEvent is fired when any entity takes damage. The entity can be a Player or any LivingEntity. Use getEntityType() to check before casting.
| Method | Description |
|---|---|
| getEntity() | The entity that was damaged. |
| getEntityType() | The EntityType of the damaged entity. |
| getCause() | The DamageCause (e.g. FALL, FIRE, ENTITY_ATTACK, VOID, DROWNING, etc.). |
| getDamage() | The raw damage amount. |
| setDamage(double) | Change the raw damage amount. |
| getFinalDamage() | The damage after reductions. |
Cancellable: Yup. cancelling prevents any damage.
EntityDamageByEntityEvent extends EntityDamageEvent and is fired when an entity is damaged by another entity (e.g. player hits a mob, or mob hits a player).
| Method | Description |
|---|---|
| getEntity() | The entity that was damaged. |
| getDamager() | The entity that dealt the damage. |
| getCause() | The DamageCause. |
| getDamage() / setDamage(double) | Read/modify the damage. |
Cancellable: Yes
PlayerDeathEvent extends EntityDeathEvent and is fired when a player dies. It adds control over the death message, respawn experience, and keep-inventory.
| Method | Description |
|---|---|
| getEntity() | The Player who died. |
| getDeathMessage() | The death message shown to all players. |
| setDeathMessage(string) | Change the death message. |
| getDroppedExp() / setDroppedExp(int) | XP orbs dropped on death. |
| getDrops() | Mutable list of item drops. |
| getNewExp() / setNewExp(int) | XP the player has after respawning. |
| getNewLevel() / setNewLevel(int) | Level the player has after respawning. |
| getKeepLevel() / setKeepLevel(bool) | Whether the player keeps their XP level. Overrides other XP settings. |
| getKeepInventory() / setKeepInventory(bool) | Whether the player keeps their inventory on death. |
Cancellable: No
StructureGrowEvent is fired when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), either naturally or using bonemeal. You can cancel it, inspect the location, species, and optionally the player who caused it.
| Method | Description |
|---|---|
| getLocation() | The location of the structure. |
| getSpecies() | The species type (birch, normal, pine, red mushroom, brown mushroom). |
| isFromBonemeal() | True if the structure was grown using bonemeal. |
| getPlayer() | The player that created the structure, null if not created manually. |
| isCancelled() | Whether the event is cancelled. |
| setCancelled(bool) | Cancel or allow the structure growth. |
Cancellable: Yes
BlockBreakEvent is fired when a player breaks a block. You can cancel it, change the XP dropped, or inspect the block.
| Method | Description |
|---|---|
| getBlock() | The Block being broken. |
| getPlayer() | The player who broke the block. |
| getExpToDrop() | The XP that will be dropped. |
| setExpToDrop(int) | Set the XP dropped (1+ to drop, 0 for none). |
Cancellable: Yes
BlockPlaceEvent is fired when a player places a block. You can cancel the placement or change the placed block.
| Method | Description |
|---|---|
| getBlock() / getBlockPlaced() | The Block that was placed. |
| getBlockAgainst() | The block this was placed against. |
| getItemInHand() | The ItemStack used to place the block. |
| getPlayer() | The player who placed the block. |
Cancellable: Yes
SignChangeEvent is fired when a player edits a sign. You can read, modify, or cancel the sign text.
| Method | Description |
|---|---|
| getBlock() | The sign Block. |
| getPlayer() | The player who edited the sign. |
| getLines() | All 4 lines as a string[]. |
| getLine(int) | A single line (0-3). |
| setLine(int, string) | Change a single line (0-3). |
Cancellable: Yes
BlockGrowEvent is fired when a block grows naturally in the world. This includes crops (wheat, nether wart, cocoa beans), sugar cane, cactus, and melon/pumpkin fruit placement.
| Method | Description |
|---|---|
| getBlock() | The Block that is growing. |
| getNewState() | The BlockState representing what the block will become. |
| isCancelled() | Whether the growth is cancelled. |
| setCancelled(bool) | Cancel or allow the growth. |
Cancellable: Yes
BlockFormEvent extends BlockGrowEvent and is fired when a block forms due to world conditions. Examples include snow forming during a storm and ice forming in cold biomes. Use BlockSpreadEvent to catch blocks that actually spread instead of randomly forming.
| Method | Description |
|---|---|
| getBlock() | The Block that is forming. |
| getNewState() | The BlockState representing what the block will become. |
| isCancelled() | Whether the formation is cancelled. |
| setCancelled(bool) | Cancel or allow the formation. |
Cancellable: Yes (inherited from BlockGrowEvent)
BlockSpreadEvent extends BlockFormEvent and is fired when a block spreads from one location to another. Examples include fire spreading, mushrooms spreading, and grass spreading to dirt.
| Method | Description |
|---|---|
| getBlock() | The Block where the spread is occurring (destination). |
| getSource() | The source Block that is spreading. |
| getNewState() | The BlockState representing what the block will become. |
| isCancelled() | Whether the spread is cancelled. |
| setCancelled(bool) | Cancel or allow the spread. |
Cancellable: Yes (inherited)
BlockBurnEvent is fired when a block is destroyed as a result of being burnt by fire.
| Method | Description |
|---|---|
| getBlock() | The Block that is being burnt. |
| isCancelled() | Whether the burn is cancelled. |
| setCancelled(bool) | Cancel or allow the burn. |
Cancellable: Yes
BlockFromToEvent is fired when a block moves from one location to another. This currently only applies to liquid flow (lava and water) and teleporting dragon eggs.
| Method | Description |
|---|---|
| getBlock() | The source Block that is moving. |
| getToBlock() | The destination Block. |
| getFace() | The BlockFace direction the block is moving to. |
| isCancelled() | Whether the move is cancelled. |
| setCancelled(bool) | Cancel or allow the move. |
Cancellable: Yes
BlockPistonExtendEvent extends BlockPistonEvent and is fired when a piston extends. You can inspect the piston direction, stickiness, number of blocks being pushed, and cancel the extension.
| Method | Description |
|---|---|
| getBlock() | The piston Block. |
| getDirection() | The BlockFace direction the piston is extending. |
| isSticky() | Whether the piston is a sticky piston. |
| getLength() | The number of blocks being pushed. |
| getBlocks() | List of Block objects that will be moved. |
| isCancelled() | Whether the extension is cancelled. |
| setCancelled(bool) | Cancel or allow the extension. |
Cancellable: Yes
BlockPistonRetractEvent extends BlockPistonEvent and is fired when a piston retracts. For sticky pistons, the retract location indicates where the block being pulled is located.
| Method | Description |
|---|---|
| getBlock() | The piston Block. |
| getDirection() | The BlockFace direction the piston is retracting. |
| isSticky() | Whether the piston is a sticky piston. |
| getRetractLocation() | The Location of the block that may be pulled (for sticky pistons). |
| isCancelled() | Whether the retraction is cancelled. |
| setCancelled(bool) | Cancel or allow the retraction. |
Cancellable: Yes
InventoryOpenEvent is fired when a player opens an inventory (chest, furnace, crafting table, etc.). Cancelling this prevents the inventory screen from showing.
| Method | Description |
|---|---|
| getPlayer() | The HumanEntity who opened the inventory. |
| getInventory() | The top Inventory that was opened. |
| getView() | The full InventoryView. |
| getViewers() | List of players viewing this inventory. |
Cancellable: Yes
InventoryClickEvent is fired when a player clicks a slot in any open inventory. It provides detailed information about the click type, slot, and item.
Warning: Do not call closeInventory() or openInventory() from inside this event handler. The inventory is mid-modification. You should do this in a seperate thread fired later on.
| Method | Description |
|---|---|
| getWhoClicked() | The HumanEntity who clicked. |
| getClickedInventory() | The Inventory that was clicked, or null if outside the window. |
| getSlotType() | The SlotType of the clicked slot. |
| getCurrentItem() | The ItemStack in the clicked slot. |
| setCurrentItem(ItemStack) | Change the item in the clicked slot. |
| getCursor() | The ItemStack on the cursor. |
| getSlot() | The slot index relative to the clicked inventory. |
| getRawSlot() | The raw slot number unique to the view. |
| getClick() | The ClickType (e.g. LEFT, RIGHT, SHIFT_LEFT). |
| getAction() | The InventoryAction describing the outcome. |
| isLeftClick() / isRightClick() / isShiftClick() | Convenience click-type checks. |
| getHotbarButton() | The hotbar key pressed (0-8), or -1 if not a NUMBER_KEY click. |
| getInventory() | The top inventory of the view. |
| getView() | The full InventoryView. |
Cancellable: Yes
ChunkLoadEvent is fired when a chunk is loaded. If the chunk is newly generated it will not yet be populated when this event fires.
| Method | Description |
|---|---|
| getChunk() | The Chunk that was loaded. |
| isNewChunk() | True if this chunk was newly generated. Note that new chunks will not yet be populated at this time. |
Cancellable: No
ChunkUnloadEvent is fired when a chunk is about to be unloaded. You can cancel it to prevent the chunk from being unloaded.
| Method | Description |
|---|---|
| getChunk() | The Chunk that is about to be unloaded. |
| isCancelled() | Whether the unload is cancelled. |
| setCancelled(bool) | Cancel or allow the chunk unload. |
Cancellable: Yes