diff --git a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs index b27ae1fc78..0f5f277d79 100644 --- a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs +++ b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs @@ -259,13 +259,43 @@ public static IEnumerable Register(IEnumerable setting return result; } + /// + /// Registers all settings from the specified collection to player. + /// + /// A collection of settings to register. + /// A player that will receive settings. + /// A of instances that were successfully registered. + /// This method is used to sync new settings with players. + public static IEnumerable Register(IEnumerable settings, Player player) + { + IEnumerable> grouped = settings.Where(s => s != null).GroupBy(s => s.Header); + + List result = new(); + + // Group settings by headers + foreach (IGrouping grouping in grouped) + { + if (grouping.Key != null) + result.Add(grouping.Key); + + result.AddRange(grouping); + } + + ServerSpecificSettingsSync.DefinedSettings = (ServerSpecificSettingsSync.DefinedSettings ?? Array.Empty()).Concat(result.Select(s => s.Base)).ToArray(); + Settings.AddRange(result); + + SendToPlayer(player); + + return result; + } + /// /// Removes settings from players. /// /// Determines which players will receive this update. /// Settings to remove. If null, all settings will be removed. /// A of instances that were successfully removed. - /// This method is used to unsync settings from players. Using it with provides an opportunity to update synced settings. + /// This method is used to unsync settings from players. Using it with provides an opportunity to update synced settings. public static IEnumerable Unregister(Func predicate = null, IEnumerable settings = null) { List list = ListPool.Pool.Get(ServerSpecificSettingsSync.DefinedSettings); @@ -283,6 +313,27 @@ public static IEnumerable Unregister(Func predicate = return list2; } + /// + /// Removes settings from players. + /// + /// Determines which player will receive this update. + /// Settings to remove. If null, all settings will be removed. + /// A of instances that were successfully removed. + /// This method is used to unsync settings from players. Using it with provides an opportunity to update synced settings. + public static IEnumerable Unregister(Player player, IEnumerable settings = null) + { + List list = ListPool.Pool.Get(ServerSpecificSettingsSync.DefinedSettings); + List list2 = new((settings ?? Settings).Where(setting => list.Remove(setting.Base))); + + ServerSpecificSettingsSync.DefinedSettings = list.ToArray(); + + SendToPlayer(player); + + ListPool.Pool.Return(list); + + return list2; + } + /// /// Returns a string representation of this . ///