Skip to content

Config → IPluginConfig: consolidated config, model split, conventions, ILogger#12

Merged
Ravid-A merged 14 commits into
mainfrom
feat/config-ipluginconfig
Jun 8, 2026
Merged

Config → IPluginConfig: consolidated config, model split, conventions, ILogger#12
Ravid-A merged 14 commits into
mainfrom
feat/config-ipluginconfig

Conversation

@Ravid-A

@Ravid-A Ravid-A commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Replaces the three hand-rolled JSON config readers (main config, weapon lists, votes) with a single CounterStrikeSharp IPluginConfig<RetakesAllocatorConfig> consolidated config, then cleans up the module layer around it.

Breaking change for existing servers: configuration moves to the single CounterStrikeSharp-managed file at addons/counterstrikesharp/configs/plugins/RetakesAllocator/RetakesAllocator.json. The old configs/retakes_allocator.json, configs/weapons/*.json, and configs/votes.json files are no longer read.

What's included

Config → IPluginConfig

  • RetakesAllocatorConfig : BasePluginConfig with a labeled JSON section per subsystem; Core implements IPluginConfig<…> and loads/applies config in OnConfigParsed (before Load, and on file-watch hot reload).
  • Pure, unit-tested ConfigApplier.Apply copies config into the static state the rest of the plugin reads (weapon lists mutated in place to preserve held references).
  • Idempotent vote-command (de)registration so hot reload doesn't leak/duplicate commands.
  • The three manual readers are deleted; css_weapons_reload re-applies the in-memory config.

Module-layer cleanup

  • Models (Weapon, Vote, Nades) split into Modules/Models/; config DTOs consolidated under Modules.Config.
  • Project-wide C# naming conventions: public members to PascalCase (PREFIX→Prefix, vote→Vote, player→Controller, currentVote→CurrentVote), private fields to _camelCase, underscore locals to camelCase. Fixed the RequiredPrecentage typo and a dead O(N²) loop in Votes_OnMapStart.
  • Logging moved from a custom Console-based PrintToServer / throwing ThrowError to Microsoft.Extensions.Logging via BasePlugin.Logger, with structured templates and appropriate levels. Note: previously-fatal paths (DB connect failure, invalid config) now log and continue instead of throwing.

Build / deps / CI

  • MySqlConnector referenced via NuGet instead of a committed .dll; CounterStrikeSharp bumped to 1.0.360 (API 360).
  • Plugin output routed to build/ and a tag-triggered GitHub release job that packages it.
  • Added RetakesAllocator.sln (plugin + tests); the test project is excluded from solution/release builds and built only when running dotnet test.

Docs

  • README rewritten for the consolidated config (with the real generated default); plan updated with a follow-up logging task.

Testing

  • dotnet build RetakesAllocator.sln -c Release — clean (plugin only).
  • dotnet test tests/RetakesAllocator.Tests/RetakesAllocator.Tests.csproj — 16 passing.

Ravid-A added 14 commits June 8, 2026 16:16
Adds ConfigApplier.Apply which copies a RetakesAllocatorConfig into the
static state the rest of the plugin reads (Utils.PREFIX, Core.NadesConfig,
Allocator weapon lists, Votes settings). Weapon lists are mutated in-place
to preserve the existing list instances other code holds by reference.
Utils.PREFIX/PREFIX_CON now default to string.Empty instead of reading
Core.Config (which is null until config is applied). Also adds a
StaticState xUnit collection to sequence test classes that share static
state, preventing parallel-run interference.
…r via NuGet

Reference MySqlConnector through a NuGet PackageReference instead of the committed MySqlConnector.dll (a 2.3.0-beta build). CopyLocalLockFileAssemblies still ships it to the plugin build output for deployment, so no binary needs to live in the repo.
… via ILogger

A broad cleanup of the module layer, building on the IPluginConfig migration:

- Consolidate the config DTOs (ConnectionConfig/PrefixConfig/PistolRoundConfig/
  NadesConfig) alongside RetakesAllocatorConfig under RetakesAllocator.Modules.Config
  and delete the three hand-rolled JSON readers (Config.cs, Votes/Config.cs,
  Weapons/Config.cs).
- Move the persisted model types (Weapon, Vote, Nades) into Modules/Models/.
- Apply C# naming conventions across the layer: public members to PascalCase
  (PREFIX -> Prefix, vote -> Vote, player -> Controller, currentVote -> CurrentVote,
  playerIndex -> PlayerIndex), private fields to _camelCase (votes -> _votes,
  VotePercentage -> _votePercentage, IgnoreRoundEnd -> _ignoreRoundEnd), and
  underscore locals/params to camelCase (players_t -> playersT, map_name -> mapName).
- Replace the custom Console-based PrintToServer and the throwing ThrowError helper
  with Microsoft.Extensions.Logging via BasePlugin.Logger: structured, level-
  appropriate logs (Information for lifecycle, Error with the exception for DB
  failures, Debug for spawn-skip diagnostics). Fatal paths now log and degrade
  instead of throwing.
- Remove the dead O(N^2) outer loop in Votes_OnMapStart and fix the RequiredPrecentage
  typo to RequiredPercentage.

Build clean, 16 tests green.
Add RetakesAllocator.sln referencing the plugin and test projects so the test project is visible in Rider, and ignore *.DotSettings.user.
…se requirements

Rewrite the README Config/Weapons sections for the single CounterStrikeSharp-managed config file (with the real generated default), and bump the CI release notes to require CounterStrikeSharp v1.0.360 / API 360.
Keep RetakesAllocator.Tests visible in the solution but remove its Build.0 entries so a solution/Release build compiles only the plugin. Mark the test csproj non-packable/non-publishable; it is built only when tests are run explicitly via dotnet test.
@Ravid-A
Ravid-A merged commit 0b418ed into main Jun 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant