From f765ebbf511387bd01f0a25d0ef005683d4c6b3b Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 2 Aug 2024 23:49:12 -0700 Subject: [PATCH] Register --- .../Rebel/{Ic4Locale.cs => C4Locale.cs} | 2 +- ...otifications.cs => WardenCmdOpenLocale.cs} | 2 +- ...otifications.cs => WardenCmdRollLocale.cs} | 2 +- mod/Jailbreak.Zones/SqlZoneManager.cs | 7 +- .../Logistics/LanguageConfig.cs | 77 +++---------------- ...=> RegisterLanguageExtensions.cs.disabled} | 0 src/Jailbreak/JailbreakServiceCollection.cs | 28 +++++-- 7 files changed, 37 insertions(+), 81 deletions(-) rename lang/Jailbreak.English/Rebel/{Ic4Locale.cs => C4Locale.cs} (88%) rename lang/Jailbreak.English/Warden/{WardenCmdOpenCommandNotifications.cs => WardenCmdOpenLocale.cs} (89%) rename lang/Jailbreak.English/Warden/{WardenCmdRollCommandNotifications.cs => WardenCmdRollLocale.cs} (81%) rename public/Jailbreak.Formatting/Logistics/{RegisterLanguageExtensions.cs => RegisterLanguageExtensions.cs.disabled} (100%) diff --git a/lang/Jailbreak.English/Rebel/Ic4Locale.cs b/lang/Jailbreak.English/Rebel/C4Locale.cs similarity index 88% rename from lang/Jailbreak.English/Rebel/Ic4Locale.cs rename to lang/Jailbreak.English/Rebel/C4Locale.cs index 45031717..138db4fe 100644 --- a/lang/Jailbreak.English/Rebel/Ic4Locale.cs +++ b/lang/Jailbreak.English/Rebel/C4Locale.cs @@ -5,7 +5,7 @@ namespace Jailbreak.English.Rebel; -public class Ic4Locale : IC4Locale, ILanguage { +public class C4Locale : IC4Locale, ILanguage { public IView JihadC4Pickup => new SimpleView { RebelLocale.PREFIX, "You picked up a Jihad C4!" }; diff --git a/lang/Jailbreak.English/Warden/WardenCmdOpenCommandNotifications.cs b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs similarity index 89% rename from lang/Jailbreak.English/Warden/WardenCmdOpenCommandNotifications.cs rename to lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs index 4a93981a..c3dcbc44 100644 --- a/lang/Jailbreak.English/Warden/WardenCmdOpenCommandNotifications.cs +++ b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs @@ -4,7 +4,7 @@ namespace Jailbreak.English.Warden; -public class WardenCmdOpenCommandNotifications : IWardenCmdOpenLocale, +public class WardenCmdOpenLocale : IWardenCmdOpenLocale, ILanguage { public IView CannotOpenYet(int seconds) { return new SimpleView { diff --git a/lang/Jailbreak.English/Warden/WardenCmdRollCommandNotifications.cs b/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs similarity index 81% rename from lang/Jailbreak.English/Warden/WardenCmdRollCommandNotifications.cs rename to lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs index 69c03025..a29bce92 100644 --- a/lang/Jailbreak.English/Warden/WardenCmdRollCommandNotifications.cs +++ b/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs @@ -4,7 +4,7 @@ namespace Jailbreak.English.Warden; -public class WardenCmdRollCommandNotifications : IWardenCmdRollLocale, +public class WardenCmdRollLocale : IWardenCmdRollLocale, ILanguage { public IView Roll(int roll) { return new SimpleView { diff --git a/mod/Jailbreak.Zones/SqlZoneManager.cs b/mod/Jailbreak.Zones/SqlZoneManager.cs index 01eb04d7..470e95ec 100644 --- a/mod/Jailbreak.Zones/SqlZoneManager.cs +++ b/mod/Jailbreak.Zones/SqlZoneManager.cs @@ -22,7 +22,6 @@ public class SqlZoneManager(IZoneFactory factory) : IZoneManager { public void Start(BasePlugin basePlugin) { plugin = basePlugin; - Server.NextFrameAsync(async () => { await createTable(); }); basePlugin.RegisterListener(OnMapStart); basePlugin.RegisterListener(OnMapEnd); @@ -30,6 +29,7 @@ public void Start(BasePlugin basePlugin) { public void Dispose() { plugin.RemoveListener(OnMapStart); + plugin.RemoveListener(OnMapEnd); } public async Task DeleteZone(int zoneId, string map) { @@ -164,7 +164,10 @@ PRIMARY KEY(map, zoneid, pointid)) } private void OnMapStart(string mapname) { - Server.NextFrameAsync(async () => await LoadZones(mapname)); + Server.NextFrameAsync(async () => { + await createTable(); + await LoadZones(mapname); + }); } private MySqlCommand queryAllZones(string map, ZoneType type) { diff --git a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs index ab3c0830..df057de7 100644 --- a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs +++ b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs @@ -9,74 +9,6 @@ public LanguageConfig(IServiceCollection collection) { this.collection = collection; } - // public void WithGenericCommand() - // where TGenericCommand : class, ILanguage, - // IGenericCmdLocale { - // collection.AddSingleton(); - // } - // - // public void WithWarden() - // where TWarden : class, ILanguage, IWardenLocale { - // collection.AddSingleton(); - // } - // - // public void WithRebel() - // where TRebel : class, ILanguage, IRebelLocale { - // collection.AddSingleton(); - // } - // - // public void WithJihadC4() - // where TJihadC4 : class, ILanguage, IC4Locale { - // collection.AddSingleton(); - // } - // - // public void WithSpecialDay() - // where TSpecialDay : class, ILanguage, ISDLocale { - // collection.AddSingleton(); - // } - // - // public void WithLogging() - // where TLogging : class, ILanguage, ILogLocale { - // collection.AddSingleton(); - // } - // - // public void WithRollCommand() - // where TRollCommand : class, ILanguage, IWardenCmdRollLocale { - // collection.AddSingleton(); - // } - // - // public void WithLastRequest() - // where TLastRequest : class, ILanguage, ILRLocale { - // collection.AddSingleton(); - // } - // - // public void WithSpecialTreatment() - // where TSpecialTreatment : class, ILanguage, - // IWardenSTLocale { - // collection - // .AddSingleton(); - // } - // - // public void WithMute() - // where TMute : class, ILanguage, IWardenPeaceLocale { - // collection.AddSingleton(); - // } - // - // public void WithRaceLR() - // where TRaceLR : class, ILanguage, ILRRaceLocale { - // collection.AddSingleton(); - // } - // - // public void WithLastGuard() - // where TLastGuard : class, ILanguage, ILGLocale { - // collection.AddSingleton(); - // } - // - // public void WithOpenCommand() - // where TOpenCommand : class, ILanguage, IWardenCmdOpenLocale { - // collection.AddSingleton(); - // } - public void Configure(Dictionary serviceMap) { foreach (var (service, implementation) in serviceMap) { var method = typeof(IServiceCollection).GetMethod("AddSingleton") @@ -84,4 +16,13 @@ public void Configure(Dictionary serviceMap) { method?.Invoke(collection, null); } } +} + +public static class ServiceCollectionExtensions { + public static void AddLanguage(this IServiceCollection services, + Action> configure) + where TDialect : class, IDialect { + var config = new LanguageConfig(services); + configure(config); + } } \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Logistics/RegisterLanguageExtensions.cs b/public/Jailbreak.Formatting/Logistics/RegisterLanguageExtensions.cs.disabled similarity index 100% rename from public/Jailbreak.Formatting/Logistics/RegisterLanguageExtensions.cs rename to public/Jailbreak.Formatting/Logistics/RegisterLanguageExtensions.cs.disabled diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 0d3e2a43..9f7de81c 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -47,10 +47,26 @@ public void ConfigureServices(IServiceCollection serviceCollection) { serviceCollection.AddJailbreakSpecialDay(); serviceCollection.AddJailbreakZones(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + // Add in english localization serviceCollection.AddLanguage(config => { var serviceMap = new Dictionary { - { typeof(IC4Locale), typeof(Ic4Locale) }, + { typeof(IC4Locale), typeof(C4Locale) }, { typeof(IGenericCmdLocale), typeof(GenericCmdLocale) }, { typeof(ILGLocale), typeof(IlgLocale) }, { typeof(ILRCFLocale), typeof(CoinflipLocale) }, @@ -60,13 +76,9 @@ public void ConfigureServices(IServiceCollection serviceCollection) { { typeof(ILogLocale), typeof(LogLocale) }, { typeof(IRebelLocale), typeof(RebelLocale) }, { typeof(ISDLocale), typeof(IsdLocale) }, - { typeof(IWardenSTLocale), typeof(IstLocale) }, { - typeof(IWardenCmdOpenLocale), - typeof(WardenCmdOpenCommandNotifications) - }, { - typeof(IWardenCmdRollLocale), - typeof(WardenCmdRollCommandNotifications) - }, + { typeof(IWardenSTLocale), typeof(IstLocale) }, + { typeof(IWardenCmdOpenLocale), typeof(WardenCmdOpenLocale) }, + { typeof(IWardenCmdRollLocale), typeof(WardenCmdRollLocale) }, { typeof(IWardenLocale), typeof(WardenLocale) }, { typeof(IWardenPeaceLocale), typeof(WardenPeaceLocale) } };