From abc840958075990b2fc16505a70b97525ae9b4aa Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 8 Sep 2024 01:29:33 -0700 Subject: [PATCH] Auto-Format --- Commands/CommandManager.cs | 2 +- Commands/GangCommand.cs | 3 +- GangsAPI/Data/Command/CommandInfoWrapper.cs | 1 - GangsAPI/Data/ICacher.cs | 1 + GangsAPI/MSG.cs | 3 +- GangsAPI/Services/Gang/IGangManager.cs | 3 +- GangsAPI/Services/Gang/IGangStatManager.cs | 1 - GangsAPI/Services/IStatManager.cs | 3 +- GangsAPI/Services/Player/IPlayerManager.cs | 3 +- GangsImpl/AbstractDB/AbstractDBGangManager.cs | 32 +++++++++---------- .../AbstractDB/AbstractDBPlayerManager.cs | 24 +++++++------- GangsImpl/Mock/MockGangManager.cs | 6 ++-- GangsImpl/SQLite/SQLiteGangManager.cs | 1 - .../Commands/Command/Concrete/GangTests.cs | 3 +- GangsTest/API/Services/Gang/CreationTests.cs | 1 - .../API/Services/Gang/PersistenceTests.cs | 1 - GangsTest/TestLocale/FormatTests.cs | 4 +-- GangsTest/TestLocale/LocaleImplData.cs | 2 +- GangsTest/TestLocale/ParityTests.cs | 6 ++-- GangsTest/TestLocale/StringLocalizer.cs | 15 +++++---- 20 files changed, 53 insertions(+), 62 deletions(-) diff --git a/Commands/CommandManager.cs b/Commands/CommandManager.cs index 7ce303d..9f5894b 100644 --- a/Commands/CommandManager.cs +++ b/Commands/CommandManager.cs @@ -37,7 +37,7 @@ private void Server.NextFrameAsync(async () => { var result = await ProcessCommand(wrapper, wrappedInfo); if (result == CommandResult.PLAYER_ONLY) - executor?.PrintToChat(Locale.Get(GangsAPI.MSG.GENERIC_PLAYER_ONLY)); + executor?.PrintToChat(Locale.Get(MSG.GENERIC_PLAYER_ONLY)); }); } } \ No newline at end of file diff --git a/Commands/GangCommand.cs b/Commands/GangCommand.cs index 3e64c81..0765fd7 100644 --- a/Commands/GangCommand.cs +++ b/Commands/GangCommand.cs @@ -58,9 +58,8 @@ public async Task Execute(PlayerWrapper? executor, return CommandResult.SUCCESS; } - if (!sub.TryGetValue(info[1], out var command)) { + if (!sub.TryGetValue(info[1], out var command)) return CommandResult.UNKNOWN_COMMAND; - } var newInfo = new CommandInfoWrapper(info, 1); return await command.Execute(executor, newInfo); diff --git a/GangsAPI/Data/Command/CommandInfoWrapper.cs b/GangsAPI/Data/Command/CommandInfoWrapper.cs index 6de0832..e6464a9 100644 --- a/GangsAPI/Data/Command/CommandInfoWrapper.cs +++ b/GangsAPI/Data/Command/CommandInfoWrapper.cs @@ -1,5 +1,4 @@ using CounterStrikeSharp.API.Modules.Commands; -using Microsoft.Extensions.Localization; namespace GangsAPI.Data.Command; diff --git a/GangsAPI/Data/ICacher.cs b/GangsAPI/Data/ICacher.cs index 47cfa0a..386332d 100644 --- a/GangsAPI/Data/ICacher.cs +++ b/GangsAPI/Data/ICacher.cs @@ -4,6 +4,7 @@ public interface ICacher { [Obsolete] void ClearCache(); + [Obsolete] Task Load(); } \ No newline at end of file diff --git a/GangsAPI/MSG.cs b/GangsAPI/MSG.cs index 03698de..70e16f7 100644 --- a/GangsAPI/MSG.cs +++ b/GangsAPI/MSG.cs @@ -1,5 +1,4 @@ -using GangsAPI.Data.Command; -using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Localization; namespace GangsAPI; diff --git a/GangsAPI/Services/Gang/IGangManager.cs b/GangsAPI/Services/Gang/IGangManager.cs index 5444721..aa759e7 100644 --- a/GangsAPI/Services/Gang/IGangManager.cs +++ b/GangsAPI/Services/Gang/IGangManager.cs @@ -1,5 +1,4 @@ -using GangsAPI.Data; -using GangsAPI.Data.Gang; +using GangsAPI.Data.Gang; namespace GangsAPI.Services.Gang; diff --git a/GangsAPI/Services/Gang/IGangStatManager.cs b/GangsAPI/Services/Gang/IGangStatManager.cs index 1300a32..cefba25 100644 --- a/GangsAPI/Services/Gang/IGangStatManager.cs +++ b/GangsAPI/Services/Gang/IGangStatManager.cs @@ -1,4 +1,3 @@ -using GangsAPI.Data; using GangsAPI.Data.Gang; using GangsAPI.Data.Stat; diff --git a/GangsAPI/Services/IStatManager.cs b/GangsAPI/Services/IStatManager.cs index 05a3031..1b5ebaa 100644 --- a/GangsAPI/Services/IStatManager.cs +++ b/GangsAPI/Services/IStatManager.cs @@ -1,5 +1,4 @@ -using GangsAPI.Data; -using GangsAPI.Data.Stat; +using GangsAPI.Data.Stat; namespace GangsAPI.Services; diff --git a/GangsAPI/Services/Player/IPlayerManager.cs b/GangsAPI/Services/Player/IPlayerManager.cs index 7236443..536d7dd 100644 --- a/GangsAPI/Services/Player/IPlayerManager.cs +++ b/GangsAPI/Services/Player/IPlayerManager.cs @@ -1,5 +1,4 @@ -using GangsAPI.Data; -using GangsAPI.Data.Gang; +using GangsAPI.Data.Gang; namespace GangsAPI.Services.Player; diff --git a/GangsImpl/AbstractDB/AbstractDBGangManager.cs b/GangsImpl/AbstractDB/AbstractDBGangManager.cs index f7baf30..7d100e8 100644 --- a/GangsImpl/AbstractDB/AbstractDBGangManager.cs +++ b/GangsImpl/AbstractDB/AbstractDBGangManager.cs @@ -4,7 +4,6 @@ using GangsAPI.Data.Gang; using GangsAPI.Services.Gang; using GangsAPI.Services.Player; -using Mock; namespace GenericDB; @@ -13,8 +12,6 @@ public abstract class AbstractDBGangManager(IPlayerManager playerMgr, : IGangManager { protected DbConnection Connection = null!; protected DbTransaction? Transaction; - public void ClearCache() { } - public Task Load() { return Task.CompletedTask; } public void Start(BasePlugin? plugin, bool hotReload) { Connection = CreateDbConnection(connectionString); @@ -37,14 +34,6 @@ public void Start(BasePlugin? plugin, bool hotReload) { } } - abstract protected DbConnection CreateDbConnection(string connectionString); - - virtual protected string CreateTableQuery(string tableName, bool inTesting) { - return inTesting ? - $"CREATE TEMPORARY TABLE IF NOT EXISTS {tableName} (GangId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255) NOT NULL)" : - $"CREATE TABLE IF NOT EXISTS {tableName} (GangId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255) NOT NULL)"; - } - public async Task> GetGangs() { var query = $"SELECT * FROM {table}"; return await Connection.QueryAsync(query, transaction: Transaction); @@ -79,11 +68,6 @@ public async Task DeleteGang(int id) { return await Connection.ExecuteAsync(query, new { id }, Transaction) > 0; } - virtual protected async Task GetLastId() { - return await Connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID()", - transaction: Transaction); - } - public async Task CreateGang(string name, ulong owner) { var player = await playerMgr.GetPlayer(owner); if (player == null) return null; @@ -105,4 +89,20 @@ public void Dispose() { Transaction?.Dispose(); Connection.Dispose(); } + + public void ClearCache() { } + public Task Load() { return Task.CompletedTask; } + + abstract protected DbConnection CreateDbConnection(string connectionString); + + virtual protected string CreateTableQuery(string tableName, bool inTesting) { + return inTesting ? + $"CREATE TEMPORARY TABLE IF NOT EXISTS {tableName} (GangId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255) NOT NULL)" : + $"CREATE TABLE IF NOT EXISTS {tableName} (GangId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255) NOT NULL)"; + } + + virtual protected async Task GetLastId() { + return await Connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID()", + transaction: Transaction); + } } \ No newline at end of file diff --git a/GangsImpl/AbstractDB/AbstractDBPlayerManager.cs b/GangsImpl/AbstractDB/AbstractDBPlayerManager.cs index fa0c8af..9d31552 100644 --- a/GangsImpl/AbstractDB/AbstractDBPlayerManager.cs +++ b/GangsImpl/AbstractDB/AbstractDBPlayerManager.cs @@ -3,7 +3,6 @@ using Dapper; using GangsAPI.Data.Gang; using GangsAPI.Services.Player; -using Mock; namespace GenericDB; @@ -11,8 +10,6 @@ public abstract class AbstractDBPlayerManager(string connectionString, string table = "gang_players", bool testing = false) : IPlayerManager { protected DbConnection Connection = null!; protected DbTransaction? Transaction; - public void ClearCache() { } - public Task Load() { return Task.CompletedTask; } public void Start(BasePlugin? plugin, bool hotReload) { Connection = CreateDbConnection(connectionString); @@ -35,14 +32,6 @@ public void Start(BasePlugin? plugin, bool hotReload) { } } - abstract protected DbConnection CreateDbConnection(string connectionString); - - virtual protected string CreateTableQuery(string tableName, bool inTesting) { - return inTesting ? - $"CREATE TEMPORARY TABLE IF NOT EXISTS {tableName} (Steam INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255), GangId INT, GangRank INT)" : - $"CREATE TABLE IF NOT EXISTS {tableName} (Steam INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255), GangId INT, GangRank INT)"; - } - public void Dispose() { Transaction?.Dispose(); Connection.Dispose(); @@ -58,7 +47,7 @@ public async Task CreatePlayer(ulong steamId, string? name = null) { var existing = await GetPlayer(steamId, false); if (existing != null) return existing; - var player = new DBPlayer() { Steam = steamId, Name = name }; + var player = new DBPlayer { Steam = steamId, Name = name }; var query = $"INSERT INTO {table} (Steam, Name) VALUES (@Steam, @Name)"; await Connection.ExecuteAsync(query, player, Transaction); return player; @@ -87,4 +76,15 @@ public async Task DeletePlayer(ulong steamId) { return await Connection.ExecuteAsync(query, new { steamId }, Transaction) == 1; } + + public void ClearCache() { } + public Task Load() { return Task.CompletedTask; } + + abstract protected DbConnection CreateDbConnection(string connectionString); + + virtual protected string CreateTableQuery(string tableName, bool inTesting) { + return inTesting ? + $"CREATE TEMPORARY TABLE IF NOT EXISTS {tableName} (Steam INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255), GangId INT, GangRank INT)" : + $"CREATE TABLE IF NOT EXISTS {tableName} (Steam INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(255), GangId INT, GangRank INT)"; + } } \ No newline at end of file diff --git a/GangsImpl/Mock/MockGangManager.cs b/GangsImpl/Mock/MockGangManager.cs index c643956..8b8a05e 100644 --- a/GangsImpl/Mock/MockGangManager.cs +++ b/GangsImpl/Mock/MockGangManager.cs @@ -58,13 +58,13 @@ public virtual async Task DeleteGang(int id) { return gang.Clone() as IGang; } + public virtual void Start(BasePlugin? plugin, bool hotReload) { } + public virtual void Dispose() { } + public virtual void ClearCache() { CachedGangs.Clear(); } public virtual Task Load() { CachedGangs.UnionWith(BackendGangs); return Task.CompletedTask; } - - public virtual void Start(BasePlugin? plugin, bool hotReload) { } - public virtual void Dispose() { } } \ No newline at end of file diff --git a/GangsImpl/SQLite/SQLiteGangManager.cs b/GangsImpl/SQLite/SQLiteGangManager.cs index aaba31f..0c1a77d 100644 --- a/GangsImpl/SQLite/SQLiteGangManager.cs +++ b/GangsImpl/SQLite/SQLiteGangManager.cs @@ -1,6 +1,5 @@ using System.Data.Common; using Dapper; -using GangsAPI.Data.Gang; using GangsAPI.Services.Player; using GenericDB; using Microsoft.Data.Sqlite; diff --git a/GangsTest/API/Services/Commands/Command/Concrete/GangTests.cs b/GangsTest/API/Services/Commands/Command/Concrete/GangTests.cs index f93202a..f6db713 100644 --- a/GangsTest/API/Services/Commands/Command/Concrete/GangTests.cs +++ b/GangsTest/API/Services/Commands/Command/Concrete/GangTests.cs @@ -6,7 +6,8 @@ namespace GangsTest.API.Services.Commands.Command.Concrete; -public class GangTests(ICommandManager commands, IGangManager gangMgr, IStringLocalizer locale) +public class GangTests(ICommandManager commands, IGangManager gangMgr, + IStringLocalizer locale) : TestParent(commands, new GangCommand(gangMgr, locale)) { [Fact] public async Task Gang_TestBase() { diff --git a/GangsTest/API/Services/Gang/CreationTests.cs b/GangsTest/API/Services/Gang/CreationTests.cs index c933ff5..68cf410 100644 --- a/GangsTest/API/Services/Gang/CreationTests.cs +++ b/GangsTest/API/Services/Gang/CreationTests.cs @@ -1,7 +1,6 @@ using GangsAPI.Data.Gang; using GangsAPI.Services.Gang; using GangsAPI.Services.Player; -using MathNet.Numerics.Random; namespace GangsTest.API.Services.Gang; diff --git a/GangsTest/API/Services/Gang/PersistenceTests.cs b/GangsTest/API/Services/Gang/PersistenceTests.cs index f22dbab..c9c3971 100644 --- a/GangsTest/API/Services/Gang/PersistenceTests.cs +++ b/GangsTest/API/Services/Gang/PersistenceTests.cs @@ -1,5 +1,4 @@ using GangsAPI.Services.Gang; -using GangsAPI.Services.Player; namespace GangsTest.API.Services.Gang; diff --git a/GangsTest/TestLocale/FormatTests.cs b/GangsTest/TestLocale/FormatTests.cs index bfd8ac8..124fce6 100644 --- a/GangsTest/TestLocale/FormatTests.cs +++ b/GangsTest/TestLocale/FormatTests.cs @@ -1,12 +1,10 @@ using System.Text.RegularExpressions; using GangsAPI; using Microsoft.Extensions.Localization; -using Xunit.Abstractions; namespace GangsTest.TestLocale; -public partial class FormatTests(IStringLocalizer localizer, - ITestOutputHelper output) { +public partial class FormatTests(IStringLocalizer localizer) { [Fact] public void Handles_Formatting() { var perm = "@test/permission"; diff --git a/GangsTest/TestLocale/LocaleImplData.cs b/GangsTest/TestLocale/LocaleImplData.cs index fdfb3e2..572ba78 100644 --- a/GangsTest/TestLocale/LocaleImplData.cs +++ b/GangsTest/TestLocale/LocaleImplData.cs @@ -4,6 +4,6 @@ namespace GangsTest.TestLocale; public class LocaleImplData : TheoryData { public LocaleImplData() { - foreach (var key in Enum.GetValues()) { Add(key.Key()); } + foreach (var key in Enum.GetValues()) Add(key.Key()); } } \ No newline at end of file diff --git a/GangsTest/TestLocale/ParityTests.cs b/GangsTest/TestLocale/ParityTests.cs index b949610..2355512 100644 --- a/GangsTest/TestLocale/ParityTests.cs +++ b/GangsTest/TestLocale/ParityTests.cs @@ -4,6 +4,9 @@ namespace GangsTest.TestLocale; public class ParityTests(IStringLocalizer localizer) { + private readonly IEnumerable localeKeys = + Enum.GetValues().Select(s => s.Key()); + [Theory] [ClassData(typeof(LocaleImplData))] public void Localize_Exists_FromImpl(string key) { @@ -16,7 +19,4 @@ public void Localize_Exists_FromFile(string key, string _) { // Make sure we have an enum whose key is the same as the key in the file Assert.Contains(key, localeKeys); } - - private readonly IEnumerable localeKeys = - Enum.GetValues().Select(s => s.Key()); } \ No newline at end of file diff --git a/GangsTest/TestLocale/StringLocalizer.cs b/GangsTest/TestLocale/StringLocalizer.cs index 98e6917..6190e91 100644 --- a/GangsTest/TestLocale/StringLocalizer.cs +++ b/GangsTest/TestLocale/StringLocalizer.cs @@ -5,11 +5,11 @@ namespace GangsTest.TestLocale; public partial class StringLocalizer : IStringLocalizer { - private readonly IStringLocalizer localizer; - internal static readonly StringLocalizer Instance = new(new LocalFileLocalizerFactory()); + private readonly IStringLocalizer localizer; + public StringLocalizer(IStringLocalizerFactory factory) { var type = typeof(StringLocalizer); var assemblyName = @@ -22,9 +22,11 @@ public StringLocalizer(IStringLocalizerFactory factory) { public LocalizedString this[string name, params object[] arguments] => new(name, string.Format(GetString(name).Value, arguments)); - public IEnumerable GetAllStrings(bool includeParentCultures) - => localizer.GetAllStrings(includeParentCultures) + public IEnumerable + GetAllStrings(bool includeParentCultures) { + return localizer.GetAllStrings(includeParentCultures) .Select(str => GetString(str.Name)); + } private LocalizedString GetString(string name) { // Replace %[key]% with that key's value @@ -32,13 +34,12 @@ private LocalizedString GetString(string name) { // other locale values can use %prefix% to reference it. var value = localizer[name].Value; var matches = Percents().Matches(value); - foreach (Match match in matches) { + foreach (Match match in matches) // Check if the key exists try { var key = match.Groups[0].Value; value = value.Replace(key, localizer[key[1..^1]].Value); - } catch (NullReferenceException) { continue; } - } + } catch (NullReferenceException) { } return new LocalizedString(name, value); }