Skip to content

Commit b02381b

Browse files
committed
Refactored code + codestyle (draft commit)
1 parent cd8ab1e commit b02381b

6 files changed

Lines changed: 222 additions & 231 deletions

File tree

LabExtended/API/ExPlayer.cs

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,43 @@
1-
using LabExtended.API.Enums;
2-
using LabExtended.API.Hints;
1+
using CentralAuth;
2+
using CommandSystem;
3+
using Footprinting;
4+
using Hints;
5+
using InventorySystem.Disarming;
6+
using InventorySystem.Items;
7+
using InventorySystem.Items.Pickups;
8+
using LabApi.Features.Wrappers;
39
using LabExtended.API.Containers;
410
using LabExtended.API.CustomVoice;
5-
using LabExtended.API.RemoteAdmin;
11+
using LabExtended.API.Enums;
612
using LabExtended.API.FileStorage;
7-
8-
using LabExtended.API.Settings.Menus;
9-
using LabExtended.API.Settings.Entries;
10-
13+
using LabExtended.API.Hints;
1114
using LabExtended.API.Hints.Elements.Personal;
12-
13-
using LabExtended.Core.Pooling.Pools;
14-
15+
using LabExtended.API.RemoteAdmin;
16+
using LabExtended.API.Settings.Entries;
17+
using LabExtended.API.Settings.Menus;
1518
using LabExtended.Commands.Attributes;
1619
using LabExtended.Commands.Interfaces;
17-
20+
using LabExtended.Core;
21+
using LabExtended.Core.Pooling.Pools;
1822
using LabExtended.Events;
19-
using LabExtended.Utilities;
2023
using LabExtended.Extensions;
21-
22-
using LabApi.Features.Wrappers;
23-
24+
using LabExtended.Utilities;
25+
using LiteNetLib;
2426
using Mirror;
2527
using Mirror.LiteNetLib4Mirror;
26-
28+
using NetworkManagerUtils.Dummies;
29+
using NorthwoodLib.Pools;
2730
using PlayerRoles;
28-
using PlayerRoles.Spectating;
2931
using PlayerRoles.FirstPersonControl;
30-
31-
using InventorySystem.Disarming;
32-
33-
using InventorySystem.Items;
34-
using InventorySystem.Items.Pickups;
35-
32+
using PlayerRoles.Spectating;
3633
using RemoteAdmin;
3734
using RemoteAdmin.Communication;
38-
39-
using LiteNetLib;
40-
35+
using System.Collections.Generic;
36+
using System.Collections.ObjectModel;
37+
using System.Reflection;
4138
using UnityEngine;
42-
43-
using VoiceChat;
44-
45-
using Hints;
46-
47-
using CentralAuth;
48-
49-
using CommandSystem;
50-
51-
using Footprinting;
52-
53-
using NetworkManagerUtils.Dummies;
54-
55-
using NorthwoodLib.Pools;
56-
5739
using UserSettings.ServerSpecific;
40+
using VoiceChat;
5841

5942
#pragma warning disable CS8602 // Dereference of a possibly null reference.
6043
#pragma warning disable CS8604 // Possible null reference argument.
@@ -135,6 +118,11 @@ public class ExPlayer : Player, IDisposable
135118
}
136119
}
137120

121+
/// <summary>
122+
/// Gets a dictionary of Personal DefinedSettings for each Plugin Assembly
123+
/// </summary>
124+
public Dictionary<Assembly, ServerSpecificSettingBase[]>? SettingsByAssembly => settingsByAssembly;
125+
138126
#region Get
139127
/// <summary>
140128
/// Gets an <see cref="ExPlayer"/> instance tied to the specified <see cref="ReferenceHub"/>.
@@ -459,7 +447,10 @@ public static IEnumerable<ExPlayer> Get(RoleTypeId role)
459447
private string idInfoValue = string.Empty;
460448

461449
internal ICommandRunner? activeRunner;
462-
450+
451+
internal Dictionary<Assembly, ServerSpecificSettingBase[]>?
452+
settingsByAssembly = DictionaryPool<Assembly, ServerSpecificSettingBase[]>.Shared.Rent();
453+
463454
internal Dictionary<string, SettingsMenu>? settingsMenuLookup = DictionaryPool<string, SettingsMenu>.Shared.Rent();
464455
internal Dictionary<string, SettingsEntry>? settingsIdLookup = DictionaryPool<string, SettingsEntry>.Shared.Rent();
465456

@@ -1442,6 +1433,9 @@ public void Dispose()
14421433
PersistentStorage = null!;
14431434
}
14441435

1436+
if (settingsByAssembly != null)
1437+
DictionaryPool<Assembly, ServerSpecificSettingBase[]>.Shared.Return(settingsByAssembly);
1438+
14451439
if (settingsIdLookup != null)
14461440
DictionaryPool<string, SettingsEntry>.Shared.Return(settingsIdLookup);
14471441

@@ -1463,6 +1457,7 @@ public void Dispose()
14631457
if (SentPositions != null)
14641458
DictionaryPool<uint, PositionSync.SentPosition>.Shared.Return(SentPositions);
14651459

1460+
settingsByAssembly = null;
14661461
settingsIdLookup = null;
14671462
settingsMenuLookup = null;
14681463
settingsAssignedIdLookup = null;
@@ -1478,6 +1473,21 @@ public void Dispose()
14781473
Rotation = null!;
14791474
}
14801475

1476+
internal void SyncSettingsByAssembly(Assembly assembly, ServerSpecificSettingBase[] collection) {
1477+
if (!this)
1478+
return;
1479+
1480+
if (settingsByAssembly == null) {
1481+
ApiLog.Warn($"Player's {nameof(settingsByAssembly)} is null");
1482+
return;
1483+
}
1484+
1485+
if (collection == null || collection.Length == 0)
1486+
settingsByAssembly.Remove(assembly);
1487+
else
1488+
settingsByAssembly[assembly] = collection;
1489+
}
1490+
14811491
private static ReferenceHub SpawnHiddenDummy(string nick)
14821492
{
14831493
var hubGo = UnityEngine.Object.Instantiate(NetworkManager.singleton.playerPrefab);

LabExtended/API/Settings/SettingsManager.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static class SettingsManager
3030
/// </summary>
3131
public static List<SettingsBuilder> AllBuilders { get; } = new();
3232

33+
/// <summary>
34+
/// Gets a dictionary of DefinedSettings for each Plugin Assembly
35+
/// </summary>
36+
public static Dictionary<Assembly, ServerSpecificSettingBase[]> GlobalSettingsByAssembly { get; } = new();
37+
3338
/// <summary>
3439
/// Gets or sets the server-side settings version.
3540
/// </summary>
@@ -82,11 +87,9 @@ public static void SyncEntries(this ExPlayer player)
8287

8388

8489
Dictionary<Assembly, ServerSpecificSettingBase[]> playerSettings = DictionaryPool<Assembly, ServerSpecificSettingBase[]>.Shared.Rent();
85-
playerSettings.AddRange(VanillaSettingsAdapter.SssByAssemblyGlobal);
86-
if (VanillaSettingsAdapter.SssByAssemblyPersonal.TryGetValue(player, out var loadedPlayerSettings)) {
87-
foreach (var kvp in loadedPlayerSettings) {
88-
playerSettings[kvp.Key] = kvp.Value;
89-
}
90+
playerSettings.AddRange(GlobalSettingsByAssembly); // todo Use SendOnJoinFilter
91+
foreach (var kvp in player.settingsByAssembly) {
92+
playerSettings[kvp.Key] = kvp.Value;
9093
}
9194

9295
foreach (var sssByAssemblyEntry in playerSettings) {

LabExtended/API/Settings/VanillaSettingsAdapter.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

LabExtended/Patches/Functions/Settings/SettingsDefinitionsAdapterPatch.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)