diff --git a/MCGalaxy/Events/PlayerEvents.cs b/MCGalaxy/Events/PlayerEvents.cs
index f20312ef5..4c0bfd1b0 100644
--- a/MCGalaxy/Events/PlayerEvents.cs
+++ b/MCGalaxy/Events/PlayerEvents.cs
@@ -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);
/// Called whenever a player triggers a certain client event
public sealed class OnNotifyActionEvent : IEvent
{
- public static void Call(Player p, NotifyActionType action, int value)
+ public static void Call(Player p, NotifyActionType action, short value)
{
IEvent[] 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);
+ /// Called whenever a player triggers a respawn/setspawn client event
+ public sealed class OnNotifyPositionActionEvent : IEvent
+ {
+ public static void Call(Player p, NotifyActionType action, ushort x, ushort y, ushort z)
+ {
+ IEvent[] 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);
/// Called whenever a player recieves a message from the server or from another player
public sealed class OnMessageRecievedEvent : IEvent
diff --git a/MCGalaxy/Network/CPESupport.cs b/MCGalaxy/Network/CPESupport.cs
index 062fc56ce..0905c76f1 100644
--- a/MCGalaxy/Network/CPESupport.cs
+++ b/MCGalaxy/Network/CPESupport.cs
@@ -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
diff --git a/MCGalaxy/Network/ClassicProtocol.cs b/MCGalaxy/Network/ClassicProtocol.cs
index e844d8100..47ec7ed07 100644
--- a/MCGalaxy/Network/ClassicProtocol.cs
+++ b/MCGalaxy/Network/ClassicProtocol.cs
@@ -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;
diff --git a/MCGalaxy/Network/Packets/Opcode.cs b/MCGalaxy/Network/Packets/Opcode.cs
index 45cac7d3a..b08bed354 100644
--- a/MCGalaxy/Network/Packets/Opcode.cs
+++ b/MCGalaxy/Network/Packets/Opcode.cs
@@ -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;
}
}