Skip to content

Commit aa22f9e

Browse files
authored
Dev (#15)
* [AUTOMATIC] push version to 2.0.5 * idk * clean code * oupsi * [AUTOMATIC] push version to 2.0.6 * [AUTOMATIC] push version to 2.0.6 * remove LabApi beta
1 parent 754bea0 commit aa22f9e

11 files changed

Lines changed: 80 additions & 71 deletions

File tree

EventHandler.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase
111111
Menu.LoadForPlayer(hub, menu.TryGetSubMenu(ss.SettingId));
112112
else
113113
{
114-
ServerSpecificSettingBase s = menu.Settings.FirstOrDefault(s => s.SettingId == ss.SettingId);
115-
if (menu.SettingsSync[hub].Any(x => x.SettingId == ss.SettingId))
116-
menu.SettingsSync[hub][menu.SettingsSync[hub].FindIndex(x => x.SettingId == ss.SettingId)] = ss;
114+
if (menu.InternalSettingsSync[hub].Any(x => x.SettingId == ss.SettingId))
115+
menu.InternalSettingsSync[hub][menu.InternalSettingsSync[hub].FindIndex(x => x.SettingId == ss.SettingId)] = ss;
117116
else
118-
menu.SettingsSync[hub].Add(ss);
117+
menu.InternalSettingsSync[hub].Add(ss);
118+
ServerSpecificSettingBase s =
119+
!menu.SentSettings.TryGetValue(hub, out ServerSpecificSettingBase[] customSettings)
120+
? menu.Settings.FirstOrDefault(b => b.SettingId == ss.SettingId)
121+
: customSettings.FirstOrDefault(b => b.SettingId == ss.SettingId);
119122
switch (s)
120123
{
121124
case Button wBtn:
@@ -157,11 +160,11 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase
157160
#else
158161
Log.Debug(e.ToString());
159162
#endif
160-
if (Plugin.StaticConfig.ShowErrorToClient)
163+
if (Plugin.Instance.Config.ShowErrorToClient)
161164
{
162165
Features.Utils.SendToPlayer(hub, null, new ServerSpecificSettingBase[]
163166
{
164-
new SSTextArea(-5, $"<color=red><b>{Plugin.GetTranslation().ServerError}\n{((hub.serverRoles.RemoteAdmin || Plugin.StaticConfig.ShowFullErrorToClient) && Plugin.StaticConfig.ShowFullErrorToModerators ? e.ToString() : Plugin.GetTranslation().NoPermission)}</b></color>", SSTextArea.FoldoutMode.CollapsedByDefault, Plugin.GetTranslation().ServerError),
167+
new SSTextArea(-5, $"<color=red><b>{Plugin.GetTranslation().ServerError}\n{((hub.serverRoles.RemoteAdmin || Plugin.Instance.Config.ShowFullErrorToClient) && Plugin.Instance.Config.ShowFullErrorToModerators ? e.ToString() : Plugin.GetTranslation().NoPermission)}</b></color>", SSTextArea.FoldoutMode.CollapsedByDefault, Plugin.GetTranslation().ServerError),
165168
new SSButton(-999, Plugin.GetTranslation().ReloadButton.Label, Plugin.GetTranslation().ReloadButton.ButtonText)
166169
});
167170
}

Features/Log.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static void Info(string message)
3030
/// <param name="message">The message to be sent.</param>
3131
internal static void Debug(object message)
3232
{
33-
if (Plugin.StaticConfig?.Debug ?? false)
33+
if (Plugin.Instance.Config?.Debug ?? false)
3434
Send($"[SSMenuSystem] {message}", LogLevel.Debug, ConsoleColor.Green);
3535
}
3636

@@ -41,7 +41,7 @@ internal static void Debug(object message)
4141
/// <param name="message">The message to be sent.</param>
4242
internal static void Debug(string message)
4343
{
44-
if (Plugin.StaticConfig?.Debug ?? false)
44+
if (Plugin.Instance.Config?.Debug ?? false)
4545
Send($"[SSMenuSystem] {message}", LogLevel.Debug, ConsoleColor.Green);
4646
}
4747

Features/Menu.cs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal static void RegisterQueuedAssemblies()
7373
/// </summary>
7474
public static void QueueOrRegister()
7575
{
76-
if (Plugin.StaticConfig is null)
76+
if (Plugin.Instance.Config is null)
7777
{
7878
Assembly assembly = Assembly.GetCallingAssembly();
7979
if (!_waitingAssemblies.Contains(assembly))
@@ -94,7 +94,7 @@ public static void QueueOrRegister()
9494
/// <param name="assembly">The target <see cref="Assembly"/>.</param>
9595
private static void Register(Assembly assembly)
9696
{
97-
if (Plugin.StaticConfig is null) // plugin is not loaded.
97+
if (Plugin.Instance.Config is null) // plugin is not loaded.
9898
{
9999
if (!_waitingAssemblies.Contains(assembly))
100100
_waitingAssemblies.Enqueue(assembly);
@@ -109,7 +109,7 @@ private static void Register(Assembly assembly)
109109
if (type == typeof(AssemblyMenu)) // only used for comptability (throw error when loaded)
110110
continue;
111111

112-
if (type == typeof(MainExample) && (!Plugin.StaticConfig.EnableExamples))
112+
if (type == typeof(MainExample) && (!Plugin.Instance.Config.EnableExamples))
113113
continue;
114114

115115
if (type.IsAbstract || type.IsInterface)
@@ -165,7 +165,7 @@ public static void Register(Menu menu)
165165
{
166166
if (menu == null)
167167
return;
168-
if (menu.MenuRelated == typeof(MainExample) && !Plugin.StaticConfig.EnableExamples)
168+
if (menu.MenuRelated == typeof(MainExample) && !Plugin.Instance.Config.EnableExamples)
169169
return;
170170

171171
Log.Debug($"loading Server Specific menu {menu.Name}...");
@@ -259,7 +259,13 @@ internal static void UnregisterAll()
259259
/// </summary>
260260
public abstract ServerSpecificSettingBase[] Settings { get; }
261261

262-
/// <summary>
262+
/// <summary>
263+
/// Gets all settings sent to the refHub. (only in the case of one GetSettings is not null or empty)
264+
///
265+
/// </summary>
266+
internal readonly Dictionary<ReferenceHub, ServerSpecificSettingBase[]> SentSettings = new();
267+
268+
/// <summary>
263269
/// Gets the Hash of menu, based on <see cref="Name"/>. Mainly used to seperate menu settings for client.
264270
/// </summary>
265271
public int Hash => Mathf.Abs(Name.GetHashCode() % 100000);
@@ -288,7 +294,7 @@ private static ServerSpecificSettingBase[] GetMainMenu(ReferenceHub hub)
288294
{
289295
List<ServerSpecificSettingBase> mainMenu = new();
290296

291-
if (Plugin.StaticConfig.AllowPinnedContent)
297+
if (Plugin.Instance.Config.AllowPinnedContent)
292298
mainMenu.AddRange(Pinned.Values.SelectMany(pin => pin));
293299

294300
if (LoadedMenus.Where(x => x.CheckAccess(hub)).IsEmpty())
@@ -310,10 +316,10 @@ private List<ServerSpecificSettingBase> GetSettings(ReferenceHub hub)
310316
{
311317
List<ServerSpecificSettingBase> settings = new();
312318

313-
if (Plugin.StaticConfig.AllowPinnedContent)
319+
if (Plugin.Instance.Config.AllowPinnedContent)
314320
settings.AddRange(Pinned.Values.SelectMany(pin => pin));
315321

316-
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) != this || Plugin.StaticConfig.ForceMainMenuEvenIfOnlyOne)
322+
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) != this || Plugin.Instance.Config.ForceMainMenuEvenIfOnlyOne)
317323
{
318324
if (MenuRelated != null)
319325
settings.Add(new SSButton(0, string.Format(Plugin.GetTranslation().ReturnTo.Label, Menu.GetMenu(MenuRelated)?.Name ?? "Unknown"),
@@ -323,7 +329,7 @@ private List<ServerSpecificSettingBase> GetSettings(ReferenceHub hub)
323329
Plugin.GetTranslation().ReturnToMenu.ButtonText));
324330
}
325331

326-
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) == this && !Plugin.StaticConfig.ForceMainMenuEvenIfOnlyOne)
332+
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) == this && !Plugin.Instance.Config.ForceMainMenuEvenIfOnlyOne)
327333
settings.Add(new SSGroupHeader(Name));
328334
else
329335
{
@@ -334,7 +340,7 @@ private List<ServerSpecificSettingBase> GetSettings(ReferenceHub hub)
334340
foreach (Menu s in LoadedMenus.Where(x => x.MenuRelated == GetType() && x != this))
335341
settings.Add(new SSButton(s.Id, string.Format(Plugin.GetTranslation().OpenMenu.Label, s.Name), Plugin.GetTranslation().OpenMenu.ButtonText, null, string.IsNullOrEmpty(Description) ? null : Description));
336342

337-
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) != this || Plugin.StaticConfig.ForceMainMenuEvenIfOnlyOne)
343+
if (LoadedMenus.First(x => x.CheckAccess(hub) && x.MenuRelated == null) != this || Plugin.Instance.Config.ForceMainMenuEvenIfOnlyOne)
338344
settings.Add(new SSGroupHeader(Name, false, Description));
339345

340346
if (this is AssemblyMenu assemblyMenu &&
@@ -346,16 +352,17 @@ private List<ServerSpecificSettingBase> GetSettings(ReferenceHub hub)
346352
return settings;
347353
}
348354

349-
if (Settings == null || Settings.IsEmpty())
355+
ServerSpecificSettingBase[] oSettings = GetSettingsFor(hub);
356+
357+
if ((Settings == null || Settings.IsEmpty()) && (oSettings == null || oSettings.IsEmpty()))
350358
{
351359
settings.RemoveAt(settings.Count - 1);
352360
return settings;
353361
}
354362

355-
ServerSpecificSettingBase[] oSettings = GetSettingsFor(hub);
356-
if (oSettings != null && !oSettings.IsEmpty())
363+
if (Settings != null)
357364
{
358-
foreach (ServerSpecificSettingBase t in oSettings)
365+
foreach (ServerSpecificSettingBase t in Settings)
359366
{
360367
if (t is ISetting setting)
361368
settings.Add(setting.Base);
@@ -364,13 +371,21 @@ private List<ServerSpecificSettingBase> GetSettings(ReferenceHub hub)
364371
}
365372
}
366373

367-
foreach (ServerSpecificSettingBase t in Settings)
374+
if (oSettings != null && !oSettings.IsEmpty())
368375
{
369-
if (t is ISetting setting)
370-
settings.Add(setting.Base);
371-
else
372-
settings.Add(t);
376+
foreach (ServerSpecificSettingBase t in oSettings)
377+
{
378+
if (t is ISetting setting)
379+
settings.Add(setting.Base);
380+
else
381+
settings.Add(t);
382+
}
383+
384+
SentSettings[hub] = settings.ToArray();
373385
}
386+
else
387+
SentSettings.Remove(hub);
388+
374389
return settings;
375390
}
376391

@@ -435,7 +450,7 @@ internal static void LoadForPlayer(ReferenceHub hub, Menu menu)
435450
if (menu != null && !menu.CheckAccess(hub))
436451
menu = null;
437452

438-
if (menu == null && LoadedMenus.Count(x => x.CheckAccess(hub) && x.MenuRelated == null) == 1 && !Plugin.StaticConfig.ForceMainMenuEvenIfOnlyOne)
453+
if (menu == null && LoadedMenus.Count(x => x.CheckAccess(hub) && x.MenuRelated == null) == 1 && !Plugin.Instance.Config.ForceMainMenuEvenIfOnlyOne)
439454
{
440455
menu = Menus.First(x => x.CheckAccess(hub) && x.MenuRelated == null);
441456
Log.Debug($"triggered The only menu registered: {menu.Name}.");

Features/Parameters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static TSs GetParameter<TMenu, TSs>(this ReferenceHub hub, int settingId)
2626
if (typeof(TSs).BaseType == typeof(ISetting))
2727
{
2828
Log.Error(nameof(TSs) + " need to be of base type (example: Plaintext became SSPlaintextSetting).");
29-
return default;
29+
return null;
3030
}
3131

3232
foreach (Menu menu in Menu.Menus.Where(x => x is TMenu))
@@ -38,7 +38,7 @@ public static TSs GetParameter<TMenu, TSs>(this ReferenceHub hub, int settingId)
3838
return t as TSs;
3939
}
4040

