Skip to content

feat: add new events#565

Closed
RozyGay wants to merge 10 commits into
ExMod-Team:devfrom
RozyGay:master
Closed

feat: add new events#565
RozyGay wants to merge 10 commits into
ExMod-Team:devfrom
RozyGay:master

Conversation

@RozyGay

@RozyGay RozyGay commented Jun 14, 2025

Copy link
Copy Markdown

Description

Describe the changes
This pull request enhances the Server.RoundStarted event by introducing RoundStartedEventArgs, replacing the parameterless Event with one that provides useful context. It updates Server.cs to use the new event args and adds a transpiler patch in RoundStartPatch.cs for RoundSummary.Start. It also builds on earlier command-related event improvements. Changes include:

  • Added RoundStartedEventArgs.cs in Exiled.Events/EventArgs/Server with properties:
    • RoundStartTime: UTC time when the round started.
    • PlayerCount: Number of non-NPC, non-host players (via Player.List.Where(p => !p.IsNPC && !p.IsHost).Count()).
    • KeepRoundOnOne: Inverted value of ServerConfig.GetBool("end_round_on_one_player", false).
  • Modified Server.cs in Exiled.Events/Handlers to use Event<RoundStartedEventArgs> and updated OnRoundStarted to accept RoundStartedEventArgs.
  • Added RoundStartPatch.cs in Exiled.Events/Patches/Events/Server with a transpiler for RoundSummary.Start, injecting OnRoundStarted before KeepRoundOnOne assignment (IL_0033).

Previous command-related enhancements:

  • Added ExecutingClientCommandEventArgs.cs in Exiled.Events/EventArgs/Server to improve client-side command handling (e.g., .help, .sp), providing plugins with issuer and argument details.
  • Added ExecutingRemoteAdminCommandEventArgs.cs in Exiled.Events/EventArgs/Server to enhance Remote Admin (RA) command handling (e.g., kick, ban), offering richer context for RA command execution.
  • Enhanced ExecutingCommand event in Server.cs to provide ExecutingCommandEventArgs, allowing plugins to intercept and modify general server commands.

What is the current behavior?

  • The Server.RoundStarted event is a parameterless Event, offering no round start details, limiting plugin functionality.
  • Command events like ExecutingCommand previously had basic functionality, with limited support for client-side or RA-specific commands.

What is the new behavior?

  • The Server.RoundStarted event now provides RoundStartedEventArgs, enabling plugins to access:
    • Round start time in UTC.
    • Count of non-NPC, non-host players.
    • KeepRoundOnOne config value (!ServerConfig.GetBool("end_round_on_one_player", false)).
      The transpiler ensures the event triggers early in RoundSummary.Start.
  • Command-related events now offer:
    • ExecutingClientCommandEventArgs for client commands, with issuer and argument data.
    • ExecutingRemoteAdminCommandEventArgs for RA commands, with detailed execution context.
    • ExecutingCommandEventArgs for general command handling, improving plugin flexibility.

Does this PR introduce a breaking change?
No breaking changes. Existing plugins using Server.RoundStarted, ExecutingCommand, or other command events without args remain compatible via InvokeSafely.

Other information:

  • Tested with end_round_on_one_player set to true and false.
  • Tested command events with plugins intercepting ban (RA) and .help (client).
  • Changelog updated:
    • “Added RoundStartedEventArgs with RoundStartTime, PlayerCount, and KeepRoundOnOne. Updated Server.RoundStarted with transpiler patch.”
    • “Added ExecutingClientCommandEventArgs and ExecutingRemoteAdminCommandEventArgs for enhanced command handling.”
  • Sample plugin log for round start:
    Log.Info($"Round started: Time={ev.RoundStartTime}, Count={ev.PlayerCount}, KeepRoundOnOne={ev.KeepRoundOnOne}");

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

BoltonDev and others added 6 commits June 13, 2025 12:15
## Description
**Describe the changes** 


**What is the current behavior?** (You can also link to an open issue
here)


**What is the new behavior?** (if this is a feature change)


**Does this PR introduce a breaking change?** (What changes might users
need to make in their application due to this PR?)


**Other information**:

<br />

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentations
<br />

## Submission checklist
<!--- Put an `x` in all the boxes that apply: -->
- [ ] I have checked the project can be compiled
- [ ] I have tested my changes and it worked as expected

### Patches (if there are any changes related to Harmony patches)
- [ ] I have checked no IL patching errors in the console

### Other
- [ ] Still requires more testing
- Introduced new event args classes: `ExecutingRemoteAdminCommandEventArgs` and `ExecutingClientCommandEventArgs` in `Exiled.Events.EventArgs.Player` to handle Remote Admin and Client command execution events.
- Added `PlayerCommands` event handler class in `Exiled.Events.Handlers` to define `ExecutingRemoteAdminCommand` and `ExecutingClientCommand` events.
- Implemented Harmony transpiler patches in `Exiled.Events.Patches.Events.Player`:
  - `ExecutingRemoteAdminCommand` patches `CommandProcessor.ProcessQuery` to trigger the event before Remote Admin command execution.
  - `ExecutingClientCommand` patches `QueryProcessor.ProcessGameConsoleQuery` to trigger the event before Client command execution.
- Patches use pattern-matching for robust instruction insertion, allowing plugins to monitor, modify, or cancel command execution via the `IsAllowed` property.
- Follows EXILED conventions for documentation, licensing, and code structure.

This addition enhances plugin flexibility by providing fine-grained control over command execution in SCP:SL.
@RozyGay RozyGay changed the title ExecutingRemoteAdminCommand and ExecutingClientCommand events ExecutingRemoteAdminCommand and add ExecutingClientCommand events Jun 14, 2025
@RozyGay RozyGay changed the title ExecutingRemoteAdminCommand and add ExecutingClientCommand events add new events Jun 14, 2025
@RozyGay RozyGay changed the title add new events feat: add new events Jun 14, 2025
@MS-crew

MS-crew commented Jun 14, 2025

Copy link
Copy Markdown

This is a breaking change, and you should mark it as such in the box provided for that purpose. It will break 80% of plugins.

@VALERA771 VALERA771 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Duplicate events (executing commands). Also I didn't find such event for GameConsole handler and personally I don't think that this is neccecary to separate these events while we just can have a property that will indicate which handler is used
  2. Duplicate calling RoundStarted event (handler + patch)
  3. We already have a SendingCommand event and yours seems like duplicate of it

Comment thread EXILED/Exiled.Events/Events.cs
Comment thread EXILED/Exiled.Events/Events.cs
@VALERA771

Copy link
Copy Markdown

Also I forgot to mention some breaking changes. Because of them we will be able to merge your PR only on major release

Comment on lines +106 to +108
CharacterClassManager.OnRoundStarted -= () => Handlers.Server.OnRoundStarted(new RoundStartedEventArgs(
DateTime.UtcNow,
Player.List.Where(p => !p.IsNPC && !p.IsHost).Count(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will not work

@louis1706 louis1706 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this event in PlayerEventArgs

Comment on lines +73 to +76
CharacterClassManager.OnRoundStarted += () => Handlers.Server.OnRoundStarted(new RoundStartedEventArgs(
DateTime.UtcNow,
Player.List.Where(p => !p.IsNPC && !p.IsHost).Count(),
!ConfigFile.ServerConfig.GetBool("end_round_on_one_player", false)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed in my opinion

@louis1706 louis1706 closed this Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants