MinecraftConsoles/Minecraft.Server.FourKit/FourKitHost.Callbacks.cs
DrPerkyLegit 21b5accc69
Feature/plugin api experimental (#12)
* added a null check to fix crash, expose internal latency value (its buggy)

* fix latency calculations

* sending packets from c#

* world save event, move shutdown def, move called location of shutdown, expose FourKit.FireEvent

* add docs

---------

Co-authored-by: sylvessa <225480449+sylvessa@users.noreply.github.com>
2026-04-05 21:21:22 -05:00

125 lines
4.8 KiB
C#

using System.Runtime.InteropServices;
namespace Minecraft.Server.FourKit;
public static partial class FourKitHost
{
[UnmanagedCallersOnly]
public static void SetNativeCallbacks(IntPtr damage, IntPtr setHealth, IntPtr teleport, IntPtr setGameMode, IntPtr broadcastMessage, IntPtr setFallDistance, IntPtr getPlayerSnapshot, IntPtr sendMessage, IntPtr setWalkSpeed, IntPtr teleportEntity)
{
try
{
NativeBridge.SetCallbacks(damage, setHealth, teleport, setGameMode, broadcastMessage, setFallDistance, getPlayerSnapshot, sendMessage, setWalkSpeed, teleportEntity);
ServerLog.Info("fourkit", "Native callbacks registered.");
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetNativeCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetWorldCallbacks(IntPtr getTileId, IntPtr getTileData, IntPtr setTile, IntPtr setTileData, IntPtr breakBlock, IntPtr getHighestBlockY, IntPtr getWorldInfo, IntPtr setWorldTime, IntPtr setWeather, IntPtr createExplosion, IntPtr strikeLightning, IntPtr setSpawnLocation, IntPtr dropItem)
{
try
{
NativeBridge.SetWorldCallbacks(getTileId, getTileData, setTile, setTileData, breakBlock, getHighestBlockY, getWorldInfo, setWorldTime, setWeather, createExplosion, strikeLightning, setSpawnLocation, dropItem);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetWorldCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetPlayerCallbacks(IntPtr kickPlayer, IntPtr banPlayer, IntPtr banPlayerIp, IntPtr getPlayerAddress, IntPtr getPlayerLatency)
{
try
{
NativeBridge.SetPlayerCallbacks(kickPlayer, banPlayer, banPlayerIp, getPlayerAddress, getPlayerLatency);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetPlayerCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetPlayerConnectionCallbacks(IntPtr sendRaw)
{
try
{
NativeBridge.SetPlayerConnectionCallbacks(sendRaw);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetPlayerConnectionCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetInventoryCallbacks(IntPtr getPlayerInventory, IntPtr setPlayerInventorySlot, IntPtr getContainerContents, IntPtr setContainerSlot, IntPtr getContainerViewerEntityIds, IntPtr closeContainer, IntPtr openVirtualContainer, IntPtr getItemMeta, IntPtr setItemMeta, IntPtr setHeldItemSlot)
{
try
{
NativeBridge.SetInventoryCallbacks(getPlayerInventory, setPlayerInventorySlot, getContainerContents, setContainerSlot, getContainerViewerEntityIds, closeContainer, openVirtualContainer, getItemMeta, setItemMeta, setHeldItemSlot);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetInventoryCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetEntityCallbacks(IntPtr setSneaking, IntPtr setVelocity, IntPtr setAllowFlight, IntPtr playSound, IntPtr setSleepingIgnored)
{
try
{
NativeBridge.SetEntityCallbacks(setSneaking, setVelocity, setAllowFlight, playSound, setSleepingIgnored);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetEntityCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetExperienceCallbacks(IntPtr setLevel, IntPtr setExp, IntPtr giveExp, IntPtr giveExpLevels, IntPtr setFoodLevel, IntPtr setSaturation, IntPtr setExhaustion)
{
try
{
NativeBridge.SetExperienceCallbacks(setLevel, setExp, giveExp, giveExpLevels, setFoodLevel, setSaturation, setExhaustion);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetExperienceCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetParticleCallbacks(IntPtr spawnParticle)
{
try
{
NativeBridge.SetParticleCallbacks(spawnParticle);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetParticleCallbacks error: {ex}");
}
}
[UnmanagedCallersOnly]
public static void SetVehicleCallbacks(IntPtr setPassenger, IntPtr leaveVehicle, IntPtr eject, IntPtr getVehicleId, IntPtr getPassengerId, IntPtr getEntityInfo)
{
try
{
NativeBridge.SetVehicleCallbacks(setPassenger, leaveVehicle, eject, getVehicleId, getPassengerId, getEntityInfo);
}
catch (Exception ex)
{
ServerLog.Error("fourkit", $"SetVehicleCallbacks error: {ex}");
}
}
}