41-
return default;
41+
return null;
4242
}
4343

4444

Patchs/CompatibilizerPatchs/Compatibilizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
3838

3939
internal static void Load(ServerSpecificSettingBase[] settings)
4040
{
41-
if (!Plugin.StaticConfig.ComptabilitySystem.ComptabilityEnabled)
41+
if (!Plugin.Instance.Config.ComptabilitySystem.ComptabilityEnabled)
4242
return;
4343
Assembly assembly = Assembly.GetCallingAssembly();
4444
Log.Debug(assembly.GetName().Name + " tried to set " + nameof(ServerSpecificSettingsSync.DefinedSettings) + ". Game Assembly: " + typeof(ReferenceHub).Assembly.GetName().Name);

Plugin.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
using SSMenuSystem.Features;
66
using UserSettings.ServerSpecific;
77
using Log = SSMenuSystem.Features.Log;
8-
#if EXILED || LABAPI
98
using System;
10-
#endif
119
#if EXILED
1210
using Exiled.API.Features;
13-
#elif NWAPI
14-
using PluginAPI.Core;
15-
#elif LABAPI
11+
#else
1612
using LabApi.Loader.Features.Plugins;
1713
#endif
1814

@@ -22,14 +18,11 @@ namespace SSMenuSystem
2218
/// Load the plugin to send datas to player
2319
/// </summary>
2420
// ReSharper disable once ClassNeverInstantiated.Global
25-
public class Plugin
26-
#if EXILED || LABAPI
27-
: Plugin<Config
21+
public class Plugin : Plugin<Config
2822
#if EXILED
2923
, Translation
3024
#endif
3125
>
32-
#endif
3326
{
3427
/// <summary>
3528
/// Gets the author of the plugin.
@@ -44,7 +37,7 @@ public class Plugin
4437
/// <summary>
4538
/// Gets the version of the plugin.
4639
/// </summary>
47-
public override Version Version => new(2, 0, 4);
40+
public override Version Version => new(2, 0, 6);
4841

4942
#if EXILED
5043
/// <inheritdoc/>
@@ -54,7 +47,7 @@ public class Plugin
5447
/// Gets the prefix used for configs.
5548
/// </summary>
5649
public override string Prefix => "ss_menu_system";
57-
#elif LABAPI
50+
#else
5851

5952
/// <inheritdoc />
6053
public override string Description => "Convert all Server-Specifics Settings created by plugins into menu. Help for multi-plugin comptability and organization.";
@@ -63,13 +56,6 @@ public class Plugin
6356
public override Version RequiredApiVersion => new(1, 0, 0);
6457
#endif
6558

66-
private static Config _staticConfig;
67-
68-
/// <summary>
69-
/// Gets the <see cref="Config"/> instance. Can be null if the plugin is not enabled.
70-
/// </summary>
71-
public static Config StaticConfig => _staticConfig ??= Instance?.Config;
72-
7359
/// <summary>
7460
/// Gets the <see cref="Plugin"/> instance. can be null if the plugin is not enabled.
7561
/// </summary>
@@ -107,7 +93,7 @@ public override void OnDisabled()
10793
base.OnDisabled();
10894
}
10995

110-
#elif LABAPI
96+
#else
11197

11298
/// <inheritdoc />
11399
public override void Enable()
@@ -143,7 +129,7 @@ private void GenericEnable()
143129
#if DEBUG
144130
Log.Warn("EXPERIMENTAL VERSION IS ACTIVATED. BE AWARD OF BUGS CAN BE DONE. NOT STABLE VERSION.");
145131
Menu.RegisterPin(new[]{new SSTextArea(null, "this pinned content is related to the called assembly\nwith Menu.UnregisterPin() you just unregister ONLY pinned settings by the called assembly.", SSTextArea.FoldoutMode.CollapsedByDefault, "This is a pinned content.")});
146-
StaticConfig.Debug = true;
132+
Instance.Config!.Debug = true;
147133
#endif
148134

149135
ServerSpecificSettingsSync.ServerOnSettingValueReceived += EventHandler.OnReceivingInput;
@@ -158,7 +144,7 @@ public static Translation GetTranslation()
158144
#if EXILED
159145
return Instance?.Translation;
160146
#else
161-
return StaticConfig?.Translation;
147+
return Instance.Config?.Translation;
162148
#endif
163149
}
164150
}

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.0.4")]
34+
[assembly: AssemblyVersion("2.0.6")]
3535
[assembly: AssemblyFileVersion("1.0.0.0")]

