From fc6435c5f675dc190eeeead90c3f87aa6164b3e0 Mon Sep 17 00:00:00 2001 From: Oscar <29248751+oscar-wos@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:04:07 +0000 Subject: [PATCH 1/3] feat: minPlayers config --- .gitmodules | 3 +++ AntiRush.sln | 8 +++++++- CSSharpUtils | 1 + src/AntiRush.cs | 4 ++++ src/AntiRush.csproj | 6 +----- src/Config.cs | 3 ++- src/Events.cs | 4 +++- src/Globals.cs | 3 ++- src/Listeners.cs | 3 +++ 9 files changed, 26 insertions(+), 9 deletions(-) create mode 160000 CSSharpUtils diff --git a/.gitmodules b/.gitmodules index c9bbd48..2d5b6f2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Menu"] path = Menu url = https://github.com/oscar-wos/Menu.git +[submodule "CSSharpUtils"] + path = CSSharpUtils + url = https://github.com/oscar-wos/CSSharpUtils diff --git a/AntiRush.sln b/AntiRush.sln index 04b9d30..8cc03d0 100644 --- a/AntiRush.sln +++ b/AntiRush.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiRush", "src\AntiRush.csproj", "{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", ".\Menu\src\Menu.csproj", "{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", "Menu\src\Menu.csproj", "{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSSharpUtils", "CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj", "{794D24A4-83A3-4F67-94DE-09087FC9554E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Debug|Any CPU.Build.0 = Debug|Any CPU {5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.ActiveCfg = Release|Any CPU {5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.Build.0 = Release|Any CPU + {794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CSSharpUtils b/CSSharpUtils new file mode 160000 index 0000000..4291c7a --- /dev/null +++ b/CSSharpUtils @@ -0,0 +1 @@ +Subproject commit 4291c7ad17ca3459e0ec24b584562c8acbf14623 diff --git a/src/AntiRush.cs b/src/AntiRush.cs index ebf7bd5..2e199fa 100644 --- a/src/AntiRush.cs +++ b/src/AntiRush.cs @@ -2,6 +2,7 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; using AntiRush.Enums; +using CSSharpUtils.Extensions; namespace AntiRush; @@ -9,6 +10,9 @@ public partial class AntiRush : BasePlugin, IPluginConfig { public void OnConfigParsed(AntiRushConfig config) { + if (config.Update()) + config.Reload(); + Config = config; _countdown = Config.Countdown.Select(c => (float)c).ToArray(); } diff --git a/src/AntiRush.csproj b/src/AntiRush.csproj index 0988e07..68e2eef 100644 --- a/src/AntiRush.csproj +++ b/src/AntiRush.csproj @@ -8,6 +8,7 @@ + @@ -18,9 +19,4 @@ - - - - - diff --git a/src/Config.cs b/src/Config.cs index a83ec97..b33dde0 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -5,7 +5,7 @@ namespace AntiRush; public class AntiRushConfig : BasePluginConfig { - public override int Version { get; set; } = 5; + public override int Version { get; set; } = 6; [JsonPropertyName("Messages")] public string Messages { get; set; } = "simple"; [JsonPropertyName("DrawZones")] public bool DrawZones { get; set; } = false; [JsonPropertyName("Warmup")] public bool Warmup { get; set; } = false; @@ -16,4 +16,5 @@ public class AntiRushConfig : BasePluginConfig [JsonPropertyName("RushZones")] public int[] RushZones { get; set; } = [0, 2, 3]; [JsonPropertyName("CampZones")] public int[] CampZones { get; set; } = [1]; [JsonPropertyName("Countdown")] public int[] Countdown { get; set; } = [60, 30, 15, 10, 5, 3, 2, 1]; + [JsonPropertyName("MinPlayers")] public int MinPlayers { get; set; } = 1; } \ No newline at end of file diff --git a/src/Events.cs b/src/Events.cs index 8fd23a8..fb4961c 100644 --- a/src/Events.cs +++ b/src/Events.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; +using CSSharpUtils.Utils; namespace AntiRush; @@ -11,7 +12,8 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) _roundStart = Server.CurrentTime; _bombPlanted = false; - _gameRules ??= Utilities.FindAllEntitiesByDesignerName("cs_gamerules").First().GameRules!; + _gameRules = GameUtils.GetGameRules(); + _minPlayers = Utilities.GetPlayers().Where(p => p.Team == (CsTeam.Terrorist | CsTeam.CounterTerrorist)).ToList().Count >= Config.MinPlayers; foreach (var zone in _zones) { diff --git a/src/Globals.cs b/src/Globals.cs index a6c296e..aa6afde 100644 --- a/src/Globals.cs +++ b/src/Globals.cs @@ -8,7 +8,7 @@ namespace AntiRush; public partial class AntiRush { public override string ModuleName => "AntiRush"; - public override string ModuleVersion => "1.0.7"; + public override string ModuleVersion => "1.0.8"; public override string ModuleAuthor => "https://github.com/oscar-wos/AntiRush"; public AntiRushConfig Config { get; set; } = new(); public Menu.Menu Menu { get; } = new(); @@ -20,4 +20,5 @@ public partial class AntiRush private bool _bombPlanted; private float[] _countdown = []; private CCSGameRules? _gameRules; + private bool _minPlayers; } \ No newline at end of file diff --git a/src/Listeners.cs b/src/Listeners.cs index 534ef83..21506e6 100644 --- a/src/Listeners.cs +++ b/src/Listeners.cs @@ -10,6 +10,9 @@ private void OnTick() if (_gameRules is { WarmupPeriod: true } && !Config.Warmup) return; + if (!_minPlayers) + return; + if (Config.NoRushTime != 0 && !_bombPlanted) { var diff = (Config.NoRushTime + _roundStart) - Server.CurrentTime; From e46dace0a3896b25b73f9e1b53f818086aa521be Mon Sep 17 00:00:00 2001 From: Oscar <29248751+oscar-wos@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:07:28 +0000 Subject: [PATCH 2/3] fix: workflow --- .github/workflows/build.yml | 24 +++++++++++++++++++ .github/workflows/{dotnet.yml => release.yml} | 11 +++++---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{dotnet.yml => release.yml} (95%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3a60e22 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Build + +on: push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build -c Release \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/release.yml similarity index 95% rename from .github/workflows/dotnet.yml rename to .github/workflows/release.yml index ec435f9..b6325e8 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,16 @@ name: Build and Release -on: push +on: + push: + branches: + - main jobs: build: runs-on: ubuntu-latest steps: - - name: checkout all the submodules + - name: Checkout repository uses: actions/checkout@v4 with: submodules: recursive @@ -32,7 +35,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - submodules: recursive + submodules: recursive - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -105,4 +108,4 @@ jobs: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./plugin/${{ github.event.repository.name }}-${{ github.sha }}.zip asset_name: ${{ github.event.repository.name }}.zip - asset_content_type: application/zip \ No newline at end of file + asset_content_type: application/zip From d2ecee2dd5675f4913c2afbf633ab150dd5d57f2 Mon Sep 17 00:00:00 2001 From: Oscar <29248751+oscar-wos@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:13:12 +0000 Subject: [PATCH 3/3] fix: OnBombPlanted event when minPlayers is true --- src/Config.cs | 4 ++-- src/Events.cs | 2 +- src/Json.cs | 4 ++-- src/Listeners.cs | 1 - src/Zone.cs | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Config.cs b/src/Config.cs index b33dde0..25eb597 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -1,5 +1,5 @@ -using CounterStrikeSharp.API.Core; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; +using CounterStrikeSharp.API.Core; namespace AntiRush; diff --git a/src/Events.cs b/src/Events.cs index fb4961c..c3fff02 100644 --- a/src/Events.cs +++ b/src/Events.cs @@ -28,7 +28,7 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) private HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo info) { - if (!Config.DisableOnBombPlant) + if (!Config.DisableOnBombPlant || !_minPlayers) return HookResult.Continue; _bombPlanted = true; diff --git a/src/Json.cs b/src/Json.cs index 6a23dff..a2e45dd 100644 --- a/src/Json.cs +++ b/src/Json.cs @@ -1,5 +1,5 @@ -using CounterStrikeSharp.API.Modules.Utils; -using System.Text.Json; +using System.Text.Json; +using CounterStrikeSharp.API.Modules.Utils; using AntiRush.Enums; namespace AntiRush; diff --git a/src/Listeners.cs b/src/Listeners.cs index 21506e6..c6ffc63 100644 --- a/src/Listeners.cs +++ b/src/Listeners.cs @@ -1,5 +1,4 @@ using CounterStrikeSharp.API; -using AntiRush.Enums; namespace AntiRush; diff --git a/src/Zone.cs b/src/Zone.cs index d7a3e11..b6fa9cf 100644 --- a/src/Zone.cs +++ b/src/Zone.cs @@ -1,8 +1,8 @@ -using System.Drawing; +using Microsoft.Extensions.Localization; +using System.Drawing; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; -using Microsoft.Extensions.Localization; using AntiRush.Enums; namespace AntiRush;