diff --git a/src/Host/Extensions/HostEcsBuilderExtensions.cs b/src/Host/Extensions/HostEcsBuilderExtensions.cs index b1deaf0a..2b768018 100644 --- a/src/Host/Extensions/HostEcsBuilderExtensions.cs +++ b/src/Host/Extensions/HostEcsBuilderExtensions.cs @@ -23,7 +23,8 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder) "OnPlayerPickUpPickup", "OnPlayerSpawn", "OnPlayerRequestClass", - "OnPlayerRequestSpawn" + "OnPlayerRequestSpawn", + "OnPlayerPauseStateChange" ]; foreach (string @event in events) @@ -33,4 +34,13 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder) return builder; } + + public static IEcsBuilder EnableYsfEvents(this IEcsBuilder builder) + { + builder + .EnableEvent("OnPlayerPauseStateChange"); + + builder.UseMiddleware("OnPlayerPauseStateChange"); + return builder; + } } diff --git a/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs b/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs new file mode 100644 index 00000000..cc9d04d4 --- /dev/null +++ b/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs @@ -0,0 +1,15 @@ +namespace CTF.Host.Middlewares; + +public class PlayerPauseStateChangeMiddleware(EventDelegate next) +{ + public object Invoke(EventContext context, IEntityManager entityManager) + { + var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]); + + if (!entityManager.Exists(playerEntity)) + return null; + + context.Arguments[0] = playerEntity; + return next(context); + } +} diff --git a/src/Host/Startup.cs b/src/Host/Startup.cs index 201c8dfb..981f014e 100644 --- a/src/Host/Startup.cs +++ b/src/Host/Startup.cs @@ -32,6 +32,7 @@ public void Configure(IEcsBuilder builder) .EnableSampEvents() .EnablePlayerCommands() .EnableRconCommands() - .EnableStreamerEvents(); + .EnableStreamerEvents() + .EnableYsfEvents(); } }