feat: add FourKit plugin host with dual server build
Adds the FourKit .NET 10 plugin host as a second dedicated server
build flavour alongside the existing vanilla server. Both flavours
build from the same source tree, with FourKit gated by the
MINECRAFT_SERVER_FOURKIT_BUILD preprocessor define.
Build layout:
Minecraft.Server vanilla, no plugin support, no .NET dep
Minecraft.Server.FourKit FourKit-enabled, ships with bundled
.NET 10 self-contained runtime in runtime/
and an empty plugins/ folder
Both produce a Minecraft.Server.exe in their own per-target output
dir. The variant identity lives in the directory name, not the
binary name, so either flavour can be shipped as a drop-in.
Native bridge (Minecraft.Server/FourKit*.{cpp,h}):
* FourKitRuntime: hosts CoreCLR via hostfxr's command-line init API
(the runtime-config API does not support self-contained components)
* FourKitBridge: ~50 Fire* event entry points, with inline no-op
stubs for the standalone build so gameplay code can call them
unconditionally
* FourKitNatives: ~80 native callbacks the managed side invokes
for player/world/inventory mutations
* FourKitMappers: type and enum mapping helpers
Managed plugin host (Minecraft.Server.FourKit/):
* Bukkit-style API: Player, World, Block, Inventory, Command,
Listener, EventHandler attribute, ~54 event classes
* PluginLoader with per-plugin AssemblyLoadContext
* FourKitHost as the [UnmanagedCallersOnly] entry point table
* Runtime resolves plugins relative to the host process so they
always live next to Minecraft.Server.exe regardless of where the
managed assembly itself is loaded from
Engine hooks (Minecraft.Client/, Minecraft.World/):
* Player lifecycle (PreLogin, Login, Join, Quit, Kick, Move,
Teleport, Portal, Death) wired into PendingConnection and
PlayerConnection without disturbing the cipher handshake or
identity-token security flow
* Inventory open/click/drop hooks across every container menu type
* Block place/break/grow/burn/spread/from-to hooks across the
full tile family
* Bed enter/leave, sign change, entity damage/death, ender pearl
teleport hooks
Regression fixes preserved while applying donor diffs:
* ServerPlayer::die() retains the LCE-Revelations hardcore branch
(setGameMode(ADVENTURE) + banPlayerForHardcoreDeath) in both the
FourKit and non-FourKit code paths
* ServerLevel::entityAdded() retains the sub-entity ID reassignment
loop required by the client's handleAddMob offset, fixing Ender
Dragon and Wither boss multi-part hit detection
* LivingEntity::travel() retains the raw Player* cast and the
cached frictionTile, both Revelations perf wins that the donor
silently reverted
* ServerLogger.cpp keeps the file-logging code donor stripped
* PlayerList.cpp end portal transition fix and UIScene_EndPoem
bounds-check are intact
Build system:
* Top-level CMakeLists.txt adds the Minecraft.Server.FourKit
subdirectory and pulls in the new shared cmake/ServerTarget.cmake
helper
* Minecraft.Server/cmake/sources/Common.cmake is now location
independent (uses CMAKE_CURRENT_LIST_DIR) so the source list
can be consumed from either server target's CMakeLists.txt
* The seven FourKit*.cpp/h files live in their own
_MINECRAFT_SERVER_COMMON_SERVER_FOURKIT variable so the
standalone target omits them
* configure-time .NET 10 SDK check fails fast with a clear
download link if the SDK is missing
* global.json pins the SDK to 10.0.100 with latestFeature
rollforward
Sample plugin (samples/HelloPlugin/) demonstrates the loader and
the PlayerJoinEvent listener pattern.
CI:
* nightly.yml builds both server flavours, ships
LCE-Revelations-Server-Win64.zip and
LCE-Revelations-Server-Win64-FourKit.zip, attests both, and
updates release notes for the dual-flavour layout
* pull-request.yml pulls in actions/setup-dotnet so the FourKit
publish step works in PR validation
* All zip artifacts and the client zip are renamed from
LCREWindows64 to LCE-Revelations-{Client,Server}-Win64
Documentation:
* COMPILE.md gets a VS 2022 quick start, .NET 10 prereq section,
server flavours explanation, and a troubleshooting section
* docs/FOURKIT_PORT_RECON.md captures the file-by-file recon that
drove the port
* docs/FOURKIT_PARITY.md is the canonical reference for which
events FourKit fires
Docker:
* docker-compose.dedicated-server.yml MC_RUNTIME_DIR default points
at the vanilla CMake output. The FourKit Docker image is
intentionally NOT shipped yet because hosting .NET 10 self
contained inside Wine has not been smoke-tested
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block is broken by a player.
|
||||
///
|
||||
/// If you wish to have the block drop experience, you must set the experience
|
||||
/// value above 0. By default, experience will be set in the event if:
|
||||
/// <list type="bullet">
|
||||
/// <item><description>The player is not in creative or adventure mode</description></item>
|
||||
/// <item><description>The player can loot the block (ie: does not destroy it completely, by using the correct tool)</description></item>
|
||||
/// <item><description>The player does not have silk touch</description></item>
|
||||
/// <item><description>The block drops experience in vanilla Minecraft</description></item>
|
||||
/// </list>
|
||||
///
|
||||
/// Note: Plugins wanting to simulate a traditional block drop should set the
|
||||
/// block to air and utilize their own methods for determining what the default
|
||||
/// drop for the block being broken is and what to do about it, if anything.
|
||||
///
|
||||
/// If a Block Break event is cancelled, the block will not break and experience
|
||||
/// will not drop.
|
||||
/// </summary>
|
||||
public class BlockBreakEvent : BlockExpEvent, Cancellable
|
||||
{
|
||||
private readonly Player _player;
|
||||
private bool _cancel;
|
||||
internal BlockBreakEvent(Block block, Player player, int exp)
|
||||
: base(block, exp)
|
||||
{
|
||||
_player = player;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Player that is breaking the block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The Player that is breaking the block involved in this event.</returns>
|
||||
public Player getPlayer() => _player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block is destroyed as a result of being burnt by fire.
|
||||
///
|
||||
/// <para>If a Block Burn event is cancelled, the block will not be destroyed
|
||||
/// as a result of being burnt by fire.</para>
|
||||
/// </summary>
|
||||
public class BlockBurnEvent : BlockEvent, Cancellable
|
||||
{
|
||||
private bool _cancel;
|
||||
|
||||
internal BlockBurnEvent(Block block) : base(block)
|
||||
{
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Block-related event.
|
||||
/// </summary>
|
||||
public abstract class BlockEvent : Event
|
||||
{
|
||||
private readonly Block _block;
|
||||
|
||||
internal protected BlockEvent(Block block)
|
||||
{
|
||||
_block = block;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The Block which is involved in this event.</returns>
|
||||
public Block getBlock() => _block;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// An event that is called when a block yields experience.
|
||||
/// </summary>
|
||||
public class BlockExpEvent : BlockEvent
|
||||
{
|
||||
private int _exp;
|
||||
internal BlockExpEvent(Block block, int exp)
|
||||
: base(block)
|
||||
{
|
||||
_exp = exp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the experience dropped by the block after the event has processed.
|
||||
/// </summary>
|
||||
/// <returns>The experience to drop.</returns>
|
||||
public int getExpToDrop() => _exp;
|
||||
|
||||
/// <summary>
|
||||
/// Set the amount of experience dropped by the block after the event has processed.
|
||||
/// </summary>
|
||||
/// <param name="exp">1 or higher to drop experience, else nothing will drop.</param>
|
||||
public void setExpToDrop(int exp)
|
||||
{
|
||||
_exp = exp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block is formed or spreads based on world conditions.
|
||||
/// Use <see cref="BlockSpreadEvent"/> to catch blocks that actually spread
|
||||
/// and don't just "randomly" form.
|
||||
///
|
||||
/// <para>Examples:</para>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>Snow forming due to a snow storm.</description></item>
|
||||
/// <item><description>Ice forming in a snowy Biome like Taiga or Tundra.</description></item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>If a Block Form event is cancelled, the block will not be formed.</para>
|
||||
/// </summary>
|
||||
public class BlockFormEvent : BlockGrowEvent, Cancellable
|
||||
{
|
||||
internal BlockFormEvent(Block block, BlockState newState) : base(block, newState)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Represents events with a source block and a destination block, currently
|
||||
/// only applies to liquid (lava and water) and teleporting dragon eggs.
|
||||
///
|
||||
/// <para>If a Block From To event is cancelled, the block will not move
|
||||
/// (the liquid will not flow).</para>
|
||||
/// </summary>
|
||||
public class BlockFromToEvent : BlockEvent, Cancellable
|
||||
{
|
||||
private readonly Block _to;
|
||||
private readonly BlockFace _face;
|
||||
private bool _cancel;
|
||||
|
||||
internal BlockFromToEvent(Block block, BlockFace face) : base(block)
|
||||
{
|
||||
_face = face;
|
||||
_to = block.getRelative(face);
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
internal BlockFromToEvent(Block block, Block toBlock) : base(block)
|
||||
{
|
||||
_to = toBlock;
|
||||
_face = BlockFace.SELF;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
internal BlockFromToEvent(Block block, Block toBlock, BlockFace face) : base(block)
|
||||
{
|
||||
_to = toBlock;
|
||||
_face = face;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the BlockFace that the block is moving to.
|
||||
/// </summary>
|
||||
/// <returns>The BlockFace that the block is moving to.</returns>
|
||||
public BlockFace getFace() => _face;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience method for getting the faced Block.
|
||||
/// </summary>
|
||||
/// <returns>The faced Block.</returns>
|
||||
public Block getToBlock() => _to;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block grows naturally in the world.
|
||||
///
|
||||
/// <para>Examples:</para>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>Wheat</description></item>
|
||||
/// <item><description>Sugar Cane</description></item>
|
||||
/// <item><description>Cactus</description></item>
|
||||
/// <item><description>Watermelon</description></item>
|
||||
/// <item><description>Pumpkin</description></item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>If a Block Grow event is cancelled, the block will not grow.</para>
|
||||
/// </summary>
|
||||
public class BlockGrowEvent : BlockEvent, Cancellable
|
||||
{
|
||||
private bool _cancel;
|
||||
private readonly BlockState _newState;
|
||||
|
||||
internal BlockGrowEvent(Block block, BlockState newState) : base(block)
|
||||
{
|
||||
_cancel = false;
|
||||
_newState = newState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the state of the block where it will form or spread to.
|
||||
/// </summary>
|
||||
/// <returns>The block state for this events block.</returns>
|
||||
public BlockState getNewState() => _newState;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a piston block is triggered.
|
||||
/// </summary>
|
||||
public abstract class BlockPistonEvent : BlockEvent, Cancellable
|
||||
{
|
||||
private bool _cancel;
|
||||
private readonly BlockFace _direction;
|
||||
|
||||
internal protected BlockPistonEvent(Block block, BlockFace direction) : base(block)
|
||||
{
|
||||
_direction = direction;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancelled)
|
||||
{
|
||||
_cancel = cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Piston in the event is sticky.
|
||||
/// </summary>
|
||||
/// <returns>Stickiness of the piston.</returns>
|
||||
public bool isSticky()
|
||||
{
|
||||
var type = getBlock().getType();
|
||||
return type == Material.PISTON_STICKY_BASE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the direction in which the piston will operate.
|
||||
/// </summary>
|
||||
/// <returns>Direction of the piston.</returns>
|
||||
public BlockFace getDirection() => _direction;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a piston extends.
|
||||
/// </summary>
|
||||
public class BlockPistonExtendEvent : BlockPistonEvent
|
||||
{
|
||||
private readonly int _length;
|
||||
|
||||
internal BlockPistonExtendEvent(Block block, int length, BlockFace direction)
|
||||
: base(block, direction)
|
||||
{
|
||||
_length = length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the amount of blocks which will be moved while extending.
|
||||
/// </summary>
|
||||
/// <returns>The amount of moving blocks.</returns>
|
||||
public int getLength() => _length;
|
||||
|
||||
/// <summary>
|
||||
/// Get an immutable list of the blocks which will be moved by the extending.
|
||||
/// </summary>
|
||||
/// <returns>Immutable list of the moved blocks.</returns>
|
||||
public List<Block> getBlocks()
|
||||
{
|
||||
var blocks = new List<Block>();
|
||||
var world = getBlock().getWorld();
|
||||
int x = getBlock().getX();
|
||||
int y = getBlock().getY();
|
||||
int z = getBlock().getZ();
|
||||
var dir = getDirection();
|
||||
|
||||
for (int i = 0; i < _length; i++)
|
||||
{
|
||||
x += dir.getModX();
|
||||
y += dir.getModY();
|
||||
z += dir.getModZ();
|
||||
blocks.Add(new Block(world, x, y, z));
|
||||
}
|
||||
return blocks.AsReadOnly().ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a piston retracts.
|
||||
/// </summary>
|
||||
public class BlockPistonRetractEvent : BlockPistonEvent
|
||||
{
|
||||
internal BlockPistonRetractEvent(Block block, BlockFace direction)
|
||||
: base(block, direction)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location where the possible moving block might be if the
|
||||
/// retracting piston is sticky.
|
||||
/// </summary>
|
||||
/// <returns>The possible location of the possibly moving block.</returns>
|
||||
public Location getRetractLocation()
|
||||
{
|
||||
var block = getBlock();
|
||||
var dir = getDirection();
|
||||
return new Location(
|
||||
block.getWorld(),
|
||||
block.getX() + dir.getModX() * 2,
|
||||
block.getY() + dir.getModY() * 2,
|
||||
block.getZ() + dir.getModZ() * 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block is placed by a player.
|
||||
/// </summary>
|
||||
public class BlockPlaceEvent : BlockEvent, Cancellable
|
||||
{
|
||||
protected Block placedAgainst;
|
||||
protected ItemStack itemInHand;
|
||||
protected Player player;
|
||||
protected bool canBuild;
|
||||
protected bool cancel;
|
||||
|
||||
internal BlockPlaceEvent(Block placedBlock, Block placedAgainst, ItemStack itemInHand, Player thePlayer, bool canBuild)
|
||||
: base(placedBlock)
|
||||
{
|
||||
this.placedAgainst = placedAgainst;
|
||||
this.itemInHand = itemInHand;
|
||||
this.player = thePlayer;
|
||||
this.canBuild = canBuild;
|
||||
this.cancel = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who placed the block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The Player who placed the block involved in this event.</returns>
|
||||
public Player getPlayer() => player;
|
||||
|
||||
/// <summary>
|
||||
/// Clarity method for getting the placed block. Not really needed except
|
||||
/// for reasons of clarity.
|
||||
/// </summary>
|
||||
/// <returns>The Block that was placed.</returns>
|
||||
public Block getBlockPlaced() => getBlock();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the block that this block was placed against.
|
||||
/// </summary>
|
||||
/// <returns>Block the block that the new block was placed against.</returns>
|
||||
public Block getBlockAgainst() => placedAgainst;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the item in the player's hand when they placed the block.
|
||||
/// </summary>
|
||||
/// <returns>The ItemStack for the item in the player's hand when they placed the block.</returns>
|
||||
public ItemStack getItemInHand() => itemInHand;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => cancel;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel) => this.cancel = cancel;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a block spreads based on world conditions.
|
||||
/// Use <see cref="BlockFormEvent"/> to catch blocks that "randomly" form
|
||||
/// instead of actually spread.
|
||||
///
|
||||
/// <para>Examples:</para>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>Mushrooms spreading.</description></item>
|
||||
/// <item><description>Fire spreading.</description></item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>If a Block Spread event is cancelled, the block will not spread.</para>
|
||||
/// </summary>
|
||||
public class BlockSpreadEvent : BlockFormEvent, Cancellable
|
||||
{
|
||||
private readonly Block _source;
|
||||
|
||||
internal BlockSpreadEvent(Block block, Block source, BlockState newState) : base(block, newState)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The Block for the source block involved in this event.</returns>
|
||||
public Block getSource() => _source;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Block;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a sign is changed by a player.
|
||||
/// </summary>
|
||||
public class SignChangeEvent : BlockEvent, Cancellable
|
||||
{
|
||||
private readonly Player _player;
|
||||
private readonly string[] _lines;
|
||||
private bool _cancel;
|
||||
internal SignChangeEvent(Block theBlock, Player thePlayer, string[] theLines)
|
||||
: base(theBlock)
|
||||
{
|
||||
_player = thePlayer;
|
||||
_lines = theLines;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player changing the sign involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The Player involved in this event.</returns>
|
||||
public Player getPlayer() => _player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the lines of text from the sign involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>The String array for the sign's lines new text.</returns>
|
||||
public string[] getLines() => _lines;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single line of text from the sign involved in this event.
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the line to get.</param>
|
||||
/// <returns>The String containing the line of text associated with the provided index.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">Thrown when the provided index is > 3 or < 0.</exception>
|
||||
public string getLine(int index)
|
||||
{
|
||||
if (index < 0 || index > 3)
|
||||
throw new IndexOutOfRangeException($"Line index must be between 0 and 3, got {index}");
|
||||
return _lines[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a single line for the sign involved in this event.
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the line to set.</param>
|
||||
/// <param name="line">Text to set.</param>
|
||||
/// <exception cref="IndexOutOfRangeException">Thrown when the provided index is > 3 or < 0.</exception>
|
||||
public void setLine(int index, string line)
|
||||
{
|
||||
if (index < 0 || index > 3)
|
||||
throw new IndexOutOfRangeException($"Line index must be between 0 and 3, got {index}");
|
||||
_lines[index] = line;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel) => _cancel = cancel;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Minecraft.Server.FourKit.Event;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for events that can be cancelled by a plugin.
|
||||
/// When cancelled, the server will skip the default action.
|
||||
/// </summary>
|
||||
public interface Cancellable
|
||||
{
|
||||
/// <summary>Gets whether this event is cancelled.</summary>
|
||||
bool isCancelled();
|
||||
|
||||
/// <summary>Sets whether this event is cancelled.</summary>
|
||||
void setCancelled(bool cancel);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Entity;
|
||||
|
||||
using FourKitEntity = Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called when an entity is damaged by an entity.
|
||||
/// </summary>
|
||||
public class EntityDamageByEntityEvent : EntityDamageEvent
|
||||
{
|
||||
private readonly FourKitEntity.Entity _damager;
|
||||
internal EntityDamageByEntityEvent(FourKitEntity.Entity damager, FourKitEntity.Entity damagee, EntityDamageEvent.DamageCause cause, double damage)
|
||||
: base(damagee, cause, damage)
|
||||
{
|
||||
_damager = damager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entity that damaged the defender.
|
||||
/// </summary>
|
||||
/// <returns>The Entity that damaged the defender.</returns>
|
||||
public FourKitEntity.Entity getDamager() => _damager;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Entity;
|
||||
|
||||
using FourKitEntity = Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Stores data for damage events.
|
||||
/// </summary>
|
||||
public class EntityDamageEvent : EntityEvent, Cancellable
|
||||
{
|
||||
/// <summary>
|
||||
/// An enum to specify the cause of the damage.
|
||||
/// </summary>
|
||||
public enum DamageCause
|
||||
{
|
||||
/// <summary>Damage caused by being in the area when a block explodes.</summary>
|
||||
BLOCK_EXPLOSION,
|
||||
/// <summary>Damage caused when an entity contacts a block such as a Cactus.</summary>
|
||||
CONTACT,
|
||||
/// <summary>Custom damage.</summary>
|
||||
CUSTOM,
|
||||
/// <summary>Damage caused by running out of air while in water.</summary>
|
||||
DROWNING,
|
||||
/// <summary>Damage caused when an entity attacks another entity.</summary>
|
||||
ENTITY_ATTACK,
|
||||
/// <summary>Damage caused by being in the area when an entity, such as a Creeper, explodes.</summary>
|
||||
ENTITY_EXPLOSION,
|
||||
/// <summary>Damage caused when an entity falls a distance greater than 3 blocks.</summary>
|
||||
FALL,
|
||||
/// <summary>Damage caused by being hit by a falling block which deals damage.</summary>
|
||||
FALLING_BLOCK,
|
||||
/// <summary>Damage caused by direct exposure to fire.</summary>
|
||||
FIRE,
|
||||
/// <summary>Damage caused due to burns caused by fire.</summary>
|
||||
FIRE_TICK,
|
||||
/// <summary>Damage caused by direct exposure to lava.</summary>
|
||||
LAVA,
|
||||
/// <summary>Damage caused by being struck by lightning.</summary>
|
||||
LIGHTNING,
|
||||
/// <summary>Damage caused by being hit by a damage potion or spell.</summary>
|
||||
MAGIC,
|
||||
/// <summary>Damage caused due to a snowman melting.</summary>
|
||||
MELTING,
|
||||
/// <summary>Damage caused due to an ongoing poison effect.</summary>
|
||||
POISON,
|
||||
/// <summary>Damage caused when attacked by a projectile.</summary>
|
||||
PROJECTILE,
|
||||
/// <summary>Damage caused by starving due to having an empty hunger bar.</summary>
|
||||
STARVATION,
|
||||
/// <summary>Damage caused by being put in a block.</summary>
|
||||
SUFFOCATION,
|
||||
/// <summary>Damage caused by committing suicide using the command "/kill".</summary>
|
||||
SUICIDE,
|
||||
/// <summary>Damage caused in retaliation to another attack by the Thorns enchantment.</summary>
|
||||
THORNS,
|
||||
/// <summary>Damage caused by falling into the void.</summary>
|
||||
VOID,
|
||||
/// <summary>Damage caused by Wither potion effect.</summary>
|
||||
WITHER,
|
||||
}
|
||||
|
||||
private readonly DamageCause _cause;
|
||||
private double _damage;
|
||||
private readonly double _finalDamage;
|
||||
private bool _cancel;
|
||||
internal EntityDamageEvent(FourKitEntity.Entity damagee, DamageCause cause, double damage)
|
||||
: base(damagee)
|
||||
{
|
||||
_cause = cause;
|
||||
_damage = damage;
|
||||
_finalDamage = damage;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cause of the damage.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="DamageCause"/> value detailing the cause of the damage.</returns>
|
||||
public DamageCause getCause() => _cause;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw amount of damage caused by the event.
|
||||
/// </summary>
|
||||
/// <returns>The raw amount of damage.</returns>
|
||||
public double getDamage() => _damage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of damage caused by the event after all damage
|
||||
/// reduction is applied.
|
||||
/// </summary>
|
||||
/// <returns>The amount of damage after reduction.</returns>
|
||||
public double getFinalDamage() => _finalDamage;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the raw amount of damage caused by the event.
|
||||
/// </summary>
|
||||
/// <param name="damage">The raw amount of damage.</param>
|
||||
public void setDamage(double damage)
|
||||
{
|
||||
_damage = damage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Entity;
|
||||
|
||||
using FourKitEntity = Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Thrown whenever a LivingEntity dies.
|
||||
/// </summary>
|
||||
public class EntityDeathEvent : EntityEvent
|
||||
{
|
||||
private readonly List<ItemStack> _drops;
|
||||
private int _droppedExp;
|
||||
|
||||
internal EntityDeathEvent(FourKitEntity.LivingEntity entity, List<ItemStack> drops)
|
||||
: this(entity, drops, 0)
|
||||
{
|
||||
}
|
||||
|
||||
internal EntityDeathEvent(FourKitEntity.LivingEntity what, List<ItemStack> drops, int droppedExp)
|
||||
: base(what)
|
||||
{
|
||||
_drops = drops;
|
||||
_droppedExp = droppedExp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Entity involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>Entity who is involved in this event.</returns>
|
||||
public new FourKitEntity.LivingEntity getEntity() => (FourKitEntity.LivingEntity)entity;
|
||||
|
||||
/// <summary>
|
||||
/// Gets how much EXP should be dropped from this death.
|
||||
/// This does not indicate how much EXP should be taken from the entity
|
||||
/// in question, merely how much should be created after its death.
|
||||
/// </summary>
|
||||
/// <returns>Amount of EXP to drop.</returns>
|
||||
public int getDroppedExp() => _droppedExp;
|
||||
|
||||
/// <summary>
|
||||
/// Sets how much EXP should be dropped from this death.
|
||||
/// This does not indicate how much EXP should be taken from the entity
|
||||
/// in question, merely how much should be created after its death.
|
||||
/// </summary>
|
||||
/// <param name="exp">Amount of EXP to drop.</param>
|
||||
public void setDroppedExp(int exp) => _droppedExp = exp;
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the items which will drop when the entity dies.
|
||||
/// </summary>
|
||||
/// <returns>Items to drop when the entity dies.</returns>
|
||||
public List<ItemStack> getDrops() => _drops;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Entity;
|
||||
|
||||
using FourKitEntity = Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an Entity-related event.
|
||||
/// </summary>
|
||||
public abstract class EntityEvent : Event
|
||||
{
|
||||
protected FourKitEntity.Entity entity;
|
||||
|
||||
protected EntityEvent(FourKitEntity.Entity what)
|
||||
{
|
||||
entity = what;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Entity involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>Entity who is involved in this event.</returns>
|
||||
public FourKitEntity.Entity getEntity() => entity;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the EntityType of the Entity involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>EntityType of the Entity involved in this event.</returns>
|
||||
public FourKitEntity.EntityType getEntityType() => entity.getType();
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Entity;
|
||||
|
||||
using FourKitEntity = Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Thrown whenever a Player dies.
|
||||
/// </summary>
|
||||
public class PlayerDeathEvent : EntityDeathEvent
|
||||
{
|
||||
private string _deathMessage;
|
||||
private int _newExp;
|
||||
private int _newLevel;
|
||||
private bool _keepLevel;
|
||||
private bool _keepInventory;
|
||||
internal PlayerDeathEvent(FourKitEntity.Player player, List<ItemStack> drops, int droppedExp, string deathMessage)
|
||||
: this(player, drops, droppedExp, 0, deathMessage)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PlayerDeathEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="player">The Player who died.</param>
|
||||
/// <param name="drops">The items to drop when the player dies.</param>
|
||||
/// <param name="droppedExp">The amount of experience to drop.</param>
|
||||
/// <param name="newExp">The new EXP the Player should have at respawn.</param>
|
||||
/// <param name="deathMessage">The death message to display.</param>
|
||||
public PlayerDeathEvent(FourKitEntity.Player player, List<ItemStack> drops, int droppedExp, int newExp, string deathMessage)
|
||||
: base(player, drops, droppedExp)
|
||||
{
|
||||
_deathMessage = deathMessage;
|
||||
_newExp = newExp;
|
||||
_newLevel = 0;
|
||||
_keepLevel = false;
|
||||
_keepInventory = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Entity involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>Entity who is involved in this event.</returns>
|
||||
public new FourKitEntity.Player getEntity() => (FourKitEntity.Player)entity;
|
||||
|
||||
/// <summary>
|
||||
/// Get the death message that will appear to everyone on the server.
|
||||
/// </summary>
|
||||
/// <returns>Message to appear to other players on the server.</returns>
|
||||
public string getDeathMessage() => _deathMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Set the death message that will appear to everyone on the server.
|
||||
/// </summary>
|
||||
/// <param name="deathMessage">Message to appear to other players on the server.</param>
|
||||
public void setDeathMessage(string deathMessage) => _deathMessage = deathMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets how much EXP the Player should have at respawn.
|
||||
/// This does not indicate how much EXP should be dropped, please see
|
||||
/// <see cref="EntityDeathEvent.getDroppedExp"/> for that.
|
||||
/// </summary>
|
||||
/// <returns>New EXP of the respawned player.</returns>
|
||||
public int getNewExp() => _newExp;
|
||||
|
||||
/// <summary>
|
||||
/// Sets how much EXP the Player should have at respawn.
|
||||
/// This does not indicate how much EXP should be dropped, please see
|
||||
/// <see cref="EntityDeathEvent.setDroppedExp"/> for that.
|
||||
/// </summary>
|
||||
/// <param name="exp">New EXP of the respawned player.</param>
|
||||
public void setNewExp(int exp) => _newExp = exp;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Level the Player should have at respawn.
|
||||
/// </summary>
|
||||
/// <returns>New Level of the respawned player.</returns>
|
||||
public int getNewLevel() => _newLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Level the Player should have at respawn.
|
||||
/// </summary>
|
||||
/// <param name="level">New Level of the respawned player.</param>
|
||||
public void setNewLevel(int level) => _newLevel = level;
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the Player should keep all EXP at respawn.
|
||||
/// This flag overrides other EXP settings.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if Player should keep all pre-death exp.</returns>
|
||||
public bool getKeepLevel() => _keepLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Sets if the Player should keep all EXP at respawn.
|
||||
/// This overrides all other EXP settings.
|
||||
/// </summary>
|
||||
/// <param name="keepLevel"><c>true</c> to keep all current value levels.</param>
|
||||
public void setKeepLevel(bool keepLevel) => _keepLevel = keepLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the Player keeps inventory on death.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the player keeps inventory on death.</returns>
|
||||
public bool getKeepInventory() => _keepInventory;
|
||||
|
||||
/// <summary>
|
||||
/// Sets if the Player keeps inventory on death.
|
||||
/// </summary>
|
||||
/// <param name="keepInventory"><c>true</c> to keep the inventory.</param>
|
||||
public void setKeepInventory(bool keepInventory) => _keepInventory = keepInventory;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Minecraft.Server.FourKit.Event;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all events dispatched by the server.
|
||||
/// </summary>
|
||||
public abstract class Event
|
||||
{
|
||||
/// <summary>Gets the name of this event (defaults to the class name).</summary>
|
||||
public virtual string getEventName() => GetType().Name;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Minecraft.Server.FourKit.Event;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a method inside a <see cref="Listener"/> as an event handler.
|
||||
/// This class is not named "EventHandler" due to a naming conflict with the existing System.EventHandler
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class EventHandlerAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Priority of this handler. Lower values run first.
|
||||
/// Default is <see cref="EventPriority.Normal"/>.
|
||||
/// </summary>
|
||||
public EventPriority Priority { get; set; } = EventPriority.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this handler should be skipped when the event is already
|
||||
/// cancelled by a lower-priority handler. Default is <c>false</c>.
|
||||
/// </summary>
|
||||
public bool IgnoreCancelled { get; set; } = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execution priority for event handlers.
|
||||
/// </summary>
|
||||
public enum EventPriority
|
||||
{
|
||||
/// <summary>Event call is of very low importance and should be ran first, to allow other plugins to further customise the outcome</summary>
|
||||
Lowest = 0,
|
||||
/// <summary>Event call is of low importance</summary>
|
||||
Low = 1,
|
||||
/// <summary>Event call is neither important nor unimportant, and may be ran normally</summary>
|
||||
Normal = 2,
|
||||
/// <summary>Event call is of high importance</summary>
|
||||
High = 3,
|
||||
/// <summary>Event call is critical and must have the final say in what happens to the event</summary>
|
||||
Highest = 4,
|
||||
/// <summary>Event is listened to purely for monitoring the outcome of an event. Should not modify the event.</summary>
|
||||
Monitor = 5
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// What the client did to trigger this action (not the result).
|
||||
/// </summary>
|
||||
public enum ClickType
|
||||
{
|
||||
/// <summary>The left (or primary) mouse button.</summary>
|
||||
LEFT,
|
||||
/// <summary>Holding shift while pressing the left mouse button.</summary>
|
||||
SHIFT_LEFT,
|
||||
/// <summary>The right mouse button.</summary>
|
||||
RIGHT,
|
||||
/// <summary>Holding shift while pressing the right mouse button.</summary>
|
||||
SHIFT_RIGHT,
|
||||
/// <summary>Clicking the left mouse button on the grey area around the inventory.</summary>
|
||||
WINDOW_BORDER_LEFT,
|
||||
/// <summary>Clicking the right mouse button on the grey area around the inventory.</summary>
|
||||
WINDOW_BORDER_RIGHT,
|
||||
/// <summary>The middle mouse button, or a "scrollwheel click".</summary>
|
||||
MIDDLE,
|
||||
/// <summary>One of the number keys 1-9, correspond to slots on the hotbar.</summary>
|
||||
NUMBER_KEY,
|
||||
/// <summary>Pressing the left mouse button twice in quick succession.</summary>
|
||||
DOUBLE_CLICK,
|
||||
/// <summary>The "Drop" key (defaults to Q).</summary>
|
||||
DROP,
|
||||
/// <summary>Holding Ctrl while pressing the "Drop" key (defaults to Q).</summary>
|
||||
CONTROL_DROP,
|
||||
/// <summary>Any action done with the Creative inventory open.</summary>
|
||||
CREATIVE,
|
||||
/// <summary>A type of inventory manipulation not yet recognized by Bukkit.</summary>
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ClickType"/>.
|
||||
/// </summary>
|
||||
public static class ClickTypeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether this ClickType represents the pressing of a key on a keyboard.
|
||||
/// </summary>
|
||||
/// <param name="click">The click type.</param>
|
||||
/// <returns>true if this ClickType represents the pressing of a key.</returns>
|
||||
public static bool isKeyboardClick(this ClickType click)
|
||||
{
|
||||
return click == ClickType.NUMBER_KEY || click == ClickType.DROP || click == ClickType.CONTROL_DROP;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this ClickType represents an action that can only be performed
|
||||
/// by a Player in creative mode.
|
||||
/// </summary>
|
||||
/// <param name="click">The click type.</param>
|
||||
/// <returns>true if this action requires Creative mode.</returns>
|
||||
public static bool isCreativeAction(this ClickType click)
|
||||
{
|
||||
return click == ClickType.CREATIVE || click == ClickType.MIDDLE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this ClickType represents a right click.
|
||||
/// </summary>
|
||||
/// <param name="click">The click type.</param>
|
||||
/// <returns>true if this ClickType represents a right click.</returns>
|
||||
public static bool isRightClick(this ClickType click)
|
||||
{
|
||||
return click == ClickType.RIGHT || click == ClickType.SHIFT_RIGHT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this ClickType represents a left click.
|
||||
/// </summary>
|
||||
/// <param name="click">The click type.</param>
|
||||
/// <returns>true if this ClickType represents a left click.</returns>
|
||||
public static bool isLeftClick(this ClickType click)
|
||||
{
|
||||
return click == ClickType.LEFT || click == ClickType.SHIFT_LEFT
|
||||
|| click == ClickType.DOUBLE_CLICK || click == ClickType.CREATIVE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this ClickType indicates that the shift key was pressed
|
||||
/// down when the click was made.
|
||||
/// </summary>
|
||||
/// <param name="click">The click type.</param>
|
||||
/// <returns>true if the action uses Shift.</returns>
|
||||
public static bool isShiftClick(this ClickType click)
|
||||
{
|
||||
return click == ClickType.SHIFT_LEFT || click == ClickType.SHIFT_RIGHT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// An estimation of what the result will be.
|
||||
/// </summary>
|
||||
public enum InventoryAction
|
||||
{
|
||||
/// <summary>Nothing will happen from the click.</summary>
|
||||
NOTHING,
|
||||
/// <summary>All of the items on the clicked slot are moved to the cursor.</summary>
|
||||
PICKUP_ALL,
|
||||
/// <summary>Some of the items on the clicked slot are moved to the cursor.</summary>
|
||||
PICKUP_SOME,
|
||||
/// <summary>Half of the items on the clicked slot are moved to the cursor.</summary>
|
||||
PICKUP_HALF,
|
||||
/// <summary>One of the items on the clicked slot are moved to the cursor.</summary>
|
||||
PICKUP_ONE,
|
||||
/// <summary>All of the items on the cursor are moved to the clicked slot.</summary>
|
||||
PLACE_ALL,
|
||||
/// <summary>Some of the items from the cursor are moved to the clicked slot (usually up to the max stack size).</summary>
|
||||
PLACE_SOME,
|
||||
/// <summary>A single item from the cursor is moved to the clicked slot.</summary>
|
||||
PLACE_ONE,
|
||||
/// <summary>The clicked item and the cursor are exchanged.</summary>
|
||||
SWAP_WITH_CURSOR,
|
||||
/// <summary>The entire cursor item is dropped.</summary>
|
||||
DROP_ALL_CURSOR,
|
||||
/// <summary>One item is dropped from the cursor.</summary>
|
||||
DROP_ONE_CURSOR,
|
||||
/// <summary>The entire clicked slot is dropped.</summary>
|
||||
DROP_ALL_SLOT,
|
||||
/// <summary>One item is dropped from the clicked slot.</summary>
|
||||
DROP_ONE_SLOT,
|
||||
/// <summary>The item is moved to the opposite inventory if a space is found.</summary>
|
||||
MOVE_TO_OTHER_INVENTORY,
|
||||
/// <summary>The clicked item is moved to the hotbar, and the item currently there is re-added to the player's inventory.</summary>
|
||||
HOTBAR_MOVE_AND_READD,
|
||||
/// <summary>The clicked slot and the picked hotbar slot are swapped.</summary>
|
||||
HOTBAR_SWAP,
|
||||
/// <summary>A max-size stack of the clicked item is put on the cursor.</summary>
|
||||
CLONE_STACK,
|
||||
/// <summary>The inventory is searched for the same material, and they are put on the cursor up to Material.getMaxStackSize().</summary>
|
||||
COLLECT_TO_CURSOR,
|
||||
/// <summary>An unrecognized ClickType.</summary>
|
||||
UNKNOWN,
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// This event is called when a player clicks a slot in an inventory.
|
||||
/// <para>
|
||||
/// Because InventoryClickEvent occurs within a modification of the Inventory,
|
||||
/// not all Inventory related methods are safe to use.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The following should never be invoked by an EventHandler for
|
||||
/// InventoryClickEvent using the HumanEntity or InventoryView associated
|
||||
/// with this event:
|
||||
/// <list type="bullet">
|
||||
/// <item><description><see cref="HumanEntity.closeInventory()"/></description></item>
|
||||
/// <item><description><see cref="HumanEntity.openInventory(Inventory)"/></description></item>
|
||||
/// <item><description><see cref="InventoryView.close()"/></description></item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class InventoryClickEvent : InventoryInteractEvent
|
||||
{
|
||||
private readonly SlotType _slotType;
|
||||
private readonly int _rawSlot;
|
||||
private readonly int _whichSlot;
|
||||
private readonly ClickType _click;
|
||||
private readonly InventoryAction _action;
|
||||
private readonly int _hotbarKey;
|
||||
private ItemStack? _currentItem;
|
||||
internal InventoryClickEvent(InventoryView view, SlotType type, int slot,
|
||||
ClickType click, InventoryAction action)
|
||||
: this(view, type, slot, click, action, -1)
|
||||
{
|
||||
}
|
||||
internal InventoryClickEvent(InventoryView view, SlotType type, int slot,
|
||||
ClickType click, InventoryAction action, int key)
|
||||
: base(view)
|
||||
{
|
||||
_slotType = type;
|
||||
_rawSlot = slot;
|
||||
_click = click;
|
||||
_action = action;
|
||||
_hotbarKey = key;
|
||||
_currentItem = view.getItem(slot);
|
||||
_whichSlot = view.convertSlot(slot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the inventory that was clicked, or null if outside of window.
|
||||
/// </summary>
|
||||
/// <returns>The clicked inventory.</returns>
|
||||
public Inventory? getClickedInventory()
|
||||
{
|
||||
if (_rawSlot == InventoryView.OUTSIDE)
|
||||
return null;
|
||||
int topSize = getView().getTopInventory().getSize();
|
||||
if (_rawSlot < topSize)
|
||||
return getView().getTopInventory();
|
||||
return getView().getBottomInventory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of slot that was clicked.
|
||||
/// </summary>
|
||||
/// <returns>The slot type.</returns>
|
||||
public SlotType getSlotType() => _slotType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current ItemStack on the cursor.
|
||||
/// </summary>
|
||||
/// <returns>The cursor ItemStack.</returns>
|
||||
public ItemStack? getCursor() => getView().getCursor();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ItemStack currently in the clicked slot.
|
||||
/// </summary>
|
||||
/// <returns>The item in the clicked slot.</returns>
|
||||
public ItemStack? getCurrentItem() => _currentItem;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the ClickType for this event represents a right click.
|
||||
/// </summary>
|
||||
/// <returns>true if the ClickType uses the right mouse button.</returns>
|
||||
public bool isRightClick() => _click.isRightClick();
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the ClickType for this event represents a left click.
|
||||
/// </summary>
|
||||
/// <returns>true if the ClickType uses the left mouse button.</returns>
|
||||
public bool isLeftClick() => _click.isLeftClick();
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the ClickType for this event indicates that the key was
|
||||
/// pressed down when the click was made.
|
||||
/// </summary>
|
||||
/// <returns>true if the ClickType uses Shift or Ctrl.</returns>
|
||||
public bool isShiftClick() => _click.isShiftClick();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the item on the cursor.
|
||||
/// </summary>
|
||||
/// <param name="stack">The new cursor item.</param>
|
||||
[Obsolete("This changes the ItemStack in their hand before any calculations are applied to the Inventory.")]
|
||||
public void setCursor(ItemStack? stack) => getView().setCursor(stack);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the ItemStack currently in the clicked slot.
|
||||
/// </summary>
|
||||
/// <param name="stack">The item to be placed in the current slot.</param>
|
||||
public void setCurrentItem(ItemStack? stack)
|
||||
{
|
||||
_currentItem = stack;
|
||||
if (_rawSlot >= 0)
|
||||
getView().setItem(_rawSlot, stack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The slot number that was clicked, ready for passing to
|
||||
/// <see cref="Inventory.getItem(int)"/>. Note that there may be two slots
|
||||
/// with the same slot number, since a view links two different inventories.
|
||||
/// </summary>
|
||||
/// <returns>The slot number.</returns>
|
||||
public int getSlot() => _whichSlot;
|
||||
|
||||
/// <summary>
|
||||
/// The raw slot number clicked, ready for passing to
|
||||
/// <see cref="InventoryView.getItem(int)"/>. This slot number is unique
|
||||
/// for the view.
|
||||
/// </summary>
|
||||
/// <returns>The raw slot number.</returns>
|
||||
public int getRawSlot() => _rawSlot;
|
||||
|
||||
/// <summary>
|
||||
/// If the ClickType is NUMBER_KEY, this method will return the index of
|
||||
/// the pressed key (0-8).
|
||||
/// </summary>
|
||||
/// <returns>The number on the key minus 1 (range 0-8); or -1 if not a NUMBER_KEY action.</returns>
|
||||
public int getHotbarButton() => _hotbarKey;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the InventoryAction that triggered this event.
|
||||
/// This action cannot be changed, and represents what the normal outcome
|
||||
/// of the event will be. To change the behavior of this InventoryClickEvent,
|
||||
/// changes must be manually applied.
|
||||
/// </summary>
|
||||
/// <returns>The InventoryAction that triggered this event.</returns>
|
||||
public InventoryAction getAction() => _action;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ClickType for this event.
|
||||
/// This is insulated against changes to the inventory by other plugins.
|
||||
/// </summary>
|
||||
/// <returns>The type of inventory click.</returns>
|
||||
public ClickType getClick() => _click;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a player related inventory event.
|
||||
/// </summary>
|
||||
public class InventoryEvent : Event
|
||||
{
|
||||
/// <summary>The inventory view associated with this event.</summary>
|
||||
protected readonly InventoryView transaction;
|
||||
internal InventoryEvent(InventoryView transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the primary Inventory involved in this transaction.
|
||||
/// </summary>
|
||||
/// <returns>The upper inventory.</returns>
|
||||
public global::Minecraft.Server.FourKit.Inventory.Inventory getInventory()
|
||||
{
|
||||
return transaction.getTopInventory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of players viewing the primary (upper) inventory
|
||||
/// involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>A list of people viewing.</returns>
|
||||
public List<HumanEntity> getViewers()
|
||||
{
|
||||
return transaction.getTopInventory().getViewers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view object itself.
|
||||
/// </summary>
|
||||
/// <returns>The InventoryView.</returns>
|
||||
public InventoryView getView()
|
||||
{
|
||||
return transaction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// An abstract base class for events that describe an interaction between a
|
||||
/// <see cref="HumanEntity"/> and the contents of an <see cref="Inventory"/>.
|
||||
/// This is currently not emitted anywhere, use <see cref="InventoryClickEvent"/> instead.
|
||||
/// </summary>
|
||||
public abstract class InventoryInteractEvent : InventoryEvent, Cancellable
|
||||
{
|
||||
private bool _cancelled;
|
||||
internal protected InventoryInteractEvent(InventoryView transaction) : base(transaction)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who performed the click.
|
||||
/// </summary>
|
||||
/// <returns>The clicking player.</returns>
|
||||
public HumanEntity getWhoClicked()
|
||||
{
|
||||
return transaction.getPlayer();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Inventory;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player opens an inventory. Cancelling this event will prevent
|
||||
/// the inventory screen from showing.
|
||||
/// </summary>
|
||||
public class InventoryOpenEvent : InventoryEvent, Cancellable
|
||||
{
|
||||
private bool _cancelled;
|
||||
internal InventoryOpenEvent(InventoryView transaction) : base(transaction)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the player involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>Player who is involved in this event.</returns>
|
||||
public HumanEntity getPlayer() => transaction.getPlayer();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cancellation state of this event. A cancelled event will not
|
||||
/// be executed in the server, but will still pass to other plugins.
|
||||
/// If an inventory open event is cancelled, the inventory screen will not show.
|
||||
/// </summary>
|
||||
/// <returns>true if this event is cancelled.</returns>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the cancellation state of this event. A cancelled event will not
|
||||
/// be executed in the server, but will still pass to other plugins.
|
||||
/// If an inventory open event is cancelled, the inventory screen will not show.
|
||||
/// </summary>
|
||||
/// <param name="cancel">true if you wish to cancel this event.</param>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Minecraft.Server.FourKit.Event;
|
||||
|
||||
/// <summary>
|
||||
/// Simple interface for tagging all EventListeners
|
||||
/// Register instances with <see cref="FourKit.addListener(Listener)"/>.
|
||||
/// </summary>
|
||||
public interface Listener
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired when the player is almost about to enter the bed.
|
||||
/// </summary>
|
||||
public class PlayerBedEnterEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private readonly Block _bed;
|
||||
private bool _cancelled;
|
||||
|
||||
internal PlayerBedEnterEvent(Player player, Block bed) : base(player)
|
||||
{
|
||||
_bed = bed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the bed block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>the bed block involved in this event</returns>
|
||||
public Block getBed() => _bed;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired when the player is leaving a bed.
|
||||
/// </summary>
|
||||
public class PlayerBedLeaveEvent : PlayerEvent
|
||||
{
|
||||
private readonly Block _bed;
|
||||
|
||||
internal PlayerBedLeaveEvent(Player player, Block bed) : base(player)
|
||||
{
|
||||
_bed = bed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the bed block involved in this event.
|
||||
/// </summary>
|
||||
/// <returns>the bed block involved in this event</returns>
|
||||
public Block getBed() => _bed;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player sends a chat message.
|
||||
///
|
||||
/// <para>When the event finishes execution the server formats the final
|
||||
/// output using the same format specifiers from Java.
|
||||
/// <c>%1$s</c> is the player's display name and <c>%2$s</c> is the
|
||||
/// message, exactly like Bukkits <c>PlayerChatEvent</c>.</para>
|
||||
/// </summary>
|
||||
public class PlayerChatEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private string _message;
|
||||
private string _format;
|
||||
private bool _cancelled;
|
||||
internal PlayerChatEvent(Player player, string message) : base(player)
|
||||
{
|
||||
_message = message;
|
||||
_format = "<%1$s> %2$s";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message that the player is attempting to send.
|
||||
/// This message will be used with <see cref="getFormat"/>.
|
||||
/// </summary>
|
||||
/// <returns>Message the player is attempting to send.</returns>
|
||||
public string getMessage() => _message;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the message that the player will send.
|
||||
/// This message will be used with <see cref="getFormat"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">New message that the player will send.</param>
|
||||
public void setMessage(string message)
|
||||
{
|
||||
_message = message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format used to display this chat message.
|
||||
///
|
||||
/// <para>When this event finishes execution, the first format parameter
|
||||
/// (<c>%1$s</c>) is <c>Player.getDisplayName()</c> and the second
|
||||
/// parameter (<c>%2$s</c>) is <c>getMessage()</c>.</para>
|
||||
/// </summary>
|
||||
/// <returns>A Java-style positional format string compatible with Bukkit.</returns>
|
||||
public string getFormat() => _format;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the format used to display this chat message.
|
||||
///
|
||||
/// <para>When this event finishes execution, the first format parameter
|
||||
/// (<c>%1$s</c>) is <c>Player.getDisplayName()</c> and the second
|
||||
/// parameter (<c>%2$s</c>) is <c>getMessage()</c>.</para>
|
||||
/// </summary>
|
||||
/// <param name="format">A Java-style positional format string (e.g. <c>"<%1$s> %2$s"</c>).</param>
|
||||
/// <exception cref="ArgumentNullException">If format is <c>null</c>.</exception>
|
||||
public void setFormat(string format)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(format);
|
||||
_format = format;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called early in the command handling process. This event is only for very
|
||||
/// exceptional cases and you should not normally use it.
|
||||
///
|
||||
/// <para>If a PlayerCommandPreprocessEvent is cancelled, the command will not
|
||||
/// be executed in the server, but will still pass to other plugins.</para>
|
||||
/// </summary>
|
||||
public class PlayerCommandPreprocessEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private string _message;
|
||||
private bool _cancel;
|
||||
|
||||
internal PlayerCommandPreprocessEvent(Player player, string message) : base(player)
|
||||
{
|
||||
_message = message;
|
||||
_cancel = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancel = cancel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command that the player is attempting to send. All commands
|
||||
/// begin with a special character; implementations do not consider the
|
||||
/// first character when executing the content.
|
||||
/// </summary>
|
||||
/// <returns>Message the player is attempting to send.</returns>
|
||||
public string getMessage() => _message;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the command that the player will send. All commands begin with a
|
||||
/// special character; implementations do not consider the first character
|
||||
/// when executing the content.
|
||||
/// </summary>
|
||||
/// <param name="command">New message that the player will send.</param>
|
||||
/// <exception cref="ArgumentException">If command is null or empty.</exception>
|
||||
public void setMessage(string command)
|
||||
{
|
||||
if (string.IsNullOrEmpty(command))
|
||||
throw new ArgumentException("Command may not be null or empty", nameof(command));
|
||||
_message = command;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
// Yo this event pissed me the fuck off
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player drops an item from their inventory.
|
||||
/// If cancelled, the item will not be dropped and the player keeps it.
|
||||
/// The dropped item can be modified by plugins.
|
||||
/// </summary>
|
||||
public class PlayerDropItemEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private ItemStack _itemDrop;
|
||||
private bool _cancelled;
|
||||
internal PlayerDropItemEvent(Player player, ItemStack drop)
|
||||
: base(player)
|
||||
{
|
||||
_itemDrop = drop;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ItemDrop created by the player.
|
||||
/// </summary>
|
||||
/// <returns>The ItemStack being dropped.</returns>
|
||||
public ItemStack getItemDrop() => _itemDrop;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the item to be dropped. Plugins can modify which item
|
||||
/// is actually dropped.
|
||||
/// </summary>
|
||||
/// <param name="item">The new item to drop.</param>
|
||||
public void setItemDrop(ItemStack item)
|
||||
{
|
||||
_itemDrop = item;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for events related to a <see cref="FourKit.Player"/>.
|
||||
/// </summary>
|
||||
public abstract class PlayerEvent : Event
|
||||
{
|
||||
private readonly Player _player;
|
||||
|
||||
internal protected PlayerEvent(Player player)
|
||||
{
|
||||
_player = player;
|
||||
}
|
||||
|
||||
/// <summary>Returns the player involved in this event.</summary>
|
||||
public Player getPlayer() => _player;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an event that is called when a player right clicks an entity.
|
||||
/// </summary>
|
||||
public class PlayerInteractEntityEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
/// <summary>The entity that was right-clicked.</summary>
|
||||
protected Entity clickedEntity;
|
||||
|
||||
private bool _cancelled;
|
||||
|
||||
internal PlayerInteractEntityEvent(Player who, Entity clickedEntity)
|
||||
: base(who)
|
||||
{
|
||||
this.clickedEntity = clickedEntity;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity that was right-clicked by the player.
|
||||
/// </summary>
|
||||
/// <returns>entity right clicked by player</returns>
|
||||
public Entity getRightClicked() => clickedEntity;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Block;
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
using Minecraft.Server.FourKit.Inventory;
|
||||
|
||||
using FourKitBlock = Minecraft.Server.FourKit.Block.Block;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player interacts with an object or air.
|
||||
/// </summary>
|
||||
public class PlayerInteractEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private readonly Action _action;
|
||||
private readonly ItemStack? _item;
|
||||
private readonly FourKitBlock? _clickedBlock;
|
||||
private readonly BlockFace _clickedFace;
|
||||
private bool _cancelled;
|
||||
private bool _useItemInHand = true;
|
||||
|
||||
internal PlayerInteractEvent(Player who, Action action, ItemStack? item, FourKitBlock? clickedBlock, BlockFace clickedFace)
|
||||
: base(who)
|
||||
{
|
||||
_action = action;
|
||||
_item = item;
|
||||
_clickedBlock = clickedBlock;
|
||||
_clickedFace = clickedFace;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the action type.
|
||||
/// </summary>
|
||||
/// <returns>Action returns the type of interaction.</returns>
|
||||
public Action getAction() => _action;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the cancellation state of this event. A canceled event will not be
|
||||
/// executed in the server, but will still pass to other plugins.
|
||||
///
|
||||
/// Canceling this event will prevent use of food (player won't lose the
|
||||
/// food item), prevent bows/snowballs/eggs from firing, etc. (player won't
|
||||
/// lose the ammo).
|
||||
/// </summary>
|
||||
/// <param name="cancel">true if you wish to cancel this event.</param>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the item in hand represented by this event.
|
||||
/// </summary>
|
||||
/// <returns>ItemStack the item used.</returns>
|
||||
public ItemStack? getItem() => _item;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience method. Returns the material of the item represented by this event.
|
||||
/// </summary>
|
||||
/// <returns>Material the material of the item used.</returns>
|
||||
public Material getMaterial() => _item?.getType() ?? Material.AIR;
|
||||
|
||||
/// <summary>
|
||||
/// Check if this event involved a block.
|
||||
/// </summary>
|
||||
/// <returns>true if it did.</returns>
|
||||
public bool hasBlock() => _clickedBlock != null;
|
||||
|
||||
/// <summary>
|
||||
/// Check if this event involved an item.
|
||||
/// </summary>
|
||||
/// <returns>true if it did.</returns>
|
||||
public bool hasItem() => _item != null;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience method to inform the user whether this was a block placement event.
|
||||
/// </summary>
|
||||
/// <returns>true if the item in hand was a block.</returns>
|
||||
public bool isBlockInHand()
|
||||
{
|
||||
if (_item == null) return false;
|
||||
int id = (int)_item.getType();
|
||||
return id >= 1 && id <= 255;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the clicked block.
|
||||
/// </summary>
|
||||
/// <returns>Block returns the block clicked with this item.</returns>
|
||||
public FourKitBlock? getClickedBlock() => _clickedBlock;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the face of the block that was clicked.
|
||||
/// </summary>
|
||||
/// <returns>BlockFace returns the face of the block that was clicked.</returns>
|
||||
public BlockFace getBlockFace() => _clickedFace;
|
||||
|
||||
/// <summary>
|
||||
/// This controls the action to take with the item the player is holding.
|
||||
/// This includes both blocks and items (such as flint and steel or records).
|
||||
/// When this is set to default, it will be allowed if no action is taken on
|
||||
/// the interacted block.
|
||||
/// </summary>
|
||||
/// <returns>the action to take with the item in hand.</returns>
|
||||
public bool useItemInHand() => _useItemInHand;
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether to use the item in hand.
|
||||
/// </summary>
|
||||
/// <param name="useItemInHand">the action to take with the item in hand.</param>
|
||||
public void setUseItemInHand(bool useItemInHand) => _useItemInHand = useItemInHand;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player joins a server
|
||||
/// </summary>
|
||||
public class PlayerJoinEvent : PlayerEvent
|
||||
{
|
||||
private string _joinMessage;
|
||||
internal PlayerJoinEvent(Player player) : base(player)
|
||||
{
|
||||
_joinMessage = $"{player.getName()} joined the game";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the join message to send to all online players
|
||||
/// </summary>
|
||||
/// <returns>string join message</returns>
|
||||
public string getJoinMessage() => _joinMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the join message to send to all online players
|
||||
/// </summary>
|
||||
/// <param name="joinMessage">join message.</param>
|
||||
public void setJoinMessage(string? joinMessage)
|
||||
{
|
||||
_joinMessage = joinMessage ?? string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player is kicked from the server.
|
||||
/// If cancelled, the kick will not take place and the player remains connected.
|
||||
/// Plugins may modify the kick reason and the leave message broadcast to
|
||||
/// all online players.
|
||||
/// </summary>
|
||||
public class PlayerKickEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private DisconnectReason _reason;
|
||||
private string _leaveMessage;
|
||||
private bool _cancelled;
|
||||
|
||||
internal PlayerKickEvent(Player playerKicked, DisconnectReason kickReason, string leaveMessage)
|
||||
: base(playerKicked)
|
||||
{
|
||||
_reason = kickReason;
|
||||
_leaveMessage = leaveMessage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason why the player is getting kicked.
|
||||
/// </summary>
|
||||
/// <returns>The disconnect reason.</returns>
|
||||
public DisconnectReason getReason() => _reason;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the reason why the player is getting kicked.
|
||||
/// </summary>
|
||||
/// <param name="kickReason">The new disconnect reason.</param>
|
||||
public void setReason(DisconnectReason kickReason)
|
||||
{
|
||||
_reason = kickReason;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the leave message sent to all online players.
|
||||
/// </summary>
|
||||
/// <returns>The leave message.</returns>
|
||||
public string getLeaveMessage() => _leaveMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the leave message sent to all online players.
|
||||
/// </summary>
|
||||
/// <param name="leaveMessage">The new leave message.</param>
|
||||
public void setLeaveMessage(string leaveMessage)
|
||||
{
|
||||
_leaveMessage = leaveMessage;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Enums;
|
||||
using Minecraft.Server.FourKit.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Stores details for players attempting to log in.
|
||||
/// </summary>
|
||||
public class PlayerLoginEvent : Event, Cancellable
|
||||
{
|
||||
private string name;
|
||||
private InetSocketAddress ipAddress; //bukkit uses InetAddress but we expose port also
|
||||
|
||||
private ulong onlineXuid;
|
||||
private ulong offlineXuid;
|
||||
private bool changedXuidValues;
|
||||
|
||||
private LoginType loginType;
|
||||
|
||||
private bool _cancelled;
|
||||
|
||||
internal PlayerLoginEvent(string name, InetSocketAddress ipAddress, LoginType type, ulong onlineXuid, ulong offlineXuid) : base()
|
||||
{
|
||||
this.name = name;
|
||||
this.ipAddress = ipAddress;
|
||||
this.onlineXuid = onlineXuid;
|
||||
this.offlineXuid = offlineXuid;
|
||||
this.changedXuidValues = false;
|
||||
|
||||
this.loginType = type;
|
||||
}
|
||||
|
||||
public LoginType getLoginType() => loginType;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <b>Experimental.</b> Gets the online XUID (Xbox User ID), used for guests (splitscreen users).
|
||||
/// </summary>
|
||||
/// <returns>The online XUID value.</returns>
|
||||
public ulong getOnlineXuid() => onlineXuid;
|
||||
|
||||
/// <summary>
|
||||
/// <b>Experimental.</b> Sets the online XUID (Xbox User ID). Marks XUID values as changed.
|
||||
/// </summary>
|
||||
/// <param name="newXuid">The new online XUID value.</param>
|
||||
public void setOnlineXuid(ulong newXuid)
|
||||
{
|
||||
this.onlineXuid = newXuid;
|
||||
this.changedXuidValues = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <b>Experimental.</b> Gets the offline XUID (Xbox User ID), which is the main XUID used by the client.
|
||||
/// </summary>
|
||||
/// <returns>The offline XUID value.</returns>
|
||||
public ulong getOfflineXuid() => offlineXuid;
|
||||
|
||||
/// <summary>
|
||||
/// <b>Experimental.</b> Sets the offline XUID (Xbox User ID). Marks XUID values as changed.
|
||||
/// </summary>
|
||||
/// <param name="newXuid">The new offline XUID value.</param>
|
||||
public void setOfflineXuid(ulong newXuid)
|
||||
{
|
||||
this.offlineXuid = newXuid;
|
||||
this.changedXuidValues = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <b>Experimental.</b> Returns true if either XUID value has been changed via setters.
|
||||
/// </summary>
|
||||
/// <returns>True if XUID values have been changed; otherwise, false.</returns>
|
||||
public bool hasChangedXuidValues() => changedXuidValues;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player's name.
|
||||
/// </summary>
|
||||
/// <returns>The player's name.</returns>
|
||||
public string getName() => name;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player IP address.
|
||||
/// </summary>
|
||||
/// <returns>The IP address.</returns>
|
||||
public InetSocketAddress getAddress() => ipAddress;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player moves. Plugins may modify the destination
|
||||
/// or cancel the movement entirely.
|
||||
/// </summary>
|
||||
public class PlayerMoveEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private Location _from;
|
||||
private Location _to;
|
||||
private bool _cancelled;
|
||||
|
||||
internal PlayerMoveEvent(Player player, Location from, Location to) : base(player)
|
||||
{
|
||||
_from = from;
|
||||
_to = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location this player moved from.
|
||||
/// </summary>
|
||||
/// <returns>The from location.</returns>
|
||||
public Location getFrom() => _from;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location this player moved to.
|
||||
/// </summary>
|
||||
/// <returns>The to location.</returns>
|
||||
public Location getTo() => _to;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the location to mark as where the player moved from.
|
||||
/// </summary>
|
||||
/// <param name="from">The new from location.</param>
|
||||
public void setFrom(Location from)
|
||||
{
|
||||
_from = from;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the location that this player will move to.
|
||||
/// </summary>
|
||||
/// <param name="to">The new to location.</param>
|
||||
public void setTo(Location to)
|
||||
{
|
||||
_to = to;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Thrown when a player picks an item up from the ground.
|
||||
/// If cancelled the item will not be picked up.
|
||||
/// </summary>
|
||||
public class PlayerPickupItemEvent : PlayerEvent, Cancellable
|
||||
{
|
||||
private readonly Item _item;
|
||||
private readonly int _remaining;
|
||||
private bool _cancelled;
|
||||
internal PlayerPickupItemEvent(Player player, Item item, int remaining)
|
||||
: base(player)
|
||||
{
|
||||
_item = item;
|
||||
_remaining = remaining;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Item picked up by the player.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Item"/> entity.</returns>
|
||||
public Item getItem() => _item;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount remaining on the ground, if any.
|
||||
/// </summary>
|
||||
/// <returns>Amount remaining on the ground.</returns>
|
||||
public int getRemaining() => _remaining;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel)
|
||||
{
|
||||
_cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player is about to teleport because it is in contact with a portal.
|
||||
/// </summary>
|
||||
public class PlayerPortalEvent : PlayerTeleportEvent
|
||||
{
|
||||
internal PlayerPortalEvent(Player player, Location from, Location to)
|
||||
: base(player, from, to, TeleportCause.UNKNOWN) { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new PlayerPortalEvent with the given cause.
|
||||
/// </summary>
|
||||
/// <param name="player">The player entering the portal.</param>
|
||||
/// <param name="from">The location the player is coming from.</param>
|
||||
/// <param name="to">The location the player is teleporting to.</param>
|
||||
/// <param name="cause">The cause of this teleportation (should be a portal-related cause).</param>
|
||||
public PlayerPortalEvent(Player player, Location from, Location to, TeleportCause cause)
|
||||
: base(player, from, to, cause) { }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Stores details for players attempting to log in.
|
||||
/// </summary>
|
||||
public class PlayerPreLoginEvent : Event, Cancellable
|
||||
{
|
||||
private string name;
|
||||
private InetSocketAddress ipAddress; //bukkit uses InetAddress but we expose port also
|
||||
private bool _cancelled;
|
||||
|
||||
|
||||
internal PlayerPreLoginEvent(string name, InetSocketAddress ipAddress) : base()
|
||||
{
|
||||
this.name = name;
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player's name.
|
||||
/// </summary>
|
||||
/// <returns>The player's name.</returns>
|
||||
public string getName() => name;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player IP address.
|
||||
/// </summary>
|
||||
/// <returns>The IP address.</returns>
|
||||
public InetSocketAddress getAddress() => ipAddress;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player disconnects from the server.
|
||||
/// Plugins may read or modify the quit message that is broadcast to all
|
||||
/// online players.
|
||||
/// </summary>
|
||||
public class PlayerQuitEvent : PlayerEvent
|
||||
{
|
||||
private string _quitMessage;
|
||||
internal PlayerQuitEvent(Player player) : base(player)
|
||||
{
|
||||
_quitMessage = $"{player.getName()} left the game";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the quit message to send to all online players.
|
||||
/// </summary>
|
||||
/// <returns>The quit message.</returns>
|
||||
public string getQuitMessage() => _quitMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the quit message to send to all online players.
|
||||
/// </summary>
|
||||
/// <param name="quitMessage">The new quit message, or <c>null</c> to suppress it.</param>
|
||||
public void setQuitMessage(string? quitMessage)
|
||||
{
|
||||
_quitMessage = quitMessage ?? string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Player;
|
||||
|
||||
using Minecraft.Server.FourKit.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Holds information for player teleport events.
|
||||
/// </summary>
|
||||
public class PlayerTeleportEvent : PlayerMoveEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the cause of a player teleportation.
|
||||
/// </summary>
|
||||
public enum TeleportCause
|
||||
{
|
||||
/// <summary>Indicates the teleportation was caused by a player throwing an Ender Pearl.</summary>
|
||||
ENDER_PEARL,
|
||||
/// <summary>Indicates the teleportation was caused by a player executing a command.</summary>
|
||||
COMMAND,
|
||||
/// <summary>Indicates the teleportation was caused by a plugin.</summary>
|
||||
PLUGIN,
|
||||
/// <summary>Indicates the teleportation was caused by a player entering a Nether portal.</summary>
|
||||
NETHER_PORTAL,
|
||||
/// <summary>Indicates the teleportation was caused by a player entering an End portal.</summary>
|
||||
END_PORTAL,
|
||||
/// <summary>Indicates the teleportation was caused by an event not covered by this enum.</summary>
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
private readonly TeleportCause _cause;
|
||||
|
||||
internal PlayerTeleportEvent(Player player, Location from, Location to)
|
||||
: this(player, from, to, TeleportCause.UNKNOWN) { }
|
||||
internal PlayerTeleportEvent(Player player, Location from, Location to, TeleportCause cause)
|
||||
: base(player, from, to)
|
||||
{
|
||||
_cause = cause;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cause of this teleportation event.
|
||||
/// </summary>
|
||||
/// <returns>The cause of the event.</returns>
|
||||
public TeleportCause getCause() => _cause;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public class PluginDisableEvent : PluginEvent
|
||||
{
|
||||
|
||||
internal PluginDisableEvent(ServerPlugin plugin) : base(plugin)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public class PluginEnableEvent : PluginEvent
|
||||
{
|
||||
|
||||
internal PluginEnableEvent(ServerPlugin plugin) : base(plugin)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public abstract class PluginEvent : ServerEvent
|
||||
{
|
||||
private readonly ServerPlugin _plugin;
|
||||
|
||||
internal protected PluginEvent(ServerPlugin plugin) : base()
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
/// <summary>Returns the plugin involved in this event.</summary>
|
||||
public ServerPlugin getPlugin() => _plugin;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public class PluginLoadFailedEvent : ServerEvent
|
||||
{
|
||||
private readonly string _fileName;
|
||||
private readonly string _message;
|
||||
internal PluginLoadFailedEvent(string fileName, string message) : base()
|
||||
{
|
||||
_fileName = fileName;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
public string getFileName() => _fileName;
|
||||
|
||||
public string getMessage() => _message;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public class PluginsLoadedEvent : ServerEvent
|
||||
{
|
||||
internal PluginsLoadedEvent() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Minecraft.Server.FourKit.Event.Server;
|
||||
|
||||
using Minecraft.Server.FourKit.Plugin;
|
||||
|
||||
public abstract class ServerEvent : Event
|
||||
{
|
||||
|
||||
internal protected ServerEvent() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Minecraft.Server.FourKit.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Minecraft.Server.FourKit.Event.World;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is called when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal.
|
||||
/// </summary>
|
||||
public class StructureGrowEvent : WorldEvent, Cancellable
|
||||
{
|
||||
internal Location _location;
|
||||
internal TreeType _treeType;
|
||||
internal bool _wasBonemeal;
|
||||
internal Minecraft.Server.FourKit.Entity.Player? _player;
|
||||
|
||||
internal bool _cancelled;
|
||||
internal StructureGrowEvent(Location location, TreeType treeType, bool wasBonemeal, Minecraft.Server.FourKit.Entity.Player? player) : base(location.getWorld())
|
||||
{
|
||||
_location = location;
|
||||
_treeType = treeType;
|
||||
_wasBonemeal = wasBonemeal;
|
||||
_player = player;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the species type (birch, normal, pine, red mushroom, brown mushroom).
|
||||
/// </summary>
|
||||
/// <returns>Structure species</returns>
|
||||
public TreeType getSpecies() => _treeType;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location of the structure.
|
||||
/// </summary>
|
||||
/// <returns>Location of the structure</returns>
|
||||
public Location getLocation() => _location;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if structure was grown using bonemeal.
|
||||
/// </summary>
|
||||
/// <returns>True if the structure was grown using bonemeal.</returns>
|
||||
public bool isFromBonemeal() => _wasBonemeal;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that created the structure.
|
||||
/// </summary>
|
||||
/// <returns>Player that created the structure, null if was not created manually</returns>
|
||||
public Minecraft.Server.FourKit.Entity.Player? getPlayer() => _player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool isCancelled() => _cancelled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void setCancelled(bool cancel) => _cancelled = cancel;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Minecraft.Server.FourKit.Event.World;
|
||||
|
||||
using Minecraft.Server.FourKit;
|
||||
|
||||
public class WorldEvent : Event
|
||||
{
|
||||
internal World? _world;
|
||||
|
||||
internal WorldEvent(World? world) : base()
|
||||
{
|
||||
_world = world;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Minecraft.Server.FourKit.Event.World;
|
||||
|
||||
using Minecraft.Server.FourKit;
|
||||
|
||||
public class WorldSaveEvent : Event
|
||||
{
|
||||
|
||||
internal WorldSaveEvent() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user