Use NotifyPositionAction for respawn/setspawn

This commit is contained in:
Derek 2025-01-03 18:22:42 +10:00
parent 478c09205e
commit 6de8f95b74
4 changed files with 38 additions and 5 deletions

View File

@ -209,11 +209,11 @@ namespace MCGalaxy.Events.PlayerEvents
}
}
public delegate void OnNotifyAction(Player p, NotifyActionType action, int value);
public delegate void OnNotifyAction(Player p, NotifyActionType action, short value);
/// <summary> Called whenever a player triggers a certain client event </summary>
public sealed class OnNotifyActionEvent : IEvent<OnNotifyAction>
{
public static void Call(Player p, NotifyActionType action, int value)
public static void Call(Player p, NotifyActionType action, short value)
{
IEvent<OnNotifyAction>[] items = handlers.Items;
for (int i = 0; i < items.Length; i++)
@ -224,6 +224,21 @@ namespace MCGalaxy.Events.PlayerEvents
}
}
public delegate void OnNotifyPositionAction(Player p, NotifyActionType action, ushort x, ushort y, ushort z);
/// <summary> Called whenever a player triggers a respawn/setspawn client event </summary>
public sealed class OnNotifyPositionActionEvent : IEvent<OnNotifyPositionAction>
{
public static void Call(Player p, NotifyActionType action, ushort x, ushort y, ushort z)
{
IEvent<OnNotifyPositionAction>[] items = handlers.Items;
for (int i = 0; i < items.Length; i++)
{
try { items[i].method(p, action, x, y, z); }
catch (Exception ex) { LogHandlerException(ex, items[i]); }
}
}
}
public delegate void OnMessageReceived(Player p, ref string message, ref bool cancel);
/// <summary> Called whenever a player recieves a message from the server or from another player </summary>
public sealed class OnMessageRecievedEvent : IEvent<OnMessageReceived>

View File

@ -95,6 +95,7 @@ namespace MCGalaxy
public const string LightingMode = "LightingMode";
public const string CinematicGui = "CinematicGui";
public const string NotifyAction = "NotifyAction";
public const string NotifyPositionAction = "NotifyPositionAction";
}
public sealed class CpeExtension
@ -157,6 +158,7 @@ namespace MCGalaxy
new CpeExtension(CpeExt.LightingMode, "Allows changing how the client lights worlds"),
new CpeExtension(CpeExt.CinematicGui, "Allows changing the visibility of some GUI components"),
new CpeExtension(CpeExt.NotifyAction, "Allows server to be notified of certain client events"),
new CpeExtension(CpeExt.NotifyPositionAction, "Allows server to be notified of certain client events (respawn/setspawn)"),
#if TEN_BIT_BLOCKS
new CpeExtension(CpeExt.ExtBlocks, "Allows using block IDs over 255 in block definitions"),
#endif

View File

@ -50,6 +50,7 @@ namespace MCGalaxy.Network
case Opcode.CpeTwoWayPing: return HandleTwoWayPing(buffer, offset, left);
case Opcode.CpePluginMessage: return HandlePluginMessage(buffer, offset, left);
case Opcode.CpeNotifyAction: return HandleNotifyAction(buffer, offset, left);
case Opcode.CpeNotifyPositionAction: return HandleNotifyPositionAction(buffer, offset, left);
case Opcode.CpeCustomBlockSupportLevel:
return left < 2 ? 0 : 2; // only ever one level anyways
@ -256,16 +257,30 @@ namespace MCGalaxy.Network
int HandleNotifyAction(byte[] buffer, int offset, int left)
{
const int size = 1 + 2 + 5;
const int size = 1 + 2 + 2;
if (left < size) return 0;
NotifyActionType action = (NotifyActionType)buffer[offset + 1];
int value = NetUtils.ReadI32(buffer, offset + 3);
NotifyActionType action = (NotifyActionType)buffer[offset + 2];
short value = NetUtils.ReadI16(buffer, offset + 3);
OnNotifyActionEvent.Call(player, action, value);
return size;
}
int HandleNotifyPositionAction(byte[] buffer, int offset, int left)
{
const int size = 1 + 2 + 2 + 2 + 2;
if (left < size) return 0;
NotifyActionType action = (NotifyActionType)buffer[offset + 2];
ushort x = NetUtils.ReadU16(buffer, offset + 3);
ushort y = NetUtils.ReadU16(buffer, offset + 5);
ushort z = NetUtils.ReadU16(buffer, offset + 7);
OnNotifyPositionActionEvent.Call(player, action, x, y, z);
return size;
}
int HandleTwoWayPing(byte[] buffer, int offset, int left) {
const int size = 1 + 1 + 2;
if (left < size) return 0;

View File

@ -81,5 +81,6 @@ namespace MCGalaxy.Network {
public const byte CpeLightingMode = 55;
public const byte CpeCinematicGui = 56;
public const byte CpeNotifyAction = 57;
public const byte CpeNotifyPositionAction = 58;
}
}