SSMenuSystem-EXILED.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>SSMenuSystem</id>
55
<title>SS Menu System</title>
6-
<version>2.0.4-EXILED</version>
6+
<version>2.0.6-EXILED</version>
77
<authors>Sky</authors>
88
<owners>Sky</owners>
99
<copyright>Copyright © Sky 2025</copyright>
@@ -15,7 +15,7 @@
1515

1616
<dependencies>
1717
<group targetFramework="net48">
18-
<dependency id="ExMod.Exiled" version="[9.5.0]" />
18+
<dependency id="ExMod.Exiled" version="[9.6.0-beta3]" />
1919
</group>
2020
</dependencies>
2121

@@ -25,7 +25,7 @@
2525
<!-- Project files -->
2626
<file src="$(PACKAGE_REF)/Assembly-CSharp-Publicized.dll" target="lib\net48" />
2727
<file src="$(PACKAGE_REF)/NorthwoodLib.dll" target="lib\net48" />
28-
<file src="$(PACKAGE_REF)/PluginAPI.dll" target="lib\net48" />
28+
<file src="$(PACKAGE_REF)/LabApi.dll" target="lib\net48" />
2929
<file src="bin/Release EXILED/SSMenuSystem-EXILED.dll" target="lib\net48" />
3030
<file src="bin/Release EXILED/SSMenuSystem-EXILED.xml" target="lib\net48" />
3131
<file src="$(PACKAGE_REF)/Unity.TextMeshPro.dll" target="lib\net48" />
@@ -35,4 +35,4 @@
3535
<!-- Project files -->
3636
</files>
3737

