MinecraftConsoles/Minecraft.Server.FourKit/Experimental/PlayerConnection.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

36 lines
1 KiB
C#

using Minecraft.Server.FourKit.Entity;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Minecraft.Server.FourKit.Experimental;
public class PlayerConnection
{
private Player _player;
internal PlayerConnection(Player player)
{
this._player = player;
}
/// <summary>
/// Sends raw packet data directly to the client over the player's connection.
/// The byte array must contain the complete packet including the packet ID as the first byte. The server automatically prepends the 4-byte big-endian size header before transmitting.
/// </summary>
/// <param name="data">The raw packet bytes to send, where <c>data[0]</c> is the packet ID.</param>
public void send(byte[] data)
{
var gh = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
NativeBridge.SendRaw?.Invoke(_player.getEntityId(), gh.AddrOfPinnedObject(), data.Length);
}
finally
{
gh.Free();
}
}
}