blockstate, more block events, command preprocess event.

This commit is contained in:
sylvessa 2026-04-06 01:52:58 -05:00
parent 21b5accc69
commit 18a673bd46
34 changed files with 1359 additions and 58 deletions

View file

@ -462,6 +462,56 @@ public void onBedLeave(PlayerBedLeaveEvent e)
---
@subsection playercommandpreprocessevent PlayerCommandPreprocessEvent
\ref Minecraft.Server.FourKit.Event.Player.PlayerCommandPreprocessEvent "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.
```csharp
[EventHandler]
public void onCommand(PlayerCommandPreprocessEvent e)
{
// log all commands
Console.WriteLine(e.getPlayer().getName() + " issued command: " + e.getMessage());
}
```
```csharp
[EventHandler]
public void onCommand(PlayerCommandPreprocessEvent e)
{
// block a specific command
if (e.getMessage().StartsWith("/secret"))
{
e.setCancelled(true);
e.getPlayer().sendMessage("That command is disabled!");
}
}
```
```csharp
[EventHandler]
public void onCommand(PlayerCommandPreprocessEvent e)
{
// redirect a command alias
if (e.getMessage().StartsWith("/gm "))
{
e.setMessage("/gamemode " + e.getMessage().Substring(4));
}
}
```
| 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
---
@section entity_events Entity Events
@subsection entitydamageevent EntityDamageEvent
@ -745,6 +795,259 @@ public void onSign(SignChangeEvent e)
---
---
@subsection blockgrowevent BlockGrowEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockGrowEvent "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.
```csharp
[EventHandler]
public void onGrow(BlockGrowEvent e)
{
// prevent all crop growth
e.setCancelled(true);
}
```
```csharp
[EventHandler]
public void onGrow(BlockGrowEvent e)
{
// log growth events
var b = e.getBlock();
Console.WriteLine($"Block grew at {b.getX()}, {b.getY()}, {b.getZ()} type={b.getType()}");
}
```
| 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
---
@subsection blockformevent BlockFormEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockFormEvent "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 \ref Minecraft.Server.FourKit.Event.Block.BlockSpreadEvent "BlockSpreadEvent" to catch blocks that actually spread instead of randomly forming.
```csharp
[EventHandler]
public void onForm(BlockFormEvent e)
{
// prevent snow and ice from forming
e.setCancelled(true);
}
```
| 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`)
---
@subsection blockspreadevent BlockSpreadEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockSpreadEvent "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.
```csharp
[EventHandler]
public void onSpread(BlockSpreadEvent e)
{
// prevent fire from spreading
if (e.getSource().getType() == Material.FIRE)
{
e.setCancelled(true);
}
}
```
```csharp
[EventHandler]
public void onSpread(BlockSpreadEvent e)
{
// prevent grass from spreading
if (e.getBlock().getType() == Material.GRASS)
{
e.setCancelled(true);
}
}
```
| 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)
---
@subsection blockburnevent BlockBurnEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockBurnEvent "BlockBurnEvent" is fired when a block is destroyed as a result of being burnt by fire.
```csharp
[EventHandler]
public void onBurn(BlockBurnEvent e)
{
// prevent wooden planks from burning
if (e.getBlock().getType() == Material.WOOD)
{
e.setCancelled(true);
}
}
```
```csharp
[EventHandler]
public void onBurn(BlockBurnEvent e)
{
// prevent all fire destruction
e.setCancelled(true);
}
```
| Method | Description |
|--------|-------------|
| `getBlock()` | The `Block` that is being burnt. |
| `isCancelled()` | Whether the burn is cancelled. |
| `setCancelled(bool)` | Cancel or allow the burn. |
> **Cancellable:** Yes
---
@subsection blockfromtoevent BlockFromToEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockFromToEvent "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.
```csharp
[EventHandler]
public void onFromTo(BlockFromToEvent e)
{
// prevent water from flowing
if (e.getBlock().getType() == Material.WATER || e.getBlock().getType() == Material.STATIONARY_WATER)
{
e.setCancelled(true);
}
}
```
```csharp
[EventHandler]
public void onFromTo(BlockFromToEvent e)
{
// log liquid flow
var from = e.getBlock();
var to = e.getToBlock();
Console.WriteLine($"Block moving from {from.getX()},{from.getY()},{from.getZ()} to {to.getX()},{to.getY()},{to.getZ()}");
}
```
| 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
---
@subsection blockpistonextendevent BlockPistonExtendEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockPistonExtendEvent "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.
```csharp
[EventHandler]
public void onPiston(BlockPistonExtendEvent e)
{
// prevent sticky pistons from extending
if (e.isSticky())
{
e.setCancelled(true);
}
}
```
```csharp
[EventHandler]
public void onPiston(BlockPistonExtendEvent e)
{
// log piston activity
Console.WriteLine($"Piston extending {e.getDirection()} pushing {e.getLength()} blocks");
}
```
| 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
---
@subsection blockpistonretractevent BlockPistonRetractEvent
\ref Minecraft.Server.FourKit.Event.Block.BlockPistonRetractEvent "BlockPistonRetractEvent" extends `BlockPistonEvent` and is fired when a piston retracts. For sticky pistons, the retract location indicates where the block being pulled is located.
```csharp
[EventHandler]
public void onPiston(BlockPistonRetractEvent e)
{
// prevent all sticky piston retractions
if (e.isSticky())
{
e.setCancelled(true);
}
}
```
```csharp
[EventHandler]
public void onPiston(BlockPistonRetractEvent e)
{
// log where the retract is pulling from
var loc = e.getRetractLocation();
Console.WriteLine($"Piston retracting, pull location: {loc.getBlockX()}, {loc.getBlockY()}, {loc.getBlockZ()}");
}
```
| 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
---
@section inventory_events Inventory Events
@subsection inventoryopenevent InventoryOpenEvent