38-
</package>
38+
</package>

SSMenuSystem-LABAPI.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>SSMenuSystem</id>
55
<title>SS Menu System</title>
6-
<version>2.0.4-LABAPI-BETA</version>
6+
<version>2.0.6-LABAPI-Beta</version>
77
<authors>Sky</authors>
88
<owners>Sky</owners>
99
<copyright>Copyright © Sky 2025</copyright>
@@ -23,7 +23,7 @@
2323
<!-- Project files -->
2424
<file src="$(PACKAGE_REF)/Assembly-CSharp-Publicized.dll" target="lib\net48" />
2525
<file src="$(PACKAGE_REF)/NorthwoodLib.dll" target="lib\net48" />
26-
<file src="$(PACKAGE_REF)/PluginAPI.dll" target="lib\net48" />
26+
<file src="$(PACKAGE_REF)/LabApi.dll" target="lib\net48" />
2727
<file src="bin/Release LABAPI/SSMenuSystem-LABAPI.dll" target="lib\net48" />
2828
<file src="bin/Release LABAPI/SSMenuSystem-LABAPI.xml" target="lib\net48" />
2929
<file src="$(PACKAGE_REF)/Unity.TextMeshPro.dll" target="lib\net48" />

SSMenuSystem.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<Content Include="SSMenuSystem.ruleset" />
140140
</ItemGroup>
141141
<ItemGroup>
142-
<PackageReference Include="ExMod.Exiled" Version="9.6.0-beta3" />
142+
<PackageReference Include="ExMod.Exiled" Version="9.6.0-beta8" />
143143
</ItemGroup>
144144
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
145145
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)