diff --git a/XPSystem.Console/App.config b/XPSystem.Console/App.config index 932f354..34f6c8d 100644 --- a/XPSystem.Console/App.config +++ b/XPSystem.Console/App.config @@ -3,7 +3,15 @@ - + + + + + + + + + diff --git a/XPSystem.Console/XPSystem.Console.csproj b/XPSystem.Console/XPSystem.Console.csproj index b0e24a8..a5c8ebc 100644 --- a/XPSystem.Console/XPSystem.Console.csproj +++ b/XPSystem.Console/XPSystem.Console.csproj @@ -43,45 +43,45 @@ - ..\packages\EXILED.8.8.1\lib\net48\Assembly-CSharp-Publicized.dll + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Assembly-CSharp-Publicized.dll - ..\packages\EXILED.8.8.1\lib\net48\CommandSystem.Core.dll + ..\packages\ExMod.Exiled.9.1.1\lib\net48\CommandSystem.Core.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.API.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.API.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.CreditTags.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CreditTags.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.CustomItems.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CustomItems.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.CustomRoles.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CustomRoles.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.Events.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Events.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.Loader.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Loader.dll - - ..\packages\EXILED.8.8.1\lib\net48\Exiled.Permissions.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Permissions.dll - - ..\packages\EXILED.8.8.1\lib\net48\NorthwoodLib.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\NorthwoodLib.dll - - ..\packages\EXILED.8.8.1\lib\net48\PluginAPI.dll - - - ..\packages\EXILED.8.8.1\lib\net48\YamlDotNet.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\PluginAPI.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\YamlDotNet.dll + diff --git a/XPSystem.Console/packages.config b/XPSystem.Console/packages.config index b70f335..3a6171a 100644 --- a/XPSystem.Console/packages.config +++ b/XPSystem.Console/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/XPSystem/API/DisplayProviders/SyncVarXPDisplayProvider.cs b/XPSystem/API/DisplayProviders/SyncVarXPDisplayProvider.cs index 805fd3e..e0ddeaf 100644 --- a/XPSystem/API/DisplayProviders/SyncVarXPDisplayProvider.cs +++ b/XPSystem/API/DisplayProviders/SyncVarXPDisplayProvider.cs @@ -41,7 +41,7 @@ protected override void RefreshToEnabled(XPPlayer player) if (!ShouldEdit(kvp.Value)) continue; - var obj = GetObject(kvp.Value); + TObject obj = GetObject(kvp.Value); if (obj == null) continue; @@ -82,7 +82,7 @@ protected override void RefreshOfEnabled(XPPlayer player, PlayerInfoWrapper play if (!ShouldEdit(player)) return; - var obj = GetObject(player, playerInfo, true); + TObject obj = GetObject(player, playerInfo, true); if (obj == null) return; diff --git a/XPSystem/API/DisplayProviders/XPDisplayProviderCollection.cs b/XPSystem/API/DisplayProviders/XPDisplayProviderCollection.cs index c7470ef..0bb6408 100644 --- a/XPSystem/API/DisplayProviders/XPDisplayProviderCollection.cs +++ b/XPSystem/API/DisplayProviders/XPDisplayProviderCollection.cs @@ -22,7 +22,7 @@ public class XPDisplayProviderCollection : IEnumerable /// public void Refresh() { - foreach (var provider in _providers) + foreach (IXPDisplayProvider provider in _providers) provider.RefreshAll(); LogDebug("Refreshed all displays"); @@ -35,7 +35,7 @@ public void Refresh() /// The player to refresh the displays for. public void RefreshTo(XPPlayer player) { - foreach (var provider in _providers) + foreach (IXPDisplayProvider provider in _providers) provider.RefreshTo(player); LogDebug($"Refreshed displays to {player.Nickname}"); @@ -51,7 +51,7 @@ public void RefreshOf(XPPlayer player, PlayerInfoWrapper playerInfo = null) { playerInfo ??= player.GetPlayerInfo(); - foreach (var provider in _providers) + foreach (IXPDisplayProvider provider in _providers) provider.RefreshOf(player, playerInfo); LogDebug($"Refreshed displays of {player.Nickname}"); @@ -77,7 +77,7 @@ public void Add(IXPDisplayProvider provider) /// public void DisableAll() { - foreach (var provider in _providers) + foreach (IXPDisplayProvider provider in _providers) { try { @@ -95,7 +95,7 @@ public void DisableAll() /// public void Enable() { - foreach (var provider in _providers) + foreach (IXPDisplayProvider provider in _providers) { if (provider.ConfigPropertyInternal?.Enabled == true) { @@ -117,7 +117,7 @@ public void Enable() /// The folder to read and write the configs from. public void LoadConfigs(string folder) { - foreach (var provider in Providers) + foreach (IXPDisplayProvider provider in Providers) { string name = provider.GetType().Name; string file = Path.Combine(folder, name + ".yml"); @@ -136,7 +136,7 @@ public void LoadConfigs(string folder) } else { - var obj = provider.ConfigPropertyInternal; + IXPDisplayProviderConfig obj = provider.ConfigPropertyInternal; File.WriteAllText(file, XPAPI.Serializer.Serialize(obj)); provider.ConfigPropertyInternal = obj; diff --git a/XPSystem/API/Exceptions/InvalidPlayerIdException.cs b/XPSystem/API/Exceptions/InvalidPlayerIdException.cs index d159fdb..2277c8b 100644 --- a/XPSystem/API/Exceptions/InvalidPlayerIdException.cs +++ b/XPSystem/API/Exceptions/InvalidPlayerIdException.cs @@ -4,7 +4,7 @@ public class InvalidPlayerIdException : Exception { - public InvalidPlayerIdException() : base("The PlayerId for the specified player is invalid! Are you trying to add xp to a the host?") + public InvalidPlayerIdException() : base("The PlayerId for the specified player is invalid! Are you trying to modify the xp for the host?") { } } diff --git a/XPSystem/API/Legacy/LiteDBMigrator.cs b/XPSystem/API/Legacy/LiteDBMigrator.cs index 2d13e6e..12fdf1e 100644 --- a/XPSystem/API/Legacy/LiteDBMigrator.cs +++ b/XPSystem/API/Legacy/LiteDBMigrator.cs @@ -61,7 +61,7 @@ public static int ImportLegacyDB(LiteDatabase db) int count = 0; int total = collection.Count(); - foreach (var log in collection.FindAll()) + foreach (PlayerLog log in collection.FindAll()) { if (!log.ID.TryParseUserId(out var id)) { diff --git a/XPSystem/API/StorageProviders/IStorageProvider.cs b/XPSystem/API/StorageProviders/IStorageProvider.cs index 72533c8..0f2dd5c 100644 --- a/XPSystem/API/StorageProviders/IStorageProvider.cs +++ b/XPSystem/API/StorageProviders/IStorageProvider.cs @@ -11,11 +11,11 @@ public interface IStorageProvider { void Initialize(); void Dispose(); - bool TryGetPlayerInfo(PlayerId playerId, out PlayerInfoWrapper playerInfo); - PlayerInfoWrapper GetPlayerInfoAndCreateOfNotExist(PlayerId playerId); + bool TryGetPlayerInfo(IPlayerId playerId, out PlayerInfoWrapper playerInfo); + PlayerInfoWrapper GetPlayerInfoAndCreateOfNotExist(IPlayerId playerId); IEnumerable GetTopPlayers(int count); void SetPlayerInfo(PlayerInfoWrapper playerInfo); - bool DeletePlayerInfo(PlayerId playerId); + bool DeletePlayerInfo(IPlayerId playerId); void DeleteAllPlayerInfo(); } } \ No newline at end of file diff --git a/XPSystem/API/StorageProviders/Models/IPlayerId.cs b/XPSystem/API/StorageProviders/Models/IPlayerId.cs new file mode 100644 index 0000000..2ab3a75 --- /dev/null +++ b/XPSystem/API/StorageProviders/Models/IPlayerId.cs @@ -0,0 +1,25 @@ +namespace XPSystem.API.StorageProviders.Models +{ + using XPSystem.API.Enums; + + /// + /// Represents a player identifier. + /// + public interface IPlayerId + { + /// + /// The -specific identifier of the player. + /// + public object Id { get; } + + /// + /// The of the . + /// + public AuthType AuthType { get; } + + /// + /// Returns Id@AuthType. + /// + public string ToString(); + } +} \ No newline at end of file diff --git a/XPSystem/API/StorageProviders/Models/NumberPlayerId.cs b/XPSystem/API/StorageProviders/Models/NumberPlayerId.cs new file mode 100644 index 0000000..1e16c81 --- /dev/null +++ b/XPSystem/API/StorageProviders/Models/NumberPlayerId.cs @@ -0,0 +1,29 @@ +namespace XPSystem.API.StorageProviders.Models +{ + using XPSystem.API.Enums; + + /// + /// Represents an identifier that uses numbers (ex. SteamIds). + /// + public class NumberPlayerId : IPlayerId + { + /// + /// The identifier of the player, in number form. + /// + public readonly ulong IdNumber; + + /// + public object Id => IdNumber; + /// + public AuthType AuthType { get; } + + /// + public override string ToString() => $"{Id}@{AuthType.ToString().ToLower()}"; + + public NumberPlayerId(ulong id, AuthType authType) + { + IdNumber = id; + AuthType = authType; + } + } +} \ No newline at end of file diff --git a/XPSystem/API/StorageProviders/Models/PlayerId.cs b/XPSystem/API/StorageProviders/Models/PlayerId.cs deleted file mode 100644 index 9e50a07..0000000 --- a/XPSystem/API/StorageProviders/Models/PlayerId.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace XPSystem.API.StorageProviders.Models -{ - using XPSystem.API.Enums; - using XPSystem.API.Exceptions; - - public struct PlayerId - { - public AuthType AuthType { get; set; } - public ulong Id { get; set; } - - /// - /// Gets a value indicating whether or not this is valid. - /// AddXP will throw if this is true, unless forced. - /// - public bool IsValid => Id != 0; - - /// - /// Throws an if this is not valid. - /// - /// This is not valid. - public void EnsureValid() - { - if (!IsValid) - throw new InvalidPlayerIdException(); - } - - /// - /// Returns Id@AuthType. - /// - public override string ToString() => $"{Id}@{AuthType.ToString().ToLower()}"; - } -} \ No newline at end of file diff --git a/XPSystem/API/StorageProviders/Models/PlayerInfo.cs b/XPSystem/API/StorageProviders/Models/PlayerInfo.cs index 3807e4b..f4b6fd7 100644 --- a/XPSystem/API/StorageProviders/Models/PlayerInfo.cs +++ b/XPSystem/API/StorageProviders/Models/PlayerInfo.cs @@ -6,7 +6,7 @@ /// public class PlayerInfo { - public PlayerId Player { get; set; } + public IPlayerId Player { get; set; } public int XP { get; set; } #if STORENICKS public string Nickname { get; set; } diff --git a/XPSystem/API/StorageProviders/Models/StringPlayerId.cs b/XPSystem/API/StorageProviders/Models/StringPlayerId.cs new file mode 100644 index 0000000..6d87c45 --- /dev/null +++ b/XPSystem/API/StorageProviders/Models/StringPlayerId.cs @@ -0,0 +1,29 @@ +namespace XPSystem.API.StorageProviders.Models +{ + using XPSystem.API.Enums; + + /// + /// Represents an identifier that uses strings (ex. NorthwoodIds). + /// + public class StringPlayerId : IPlayerId + { + /// + /// The identifier of the player, in string form. + /// + public readonly string IdString; + + /// + public object Id => IdString; + /// + public AuthType AuthType { get; } + + /// + public override string ToString() => $"{Id}@{AuthType.ToString().ToLower()}"; + + public StringPlayerId(string id, AuthType authType) + { + IdString = id; + AuthType = authType; + } + } +} \ No newline at end of file diff --git a/XPSystem/API/StorageProviders/PlayerInfoWrapper.cs b/XPSystem/API/StorageProviders/PlayerInfoWrapper.cs index 022cc19..9334a02 100644 --- a/XPSystem/API/StorageProviders/PlayerInfoWrapper.cs +++ b/XPSystem/API/StorageProviders/PlayerInfoWrapper.cs @@ -16,9 +16,9 @@ public class PlayerInfoWrapper public readonly PlayerInfo PlayerInfo; /// - /// Gets the of the player the belongs to. + /// Gets the of the player the belongs to. /// - public PlayerId Player => PlayerInfo.Player; + public IPlayerId Player => PlayerInfo.Player; /// /// Gets the stored nickname of the player. diff --git a/XPSystem/API/StorageProviders/StorageProvider.cs b/XPSystem/API/StorageProviders/StorageProvider.cs index 42aa8b8..8deedf1 100644 --- a/XPSystem/API/StorageProviders/StorageProvider.cs +++ b/XPSystem/API/StorageProviders/StorageProvider.cs @@ -18,19 +18,19 @@ public abstract class StorageProvider : IStorageProvider /// public virtual void Dispose() => ClearCache(); - public virtual bool TryGetPlayerInfo(PlayerId playerId, out PlayerInfoWrapper playerInfo) + public virtual bool TryGetPlayerInfo(IPlayerId playerId, out PlayerInfoWrapper playerInfo) { if (TryGetFromCache(playerId, out playerInfo)) return true; - bool result = TryGetPlayerInfoNoCache(playerId, out var playerInfo3); + bool result = TryGetPlayerInfoNoCache(playerId, out PlayerInfo playerInfo3); playerInfo = playerInfo3; return result; } - public virtual PlayerInfoWrapper GetPlayerInfoAndCreateOfNotExist(PlayerId playerId) + public virtual PlayerInfoWrapper GetPlayerInfoAndCreateOfNotExist(IPlayerId playerId) { - if (TryGetFromCache(playerId, out var playerInfo)) + if (TryGetFromCache(playerId, out PlayerInfoWrapper playerInfo)) return playerInfo; return GetPlayerInfoAndCreateOfNotExistNoCache(playerId); @@ -38,15 +38,15 @@ public virtual PlayerInfoWrapper GetPlayerInfoAndCreateOfNotExist(PlayerId playe public virtual void SetPlayerInfo(PlayerInfoWrapper playerInfo) { - if (XPPlayer.TryGet(playerInfo.Player, out var player)) + if (XPPlayer.TryGet(playerInfo.Player, out XPPlayer player)) player.Variables.Set(VariableKey, playerInfo); SetPlayerInfoNoCache(playerInfo); } - public virtual bool DeletePlayerInfo(PlayerId playerId) + public virtual bool DeletePlayerInfo(IPlayerId playerId) { - if (XPPlayer.TryGet(playerId, out var player)) + if (XPPlayer.TryGet(playerId, out XPPlayer player)) player.Variables.Remove(VariableKey); return DeletePlayerInfoNoCache(playerId); @@ -58,11 +58,11 @@ public virtual void DeleteAllPlayerInfo() DeleteAllPlayerInfoNoCache(); } - protected virtual bool TryGetFromCache(PlayerId playerId, out PlayerInfoWrapper playerInfo) + protected virtual bool TryGetFromCache(IPlayerId playerId, out PlayerInfoWrapper playerInfo) { playerInfo = null; - if (!XPPlayer.TryGet(playerId, out var player)) + if (!XPPlayer.TryGet(playerId, out XPPlayer player)) { LogDebug("Player not in server: " + playerId); playerInfo = null; @@ -95,10 +95,10 @@ public virtual void ClearCache() public abstract void Initialize(); public abstract IEnumerable GetTopPlayers(int count); - protected abstract bool TryGetPlayerInfoNoCache(PlayerId playerId, out PlayerInfo playerInfo); - protected abstract PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(PlayerId playerId); + protected abstract bool TryGetPlayerInfoNoCache(IPlayerId playerId, out PlayerInfo playerInfo); + protected abstract PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(IPlayerId playerId); protected abstract void SetPlayerInfoNoCache(PlayerInfo playerInfo); - protected abstract bool DeletePlayerInfoNoCache(PlayerId playerId); + protected abstract bool DeletePlayerInfoNoCache(IPlayerId playerId); protected abstract void DeleteAllPlayerInfoNoCache(); /// diff --git a/XPSystem/API/Variables/VariableCollection.cs b/XPSystem/API/Variables/VariableCollection.cs index 8426d97..da8c40b 100644 --- a/XPSystem/API/Variables/VariableCollection.cs +++ b/XPSystem/API/Variables/VariableCollection.cs @@ -52,7 +52,7 @@ public void Add(string key, Variable variable) /// The expiry time of the variable. public void Set(string key, object value, DateTime? expiryTime = null) { - if (_variables.TryGetValue(key, out var variable)) + if (_variables.TryGetValue(key, out Variable variable)) { variable.Value = value; variable.ExpiryTime = expiryTime; @@ -93,7 +93,7 @@ public bool TryGet(string key, out Variable variable) /// Will throw if the cast fails. public bool TryGet(string key, out T value) { - if (TryGet(key, out var variable)) + if (TryGet(key, out Variable variable)) { value = variable.As(); return true; @@ -116,7 +116,7 @@ public bool TryGet(string key, out T value) /// The key of the variable. public Variable this[string key] { - get => TryGet(key, out var variable) + get => TryGet(key, out Variable variable) ? variable : null; set => _variables[key] = value; diff --git a/XPSystem/API/XPAPI.cs b/XPSystem/API/XPAPI.cs index 0833afc..d1db833 100644 --- a/XPSystem/API/XPAPI.cs +++ b/XPSystem/API/XPAPI.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; + using System.Text; using NorthwoodLib.Pools; using PlayerRoles; using XPSystem.API.DisplayProviders; @@ -92,6 +93,11 @@ public static class XPAPI /// public static bool XPGainPaused { get; set; } = false; + /// + /// Gets invoke when a player levels up. + /// + public static event Action PlayerLevelUp = delegate { }; + /// /// Prints a debug message, if debug is enabled. /// Not too different from your loader's LogDebug. @@ -169,7 +175,7 @@ public static void SetStorageProvider(string typeName) return; } - if (Main.TryCreate(typeName, out var e, out IStorageProvider provider)) + if (Main.TryCreate(typeName, out Exception e, out IStorageProvider provider)) { SetStorageProvider(provider); return; @@ -202,7 +208,7 @@ public static void LoadStorageProviderConfig(StorageProvider provider) } else { - var obj = provider.ConfigPropertyInternal; + object obj = provider.ConfigPropertyInternal; File.WriteAllText(file, Serializer.Serialize(obj)); provider.ConfigPropertyInternal = obj; @@ -223,9 +229,9 @@ public static void EnsureStorageProviderValid() /// Gets the player info of a player. /// Will create a new one if it doesn't exist. /// - /// The of the player to get the info of. + /// The of the player to get the info of. /// The belonging to the player. - public static PlayerInfoWrapper GetPlayerInfo(PlayerId playerId) + public static PlayerInfoWrapper GetPlayerInfo(IPlayerId playerId) { EnsureStorageProviderValid(); return StorageProvider.GetPlayerInfoAndCreateOfNotExist(playerId); @@ -265,8 +271,7 @@ public static void UpdateNickname(XPPlayer player, PlayerInfoWrapper playerInfo /// Whether to force the addition of XP,
/// even if
/// or the player has enabled
- /// or is true,
- /// or the is not . + /// or is true. /// The player's . Optional, only pass if you already have it, saves barely any time. /// Whether or not the XP was added. public static bool AddXP(XPPlayer player, int amount, bool force = false, PlayerInfoWrapper playerInfo = null) @@ -277,9 +282,6 @@ public static bool AddXP(XPPlayer player, int amount, bool force = false, Player if (!force && (XPGainPaused || player.DNT) || player.IsNPC) return false; - if (!force) - player.PlayerId.EnsureValid(); - playerInfo ??= GetPlayerInfo(player.PlayerId); AddXP(playerInfo, amount, player); @@ -314,7 +316,7 @@ internal static bool AddXP(PlayerInfoWrapper playerInfo, int amount, XPPlayer pl StorageProvider.SetPlayerInfo(playerInfo); if (connected && playerInfo.Level != prevLevel) - HandleLevelUp(player, playerInfo); + HandleLevelUp(player, playerInfo, prevLevel); return true; } @@ -362,8 +364,8 @@ public static bool TryAddXPAndDisplayMessage(XPPlayer player, string key, params if (!player.IsConnected) return false; - var file = XPECManager.GetFile(key, player.Role); - var item = file?.Get(subkeys); + XPECFile file = XPECManager.GetFile(key, player.Role); + XPECItem item = file?.Get(subkeys); if (item == null) return false; @@ -390,7 +392,7 @@ public static bool AddXPAndDisplayMessage(XPPlayer player, XPECItem xpecItem) if (xpecItem == null || xpecItem.Amount == 0 || player.DNT || XPGainPaused) return false; - var playerInfo = GetPlayerInfo(player.PlayerId); + PlayerInfoWrapper playerInfo = GetPlayerInfo(player.PlayerId); AddXP(player, xpecItem.Amount, playerInfo: playerInfo); string message = xpecItem.Translation; @@ -429,7 +431,8 @@ public static bool AddXPAndDisplayMessage(XPPlayer player, XPECItem xpecItem) /// /// The player that leveled up. /// The belonging to the player. - public static void HandleLevelUp(XPPlayer player, PlayerInfoWrapper wrapper) + /// The previous level the player had. + public static void HandleLevelUp(XPPlayer player, PlayerInfoWrapper wrapper, int prevLevel) { DisplayProviders.RefreshOf(player); @@ -438,44 +441,85 @@ public static void HandleLevelUp(XPPlayer player, PlayerInfoWrapper wrapper) player.DisplayMessage(Config.AddedLVLMessage.Replace("%level%", wrapper.Level.ToString())); } + + PlayerLevelUp.Invoke(player, wrapper.Level, prevLevel); } /// - /// Attempts to parse a string into a . + /// Attempts to create a from an id and an . + /// + /// The id value. + /// The of the id. + /// If successful, the created. Otherwise, null. + public static IPlayerId CreateUserId(object id, AuthType authType) + { + bool EnsureIs(out T obj) + { + if (id is T t) + { + obj = t; + return true; + } + + object converted = Convert.ChangeType(id, typeof(T)); + if (converted is T t2) + { + obj = t2; + return true; + } + + obj = default; + return false; + } + + switch (authType) + { + case AuthType.Steam: + case AuthType.Discord: + if (EnsureIs(out ulong ulongId)) + return new NumberPlayerId(ulongId, authType); + + LogDebug("UserId creating failed (not ulong)"); + return null; + case AuthType.Northwood: + if (EnsureIs(out string stringId)) + return new StringPlayerId(stringId, authType); + + LogDebug("UserId creating failed (not string)"); + return null; + default: + return null; + } + } + + /// + /// Attempts to parse a string into a . /// /// The string to parse. - /// The equivalent . + /// The equivalent . /// Whether or not the parsing was successful. - public static bool TryParseUserId(string @string, out PlayerId playerId) + public static bool TryParseUserId(string @string, out IPlayerId playerId) { - playerId = default; + playerId = null; if (@string == null) return false; - var split = @string.Split('@'); + string[] split = @string.Split('@'); if (split.Length != 2) - return false; - - switch (split[1].ToLower()) { - case "steam": - playerId.AuthType = AuthType.Steam; - break; - case "discord": - playerId.AuthType = AuthType.Discord; - break; - case "northwood": - playerId.AuthType = AuthType.Northwood; - break; - default: - return false; + LogDebug("Failed to parse UserId (length != 2)"); + return false; } - if (!ulong.TryParse(split[0], out ulong ulongId)) + string authTypeString = split[1]; + if (!Enum.TryParse(authTypeString, true, out AuthType authType)) + { + LogDebug("Failed to parse UserId (unknown authType):" + authTypeString); return false; + } - playerId.Id = ulongId; - return true; + playerId = CreateUserId(split[0], authType); + return playerId != null; } /// @@ -485,9 +529,9 @@ public static bool TryParseUserId(string @string, out PlayerId playerId) /// The formatted leaderboard, as a string.. public static string FormatLeaderboard(IEnumerable players) { - var sb = StringBuilderPool.Shared.Rent(); + StringBuilder sb = StringBuilderPool.Shared.Rent(); - foreach (var playerInfo in players) + foreach (PlayerInfoWrapper playerInfo in players) { #if STORENICKS sb.AppendLine(string.IsNullOrWhiteSpace(playerInfo.Nickname) @@ -508,12 +552,12 @@ public static string FormatLeaderboard(IEnumerable players) /// The type, formatted into a string. public static string FormatType(Type type) { - var sb = StringBuilderPool.Shared.Rent(); + StringBuilder sb = StringBuilderPool.Shared.Rent(); sb.Append(type.FullName); if (type.IsGenericType) { sb.Append("<"); - foreach (var arg in type.GetGenericArguments()) + foreach (Type arg in type.GetGenericArguments()) { sb.Append(FormatType(arg)); sb.Append(", "); diff --git a/XPSystem/API/XPExtensions.cs b/XPSystem/API/XPExtensions.cs index fbde88b..e934bc4 100644 --- a/XPSystem/API/XPExtensions.cs +++ b/XPSystem/API/XPExtensions.cs @@ -10,7 +10,7 @@ public static class XPExtensions { /// - public static bool TryParseUserId(this string @string, out PlayerId playerId) => XPAPI.TryParseUserId(@string, out playerId); + public static bool TryParseUserId(this string @string, out IPlayerId playerId) => XPAPI.TryParseUserId(@string, out playerId); /// public static string FormatLeaderboard(this IEnumerable players) => XPAPI.FormatLeaderboard(players); @@ -21,8 +21,8 @@ public static class XPExtensions /// public static ItemCategory GetCategory(this ItemType itemType) => LoaderSpecific.GetCategory(itemType); - /// - public static PlayerInfoWrapper GetPlayerInfo(this PlayerId playerId) => XPAPI.GetPlayerInfo(playerId); + /// + public static PlayerInfoWrapper GetPlayerInfo(this IPlayerId playerId) => XPAPI.GetPlayerInfo(playerId); /// public static PlayerInfoWrapper GetPlayerInfo(this XPPlayer player) => XPAPI.GetPlayerInfo(player); diff --git a/XPSystem/API/XPPlayer.cs b/XPSystem/API/XPPlayer.cs index 05442e7..6dc2ac9 100644 --- a/XPSystem/API/XPPlayer.cs +++ b/XPSystem/API/XPPlayer.cs @@ -40,7 +40,7 @@ public partial class XPPlayer /// /// Gets the player's . /// - public PlayerId PlayerId { get; } + public IPlayerId PlayerId { get; } /// /// Gets whether or not the player is a npc. @@ -180,7 +180,7 @@ private XPPlayer(ReferenceHub referenceHub) throw new ArgumentNullException(nameof(referenceHub)); #if DEBUG - if (referenceHub == ReferenceHub.HostHub) + if (referenceHub.IsHost) { var stackTrace = new StackTrace(); LogInfo("XPPlayer for Dedicated Server was created: " + stackTrace); @@ -188,7 +188,7 @@ private XPPlayer(ReferenceHub referenceHub) #endif Hub = referenceHub; - IsNPC = referenceHub == ReferenceHub.HostHub || CheckNPC(referenceHub); + IsNPC = referenceHub.IsHost || CheckNPC(referenceHub); if (UserId.TryParseUserId(out var playerId)) { @@ -212,7 +212,7 @@ private XPPlayer(ReferenceHub referenceHub) /// The player. public static XPPlayer Get(ReferenceHub hub) { - if (Players.TryGetValue(hub, out var player)) + if (Players.TryGetValue(hub, out XPPlayer player)) return player; player = new XPPlayer(hub); @@ -220,12 +220,12 @@ public static XPPlayer Get(ReferenceHub hub) } /// - /// Attempts to get a player using a . + /// Attempts to get a player using a . /// - /// The of the player. + /// The of the player. /// The player, if on the server. /// Whether or not the playerid is valid and player is on the server. - public static bool TryGet(PlayerId playerId, out XPPlayer player) + public static bool TryGet(IPlayerId playerId, out XPPlayer player) { return TryGet(playerId.ToString(), out player); } @@ -251,7 +251,7 @@ public static bool TryGet(string data, out XPPlayer player) if (string.IsNullOrWhiteSpace(data)) return false; - var hub = GetHub(data); + ReferenceHub hub = GetHub(data); if (hub == null) return false; @@ -339,7 +339,7 @@ public void SendFakeSyncVar(NetworkIdentity behaviorOwner, Type targetType, stri if (!IsConnected) return; - var writer = NetworkWriterPool.Get(); + NetworkWriterPooled writer = NetworkWriterPool.Get(); MakeCustomSyncWriter(behaviorOwner, targetType, CustomSyncVarGenerator, writer); Hub.connectionToClient.Send(new EntityStateMessage @@ -371,7 +371,7 @@ public int SendFakeSyncVars(Type targetType, string propertyName, object value, return -1; int count = 0; - var writer = NetworkWriterPool.Get(); + NetworkWriterPooled writer = NetworkWriterPool.Get(); MakeCustomSyncWriter(Hub.networkIdentity, targetType, CustomSyncVarGenerator, writer); var message = new EntityStateMessage @@ -380,7 +380,7 @@ public int SendFakeSyncVars(Type targetType, string propertyName, object value, payload = writer.ToArraySegment(), }; - foreach (var referenceHub in ReferenceHub.AllHubs) + foreach (ReferenceHub referenceHub in ReferenceHub.AllHubs) { if (skipSelf && referenceHub == Hub) continue; @@ -416,13 +416,13 @@ public int SendFakeSyncVars(Func condition, Type targetType, str return -1; int count = 0; - var writer = NetworkWriterPool.Get(); + NetworkWriterPooled writer = NetworkWriterPool.Get(); MakeCustomSyncWriter(Hub.networkIdentity, targetType, CustomSyncVarGenerator, writer); EntityStateMessage message2 = default; if (value2 != null) { - var writer2 = NetworkWriterPool.Get(); + NetworkWriterPooled writer2 = NetworkWriterPool.Get(); MakeCustomSyncWriter(Hub.networkIdentity, targetType, CustomSyncVarGeneratorValue2, writer2); message2 = new EntityStateMessage diff --git a/XPSystem/App.config b/XPSystem/App.config index fae3ae8..59da883 100644 --- a/XPSystem/App.config +++ b/XPSystem/App.config @@ -3,7 +3,7 @@ - + @@ -25,6 +25,10 @@ + + + + \ No newline at end of file diff --git a/XPSystem/BuiltInProviders/Display/Patch/MyNickPatchXPDisplayProvider.cs b/XPSystem/BuiltInProviders/Display/Patch/MyNickPatchXPDisplayProvider.cs index e937720..ab42f79 100644 --- a/XPSystem/BuiltInProviders/Display/Patch/MyNickPatchXPDisplayProvider.cs +++ b/XPSystem/BuiltInProviders/Display/Patch/MyNickPatchXPDisplayProvider.cs @@ -14,7 +14,7 @@ internal static class NicknamePatch { public static void Prefix(NicknameSync __instance, ref string value) { - if (__instance._hub == ReferenceHub.HostHub) + if (__instance._hub.IsHost) return; foreach (IXPDisplayProvider provider in XPAPI.DisplayProviders) diff --git a/XPSystem/BuiltInProviders/Display/Patch/RankSetXPDisplayProvider.cs b/XPSystem/BuiltInProviders/Display/Patch/RankSetXPDisplayProvider.cs index 84e5711..5a35fd9 100644 --- a/XPSystem/BuiltInProviders/Display/Patch/RankSetXPDisplayProvider.cs +++ b/XPSystem/BuiltInProviders/Display/Patch/RankSetXPDisplayProvider.cs @@ -65,7 +65,7 @@ private Badge GetBadge(XPPlayer player, PlayerInfoWrapper playerInfo) private void Refresh(XPPlayer player, PlayerInfoWrapper playerInfo = null) { - var badge = GetBadge(player, playerInfo ?? XPAPI.GetPlayerInfo(player)); + Badge badge = GetBadge(player, playerInfo ?? XPAPI.GetPlayerInfo(player)); if (badge == null) return; diff --git a/XPSystem/BuiltInProviders/LiteDB/LiteDBPlayerInfo.cs b/XPSystem/BuiltInProviders/LiteDB/LiteDBPlayerInfo.cs index 74826b4..4f4bb31 100644 --- a/XPSystem/BuiltInProviders/LiteDB/LiteDBPlayerInfo.cs +++ b/XPSystem/BuiltInProviders/LiteDB/LiteDBPlayerInfo.cs @@ -4,28 +4,49 @@ using XPSystem.API.Enums; using XPSystem.API.StorageProviders.Models; - public class LiteDBPlayerInfo + public class LiteDBNumberPlayerInfo : LiteDBPlayerInfo { [BsonId] public ulong Id { get; set; } + + public override T SetId(object id) + { + Id = (ulong)id; + return (T)(object)this; + } + + protected override IPlayerId toPlayerId(AuthType authType) => new NumberPlayerId(Id, authType); + } + + public class LiteDBStringPlayerInfo : LiteDBPlayerInfo + { + [BsonId] + public string Id { get; set; } + + public override T SetId(object id) + { + Id = (string)id; + return (T)(object)this; + } + + protected override IPlayerId toPlayerId(AuthType authType) => new StringPlayerId(Id, authType); + } + + public abstract class LiteDBPlayerInfo + { public int XP { get; set; } #if STORENICKS public string Nickname { get; set; } #endif - /// - /// Returns a from this . - /// - /// The of the player. + public abstract T SetId(object id) where T : LiteDBPlayerInfo; + + protected abstract IPlayerId toPlayerId(AuthType authType); public PlayerInfo ToPlayerInfo(AuthType authType) { return new PlayerInfo { - Player = new PlayerId() - { - Id = Id, - AuthType = authType - }, + Player = toPlayerId(authType), XP = XP, #if STORENICKS Nickname = Nickname diff --git a/XPSystem/BuiltInProviders/LiteDB/LiteDBProvider.cs b/XPSystem/BuiltInProviders/LiteDB/LiteDBProvider.cs index 3b825e2..0b9e063 100644 --- a/XPSystem/BuiltInProviders/LiteDB/LiteDBProvider.cs +++ b/XPSystem/BuiltInProviders/LiteDB/LiteDBProvider.cs @@ -10,9 +10,9 @@ public class LiteDBProvider : StorageProvider { - public ILiteCollection SteamCollection { get; private set; } - public ILiteCollection DiscordCollection { get; private set; } - public ILiteCollection NWCollection { get; private set; } + public ILiteCollection SteamCollection { get; private set; } + public ILiteCollection DiscordCollection { get; private set; } + public ILiteCollection NWCollection { get; private set; } private LiteDatabase database; @@ -20,13 +20,13 @@ public override void Initialize() { database = new LiteDatabase(Config.File); - SteamCollection = database.GetCollection("playerinfo_steam"); + SteamCollection = database.GetCollection("playerinfo_steam"); SteamCollection.EnsureIndex(x => x.Id); - DiscordCollection = database.GetCollection("playerinfo_discord"); + DiscordCollection = database.GetCollection("playerinfo_discord"); DiscordCollection.EnsureIndex(x => x.Id); - NWCollection = database.GetCollection("playerinfo_nw"); + NWCollection = database.GetCollection("playerinfo_nw"); NWCollection.EnsureIndex(x => x.Id); if (Config.IndexDB) @@ -48,20 +48,27 @@ public override void Dispose() database.Dispose(); database = null; } - - public ILiteCollection GetCollection(PlayerId playerId) => playerId.AuthType switch - { - AuthType.Steam => SteamCollection, - AuthType.Discord => DiscordCollection, - AuthType.Northwood => NWCollection, - _ => throw new ArgumentOutOfRangeException(nameof(playerId.AuthType), playerId.AuthType, null) - }; - protected override bool TryGetPlayerInfoNoCache(PlayerId playerId, out PlayerInfo playerInfo) + public LiteDBPlayerInfo TryGetPlayerInfo(IPlayerId playerId) => TryGetPlayerInfo(playerId); + public T TryGetPlayerInfo(IPlayerId playerId) where T : LiteDBPlayerInfo { - var collection = GetCollection(playerId); - var existing = collection.FindOne(x => x.Id == playerId.Id); // See note on SetPlayerInfoNoCache + switch (playerId.AuthType) + { + // FindById no work; BsonValue converts ulong to decimal, key is different; retarded conversion + case AuthType.Steam when playerId is NumberPlayerId numberPlayerId: + return (T)(object)SteamCollection.FindOne(x => x.Id == numberPlayerId.IdNumber); + case AuthType.Discord when playerId is NumberPlayerId numberPlayerId: + return (T)(object)DiscordCollection.FindOne(x => x.Id == numberPlayerId.IdNumber); + case AuthType.Northwood when playerId is StringPlayerId stringPlayerId: + return (T)(object)NWCollection.FindOne(x => x.Id == stringPlayerId.IdString); + default: + throw new ArgumentOutOfRangeException(nameof(playerId.AuthType), playerId.AuthType, null); + } + } + protected override bool TryGetPlayerInfoNoCache(IPlayerId playerId, out PlayerInfo playerInfo) + { + LiteDBPlayerInfo existing = TryGetPlayerInfo(playerId); if (existing == null) { playerInfo = null; @@ -72,23 +79,32 @@ protected override bool TryGetPlayerInfoNoCache(PlayerId playerId, out PlayerInf return true; } - protected override PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(PlayerId playerId) + protected override PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(IPlayerId playerId) { - var collection = GetCollection(playerId); - var existing = collection.FindOne(x => x.Id == playerId.Id); // See note on SetPlayerInfoNoCache - - if (existing == null) - { - existing = new LiteDBPlayerInfo() - { - Id = playerId.Id, - XP = 0 - }; + LiteDBPlayerInfo existing = TryGetPlayerInfo(playerId); + if (existing != null) + return existing.ToPlayerInfo(playerId.AuthType); - collection.Insert(existing); + switch (playerId.AuthType) + { + case AuthType.Steam: + return GetPlayerInfoAndCreateOfNotExistNoCache(playerId, SteamCollection); + case AuthType.Discord: + return GetPlayerInfoAndCreateOfNotExistNoCache(playerId, DiscordCollection); + case AuthType.Northwood: + return GetPlayerInfoAndCreateOfNotExistNoCache(playerId, NWCollection); + default: + throw new ArgumentOutOfRangeException(nameof(playerId.AuthType), playerId.AuthType, null); } - - return existing.ToPlayerInfo(playerId.AuthType); + } + protected PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(IPlayerId playerId, ILiteCollection collection) where T : LiteDBPlayerInfo, new() + { + T info = new T() + { + XP = 0 + }.SetId(playerId.Id); + collection.Insert(info); + return info.ToPlayerInfo(playerId.AuthType); } public override IEnumerable GetTopPlayers(int count) @@ -120,19 +136,33 @@ public override IEnumerable GetTopPlayers(int count) protected override void SetPlayerInfoNoCache(PlayerInfo playerInfo) { - var collection = GetCollection(playerInfo.Player); - var existing = collection.FindOne(x => x.Id == playerInfo.Player.Id); // FindById no work; BsonValue converts ulong to decimal, key is different; retarded conversion - + switch (playerInfo.Player.AuthType) + { + case AuthType.Steam: + SetPlayerInfoNoCache(playerInfo, SteamCollection); + break; + case AuthType.Discord: + SetPlayerInfoNoCache(playerInfo, DiscordCollection); + break; + case AuthType.Northwood: + SetPlayerInfoNoCache(playerInfo, NWCollection); + break; + default: + throw new ArgumentOutOfRangeException(nameof(playerInfo.Player.AuthType), playerInfo.Player.AuthType, null); + } + } + protected void SetPlayerInfoNoCache(PlayerInfo playerInfo, ILiteCollection collection) where T : LiteDBPlayerInfo, new() + { + T existing = TryGetPlayerInfo(playerInfo.Player); if (existing == null) { - collection.Insert(new LiteDBPlayerInfo() + collection.Insert(new T() { - Id = playerInfo.Player.Id, XP = playerInfo.XP, #if STORENICKS Nickname = playerInfo.Nickname #endif - }); + }.SetId(playerInfo.Player.Id)); } else { @@ -144,10 +174,19 @@ protected override void SetPlayerInfoNoCache(PlayerInfo playerInfo) } } - protected override bool DeletePlayerInfoNoCache(PlayerId playerId) + protected override bool DeletePlayerInfoNoCache(IPlayerId playerId) { - var collection = GetCollection(playerId); - return collection.Delete(playerId.Id); + switch (playerId.AuthType) + { + case AuthType.Steam when playerId is NumberPlayerId numberPlayerId: + return SteamCollection.Delete(numberPlayerId.IdNumber); + case AuthType.Discord when playerId is NumberPlayerId numberPlayerId: + return DiscordCollection.Delete(numberPlayerId.IdNumber); + case AuthType.Northwood when playerId is StringPlayerId stringPlayerId: + return NWCollection.Delete(stringPlayerId.IdString); + default: + throw new ArgumentOutOfRangeException(nameof(playerId.AuthType), playerId.AuthType, null); + } } protected override void DeleteAllPlayerInfoNoCache() diff --git a/XPSystem/BuiltInProviders/MySql/MySqlProvider.cs b/XPSystem/BuiltInProviders/MySql/MySqlProvider.cs index b380214..2bb7f5b 100644 --- a/XPSystem/BuiltInProviders/MySql/MySqlProvider.cs +++ b/XPSystem/BuiltInProviders/MySql/MySqlProvider.cs @@ -16,15 +16,15 @@ public class MySqlProvider : StorageProvider public override void Initialize() { - using var connection = GetConnection(); + using MySqlConnection connection = GetConnection(); foreach (AuthType authType in Enum.GetValues(typeof(AuthType))) { - using var command = connection.CreateCommand(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"CREATE TABLE IF NOT EXISTS {GetTableName(authType)} (" + - "id BIGINT UNSIGNED PRIMARY KEY," + - "xp int UNSIGNED NOT NULL DEFAULT 0" + + (authType == AuthType.Northwood ? "id VARCHAR(32) PRIMARY KEY" : "id BIGINT UNSIGNED PRIMARY KEY") + + ",xp int UNSIGNED NOT NULL DEFAULT 0" + #if STORENICKS ",nickname VARCHAR(64)" + #endif @@ -38,24 +38,27 @@ public override void Initialize() public override IEnumerable GetTopPlayers(int count) { - using var connection = GetConnection(); + using MySqlConnection connection = GetConnection(); List topPlayers = new(); foreach (AuthType authType in Enum.GetValues(typeof(AuthType))) { - using var command = connection.CreateCommand(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"SELECT * FROM {GetTableName(authType)} ORDER BY xp DESC LIMIT {count}"; - using var reader = command.ExecuteReader(); + using MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { - topPlayers.Add(FromReader(new PlayerId + var created = XPAPI.CreateUserId(reader.GetString(0), authType); + if (created == null) { - AuthType = authType, - Id = (ulong)reader.GetInt64(0) - }, reader)); + XPAPI.LogDebug("MYSQLProvider: GetTopPlayers - Failed to create player id with idstring: " + reader.GetString(0) + " and authtype: " + authType); + continue; + } + + topPlayers.Add(FromReader(reader, created)); } } @@ -65,14 +68,14 @@ public override IEnumerable GetTopPlayers(int count) .Select(x => new PlayerInfoWrapper(x)); } - protected override bool TryGetPlayerInfoNoCache(PlayerId playerId, out PlayerInfo playerInfo) + protected override bool TryGetPlayerInfoNoCache(IPlayerId playerId, out PlayerInfo playerInfo) { - using var connection = GetConnection(); - using var command = connection.CreateCommand(); + using MySqlConnection connection = GetConnection(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"SELECT * FROM {GetTableName(playerId.AuthType)} WHERE id = {playerId.Id}"; - using var reader = command.ExecuteReader(); + using MySqlDataReader reader = command.ExecuteReader(); if (!reader.Read()) { @@ -80,23 +83,23 @@ protected override bool TryGetPlayerInfoNoCache(PlayerId playerId, out PlayerInf return false; } - playerInfo = FromReader(playerId, reader); + playerInfo = FromReader(reader, playerId); return true; } - protected override PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(PlayerId playerId) + protected override PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(IPlayerId playerId) { - using var connection = GetConnection(); - using var command = connection.CreateCommand(); + using MySqlConnection connection = GetConnection(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"SELECT * FROM {GetTableName(playerId.AuthType)} WHERE id = {playerId.Id}"; - using var reader = command.ExecuteReader(); + using MySqlDataReader reader = command.ExecuteReader(); if (!reader.HasRows) { - using var insertConnection = GetConnection(); - using var insertCommand = insertConnection.CreateCommand(); + using MySqlConnection insertConnection = GetConnection(); + using MySqlCommand insertCommand = insertConnection.CreateCommand(); insertCommand.CommandText = $"INSERT INTO {GetTableName(playerId.AuthType)} (id, xp) VALUES ({playerId.Id}, 0)"; insertCommand.ExecuteNonQuery(); @@ -109,14 +112,14 @@ protected override PlayerInfo GetPlayerInfoAndCreateOfNotExistNoCache(PlayerId p } reader.Read(); - return FromReader(playerId, reader); + return FromReader(reader, playerId); } protected override void SetPlayerInfoNoCache(PlayerInfo playerInfo) { - using var connection = GetConnection(); + using MySqlConnection connection = GetConnection(); - using var command = connection.CreateCommand(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"REPLACE INTO {GetTableName(playerInfo.Player.AuthType)} (id, xp" + #if STORENICKS @@ -134,10 +137,10 @@ protected override void SetPlayerInfoNoCache(PlayerInfo playerInfo) command.ExecuteNonQuery(); } - protected override bool DeletePlayerInfoNoCache(PlayerId playerId) + protected override bool DeletePlayerInfoNoCache(IPlayerId playerId) { - using var connection = GetConnection(); - using var command = connection.CreateCommand(); + using MySqlConnection connection = GetConnection(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"DELETE FROM {GetTableName(playerId.AuthType)} WHERE id = {playerId.Id}"; @@ -146,17 +149,17 @@ protected override bool DeletePlayerInfoNoCache(PlayerId playerId) protected override void DeleteAllPlayerInfoNoCache() { - using var connection = GetConnection(); + using MySqlConnection connection = GetConnection(); foreach (AuthType authType in Enum.GetValues(typeof(AuthType))) { - using var command = connection.CreateCommand(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"DELETE FROM {GetTableName(authType)}"; command.ExecuteNonQuery(); } } - private PlayerInfo FromReader(PlayerId playerId, MySqlDataReader reader) + private PlayerInfo FromReader(MySqlDataReader reader, IPlayerId playerId = null) { return new PlayerInfo { @@ -168,7 +171,7 @@ private PlayerInfo FromReader(PlayerId playerId, MySqlDataReader reader) }; } - private void Log(object sender, MySqlInfoMessageEventArgs ev) => XPAPI.LogDebug(ev.ToString()); + private void Log(object sender, MySqlInfoMessageEventArgs ev) => XPAPI.LogDebug("MYSQLProvider: " + ev); public MySqlConnection GetConnection() { diff --git a/XPSystem/BuiltInProviders/MySql/MySqlTestCommand.cs b/XPSystem/BuiltInProviders/MySql/MySqlTestCommand.cs index 7f051a0..6c2d8f5 100644 --- a/XPSystem/BuiltInProviders/MySql/MySqlTestCommand.cs +++ b/XPSystem/BuiltInProviders/MySql/MySqlTestCommand.cs @@ -2,6 +2,7 @@ { using System; using CommandSystem; + using MySqlConnector; using XPSystem.API.Enums; using XPSystem.Commands; using static API.XPAPI; @@ -21,12 +22,12 @@ public override bool Execute(ArraySegment arguments, ICommandSender send try { - using var connection = mySqlProvider.GetConnection(); - using var command = connection.CreateCommand(); + using MySqlConnection connection = mySqlProvider.GetConnection(); + using MySqlCommand command = connection.CreateCommand(); command.CommandText = $"SELECT COUNT(*) FROM {mySqlProvider.GetTableName(AuthType.Steam)}"; - var count = (long)(command.ExecuteScalar() - ?? throw new NullReferenceException("Query returned null!")); + long count = (long)(command.ExecuteScalar() + ?? throw new NullReferenceException("Query returned null!")); response = $"Query success: {count} player entries in the steam table."; return true; } diff --git a/XPSystem/Commands/Admin/DatabasePlayerCommand.cs b/XPSystem/Commands/Admin/DatabasePlayerCommand.cs index 95df271..8180f06 100644 --- a/XPSystem/Commands/Admin/DatabasePlayerCommand.cs +++ b/XPSystem/Commands/Admin/DatabasePlayerCommand.cs @@ -23,7 +23,7 @@ public abstract class DatabasePlayerCommand : SanitizedInputCommand /// The targeted player's id, if found, otherwise 0. /// Whether the operation was successful (whether or not to return immediately after). /// If the argument count and the target player's argument position don't match, the sender will become the targeted player. - protected bool DoThingWithArgs(ref ArraySegment arguments, byte targetPlayerArgumentIndex, XPPlayer player, ref string response, out PlayerInfoWrapper playerInfo, out PlayerId playerId) + protected bool DoThingWithArgs(ref ArraySegment arguments, byte targetPlayerArgumentIndex, XPPlayer player, ref string response, out PlayerInfoWrapper playerInfo, out IPlayerId playerId) { playerId = default; playerInfo = default; @@ -31,7 +31,7 @@ protected bool DoThingWithArgs(ref ArraySegment arguments, byte targetPl // If player is specified. if (arguments.Count > targetPlayerArgumentIndex) { - var arg = arguments.At(targetPlayerArgumentIndex); + string arg = arguments.At(targetPlayerArgumentIndex); // Try to get player by name or user id. if (XPPlayer.TryGet(arg, out player)) { @@ -53,6 +53,12 @@ protected bool DoThingWithArgs(ref ArraySegment arguments, byte targetPl playerId = player.PlayerId; } + if (player.PlayerId == playerId && player.IsNPC) + { + response = "Player is not actual player, can't do that."; + return false; + } + if (XPAPI.StorageProvider.TryGetPlayerInfo(playerId, out playerInfo)) return true; diff --git a/XPSystem/Commands/Admin/Subcommands/GetCommandAdmin.cs b/XPSystem/Commands/Admin/Subcommands/GetCommandAdmin.cs index 34296ff..a6112f1 100644 --- a/XPSystem/Commands/Admin/Subcommands/GetCommandAdmin.cs +++ b/XPSystem/Commands/Admin/Subcommands/GetCommandAdmin.cs @@ -3,12 +3,13 @@ using System; using CommandSystem; using XPSystem.API; + using XPSystem.API.StorageProviders; public class GetCommandAdmin : DatabasePlayerCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.get", out var player)) + if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.get", out XPPlayer player)) { response = "You don't have permission (xps.get) to use this command."; return false; @@ -17,7 +18,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send XPAPI.EnsureStorageProviderValid(); response = null; - if (!DoThingWithArgs(ref arguments, 0, player, ref response, out var playerInfo, out var playerId)) + if (!DoThingWithArgs(ref arguments, 0, player, ref response, out PlayerInfoWrapper playerInfo, out var playerId)) return false; response = $"{playerId.ToString()} ({playerInfo.Nickname})] XP: {playerInfo.XP} (Level {playerInfo.Level})"; diff --git a/XPSystem/Commands/Admin/Subcommands/GiveCommand.cs b/XPSystem/Commands/Admin/Subcommands/GiveCommand.cs index 51560a6..d41f674 100644 --- a/XPSystem/Commands/Admin/Subcommands/GiveCommand.cs +++ b/XPSystem/Commands/Admin/Subcommands/GiveCommand.cs @@ -3,12 +3,13 @@ using System; using CommandSystem; using XPSystem.API; + using XPSystem.API.StorageProviders; public class GiveCommand : DatabasePlayerCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.give", out var player)) + if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.give", out XPPlayer player)) { response = "You don't have permission (xps.give) to use this command."; return false; @@ -20,7 +21,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send return false; } - var amountString = arguments.At(0); + string amountString = arguments.At(0); if (!int.TryParse(amountString, out int amount)) { response = $"Invalid amount: {amountString}."; @@ -28,7 +29,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send } response = null; - if (!DoThingWithArgs(ref arguments, 1, player, ref response, out var playerInfo, out var playerId)) + if (!DoThingWithArgs(ref arguments, 1, player, ref response, out PlayerInfoWrapper playerInfo, out var playerId)) return false; playerInfo.XP += amount; diff --git a/XPSystem/Commands/Admin/Subcommands/SetCommand.cs b/XPSystem/Commands/Admin/Subcommands/SetCommand.cs index 9dbb144..5844729 100644 --- a/XPSystem/Commands/Admin/Subcommands/SetCommand.cs +++ b/XPSystem/Commands/Admin/Subcommands/SetCommand.cs @@ -3,12 +3,13 @@ using System; using CommandSystem; using XPSystem.API; + using XPSystem.API.StorageProviders; public class SetCommand : DatabasePlayerCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.set", out var player)) + if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.set", out XPPlayer player)) { response = "You don't have permission (xps.set) to use this command."; return false; @@ -22,7 +23,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send return false; } - var amountString = arguments.At(0); + string amountString = arguments.At(0); if (!int.TryParse(amountString, out int amount) || amount < 0) { response = $"Invalid amount: {amountString}."; @@ -30,7 +31,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send } response = null; - if (!DoThingWithArgs(ref arguments, 1, player, ref response, out var playerInfo, out var playerId)) + if (!DoThingWithArgs(ref arguments, 1, player, ref response, out PlayerInfoWrapper playerInfo, out var playerId)) return false; playerInfo.XP = amount; diff --git a/XPSystem/Commands/Admin/Subcommands/SetLevelCommand.cs b/XPSystem/Commands/Admin/Subcommands/SetLevelCommand.cs index a3646b9..fe07b81 100644 --- a/XPSystem/Commands/Admin/Subcommands/SetLevelCommand.cs +++ b/XPSystem/Commands/Admin/Subcommands/SetLevelCommand.cs @@ -3,12 +3,13 @@ using System; using CommandSystem; using XPSystem.API; + using XPSystem.API.StorageProviders; public class SetLevelCommand : DatabasePlayerCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.setlevel", out var player)) + if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.setlevel", out XPPlayer player)) { response = "You don't have permission (xps.setlevel) to use this command."; return false; @@ -22,7 +23,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send return false; } - var levelString = arguments.At(0); + string levelString = arguments.At(0); if (!int.TryParse(levelString, out int level) || level < 0) { response = $"Invalid level: {levelString}."; @@ -30,7 +31,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send } response = null; - if (!DoThingWithArgs(ref arguments, 1, player, ref response, out var playerInfo, out var playerId)) + if (!DoThingWithArgs(ref arguments, 1, player, ref response, out PlayerInfoWrapper playerInfo, out var playerId)) return false; playerInfo.Level = level; diff --git a/XPSystem/Commands/Admin/Subcommands/ShowMessageCommand.cs b/XPSystem/Commands/Admin/Subcommands/ShowMessageCommand.cs index fcfa10c..afa23c1 100644 --- a/XPSystem/Commands/Admin/Subcommands/ShowMessageCommand.cs +++ b/XPSystem/Commands/Admin/Subcommands/ShowMessageCommand.cs @@ -3,11 +3,14 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Reflection; + using System.Text; using CommandSystem; using NorthwoodLib.Pools; using PlayerRoles; using XPSystem.API; using XPSystem.Config.Events; + using XPSystem.Config.Events.Types; public class ShowMessageCommand : SanitizedInputCommand { @@ -26,14 +29,14 @@ public override bool Execute(ArraySegment arguments, ICommandSender send } string key = arguments.At(0); - var role = RoleTypeId.None; + RoleTypeId role = RoleTypeId.None; if (key.StartsWith("default_")) key = key.Substring(8); - else if (XPPlayer.TryGet(sender, out var player)) + else if (XPPlayer.TryGet(sender, out XPPlayer player)) role = player.Role; - var file = XPECManager.GetFile(key, role); + XPECFile file = XPECManager.GetFile(key, role); if (file == null) { response = "No such XPEC file."; @@ -44,13 +47,13 @@ public override bool Execute(ArraySegment arguments, ICommandSender send if (arguments.Count > 1) { var types = file.ParametersTypes; - var subkeysStrings = arguments + string[] subkeysStrings = arguments .Skip(1) .ToArray(); for (int i = 0; i < subkeysStrings.Length; i++) { - var @string = subkeysStrings[i]; + string @string = subkeysStrings[i]; if (types.Length <= i) { subkeys.Add(@string); @@ -60,11 +63,11 @@ public override bool Execute(ArraySegment arguments, ICommandSender send bool success = false; Exception e = null; var argTypes = types[i]; - foreach (var type in argTypes) + foreach (Type type in argTypes) { try { - var converted = type.IsEnum + object converted = type.IsEnum ? Enum.Parse(type, @string, true) : Convert.ChangeType(@string, type); @@ -90,15 +93,15 @@ public override bool Execute(ArraySegment arguments, ICommandSender send } } - var item = file.Get(subkeys.ToArray()); + XPECItem item = file.Get(subkeys.ToArray()); if (item == null) { response = "Item null."; return false; } - var sb = StringBuilderPool.Shared.Rent(); - foreach (var property in item.GetType().GetProperties()) + StringBuilder sb = StringBuilderPool.Shared.Rent(); + foreach (PropertyInfo property in item.GetType().GetProperties()) sb.AppendLine($"{property.Name}: {property.GetValue(item)}"); response = StringBuilderPool.Shared.ToStringReturn(sb); diff --git a/XPSystem/Commands/Admin/Subcommands/VariablesCommand.cs b/XPSystem/Commands/Admin/Subcommands/VariablesCommand.cs index 2993d3e..0848f1b 100644 --- a/XPSystem/Commands/Admin/Subcommands/VariablesCommand.cs +++ b/XPSystem/Commands/Admin/Subcommands/VariablesCommand.cs @@ -1,6 +1,7 @@ namespace XPSystem.Commands.Admin.Subcommands { using System; + using System.Text; using CommandSystem; using NorthwoodLib.Pools; using XPSystem.API; @@ -9,7 +10,7 @@ public class VariablesCommand : SanitizedInputCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.variables", out var player)) + if (!XPPlayer.TryGetAndCheckPermission(sender, "xps.variables", out XPPlayer player)) { response = "You don't have permission (xps.variables) to use this command."; return false; @@ -30,7 +31,7 @@ public override bool Execute(ArraySegment arguments, ICommandSender send return true; } - var sb = StringBuilderPool.Shared.Rent(); + StringBuilder sb = StringBuilderPool.Shared.Rent(); sb.AppendLine("Variables:"); foreach (var kvp in player.Variables) diff --git a/XPSystem/Commands/Client/ClientAliasManager.cs b/XPSystem/Commands/Client/ClientAliasManager.cs index 03b4863..ee9ec55 100644 --- a/XPSystem/Commands/Client/ClientAliasManager.cs +++ b/XPSystem/Commands/Client/ClientAliasManager.cs @@ -19,7 +19,7 @@ public static void RegisterAliases() public static void UnregisterAliases() { - foreach (var alias in Aliases) + foreach (IAliasableCommand alias in Aliases) QueryProcessor.DotCommandHandler.UnregisterCommand(alias); } diff --git a/XPSystem/Commands/Client/Subcommands/GetCommandClient.cs b/XPSystem/Commands/Client/Subcommands/GetCommandClient.cs index c4b1aa8..53dcffe 100644 --- a/XPSystem/Commands/Client/Subcommands/GetCommandClient.cs +++ b/XPSystem/Commands/Client/Subcommands/GetCommandClient.cs @@ -3,18 +3,19 @@ using System; using CommandSystem; using XPSystem.API; + using XPSystem.API.StorageProviders; public class GetCommandClient : SanitizedInputCommand, IAliasableCommand { public override bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - if (!XPPlayer.TryGet(sender, out var player)) + if (!XPPlayer.TryGet(sender, out XPPlayer player)) { response = "This command is player only."; return false; } - var log = player.GetPlayerInfo(); + PlayerInfoWrapper log = player.GetPlayerInfo(); response = $"LVL: {log.Level} | XP: {log.XP} | Needed XP: {log.NeededXPNext}"; return true; diff --git a/XPSystem/Config/Events/Types/XPECDictFile.cs b/XPSystem/Config/Events/Types/XPECDictFile.cs index 6540e60..8e927f5 100644 --- a/XPSystem/Config/Events/Types/XPECDictFile.cs +++ b/XPSystem/Config/Events/Types/XPECDictFile.cs @@ -21,7 +21,7 @@ public override XPECItem Get(params object[] keys) if (keys == null || keys.Length == 0) return Default; - var keyObj = keys[0]; + object keyObj = keys[0]; if (keyObj is not T key) throw new InvalidCastException($"Key is not of the correct type (was: {keyObj.GetType().FormatType()}, expected: {typeof(T).FormatType()})"); @@ -31,7 +31,7 @@ public override XPECItem Get(params object[] keys) return Default; } - return Items.TryGetValue(key, out var item) + return Items.TryGetValue(key, out XPECItem item) ? item : Default; } diff --git a/XPSystem/Config/Events/Types/XPECFile.cs b/XPSystem/Config/Events/Types/XPECFile.cs index f405504..c855052 100644 --- a/XPSystem/Config/Events/Types/XPECFile.cs +++ b/XPSystem/Config/Events/Types/XPECFile.cs @@ -2,6 +2,7 @@ { using System; using System.IO; + using System.Reflection; using YamlDotNet.Core; using YamlDotNet.Core.Events; using static API.XPAPI; @@ -47,14 +48,14 @@ public virtual XPECItem Get(params object[] keys) /// The parser to read from. public virtual void Read(IParser parser) { - var type = GetType(); + Type type = GetType(); while (!parser.Accept(out MappingEnd _)) { - if (!parser.TryConsume(out var scalar)) + if (!parser.TryConsume(out Scalar scalar)) throw new InvalidDataException("Invalid YAML content: Expected scalar key."); - var property = type.GetProperty(scalar.Value); + PropertyInfo property = type.GetProperty(scalar.Value); if (property == null) { LogWarn("Skipping serialization of unknown property: " + scalar.Value); @@ -73,7 +74,7 @@ public virtual void Read(IParser parser) /// The emitter to emit to. public virtual void Write(IEmitter emitter) { - foreach (var property in GetType().GetProperties()) + foreach (PropertyInfo property in GetType().GetProperties()) { if (property.GetMethod == null || property.SetMethod == null) continue; diff --git a/XPSystem/Config/Events/Types/XPECFileCollection.cs b/XPSystem/Config/Events/Types/XPECFileCollection.cs index 8c05704..0bd0c33 100644 --- a/XPSystem/Config/Events/Types/XPECFileCollection.cs +++ b/XPSystem/Config/Events/Types/XPECFileCollection.cs @@ -26,7 +26,7 @@ public XPECItem Get(string key, params object[] subkeys) if (string.IsNullOrWhiteSpace(key)) return null; - return Files.TryGetValue(key, out var file) + return Files.TryGetValue(key, out XPECFile file) ? file.Get(subkeys) : null; } diff --git a/XPSystem/Config/Events/XPECManager.cs b/XPSystem/Config/Events/XPECManager.cs index 53e5a2a..e689c51 100644 --- a/XPSystem/Config/Events/XPECManager.cs +++ b/XPSystem/Config/Events/XPECManager.cs @@ -46,10 +46,10 @@ public static class XPECManager }, Items = new () { - [ItemCategory.MicroHID] = new () + [ItemCategory.SpecialWeapon] = new () { Amount = 50, - Translation = "You upgraded the micro!" + Translation = "You upgraded a special weapon!" } } }, @@ -63,10 +63,10 @@ public static class XPECManager }, Items = new () { - [ItemCategory.MicroHID] = new () + [ItemCategory.SpecialWeapon] = new () { Amount = 30, - Translation = "You picked up the micro!" + Translation = "You picked up a special weapon!" } } }, @@ -80,10 +80,10 @@ public static class XPECManager }, Items = new () { - [ItemCategory.MicroHID] = new () + [ItemCategory.SpecialWeapon] = new () { Amount = 10, - Translation = "You dropped the micro!" + Translation = "You dropped a special weapon!" } } }, @@ -100,6 +100,11 @@ public static class XPECManager { Amount = 5, Translation = "You used a medkit!" + }, + [ItemType.SCP1344] = new() + { + Amount = 0, + Translation = "(Can be spammed, disabled)" } } }, @@ -204,7 +209,7 @@ public static class XPECManager /// The override collection for the role. public static XPECFileCollection GetCollection(RoleTypeId role = RoleTypeId.None) { - if (role == RoleTypeId.None || !Overrides.TryGetValue(role, out var collection)) + if (role == RoleTypeId.None || !Overrides.TryGetValue(role, out XPECFileCollection collection)) collection = Default; return collection; @@ -218,13 +223,13 @@ public static XPECFileCollection GetCollection(RoleTypeId role = RoleTypeId.None /// The file, if found, otherwise null. public static XPECFile GetFile(string key, RoleTypeId role = RoleTypeId.None) { - if (Overrides.TryGetValue(role, out var collection)) + if (Overrides.TryGetValue(role, out XPECFileCollection collection)) { - if (collection.Files.TryGetValue(key, out var file)) + if (collection.Files.TryGetValue(key, out XPECFile file)) return file; } - if (Default.Files.TryGetValue(key, out var defaultFile)) + if (Default.Files.TryGetValue(key, out XPECFile defaultFile)) return defaultFile; LogDebug("Could not find XPEC file with key " + key); @@ -241,7 +246,7 @@ public static XPECFile GetFile(string key, RoleTypeId role = RoleTypeId.None) /// Thrown if the file is not of the specified type. public static T GetFile(string key, RoleTypeId role = RoleTypeId.None) where T : XPECFile { - var file = GetFile(key, role); + XPECFile file = GetFile(key, role); return file switch { null => null, @@ -260,8 +265,8 @@ public static T GetFile(string key, RoleTypeId role = RoleTypeId.None) where /// The item, if found, otherwise null. public static XPECItem GetItem(string key, RoleTypeId role = RoleTypeId.None, params object[] subkeys) { - var file = GetFile(key, role); - var item = file?.Get(subkeys); + XPECFile file = GetFile(key, role); + XPECItem item = file?.Get(subkeys); return item; } @@ -273,7 +278,7 @@ public static void Load(string dir) .Where(x => !_skipRoles.Contains(x)); Default = LoadInternal(Path.Combine(dir, "!default"), true); - foreach (var role in values) + foreach (RoleTypeId role in values) Overrides[role] = LoadInternal(Path.Combine(dir, role.ToString())); } @@ -288,7 +293,7 @@ private static XPECFileCollection LoadInternal(string dir, bool isNeeded = false try { string data = File.ReadAllText(file); - var deserialized = Deserializer.Deserialize(data); + XPECFile deserialized = Deserializer.Deserialize(data); string key = file .Replace("\\", "/") .Replace(dirFormatted, "") @@ -308,7 +313,7 @@ private static XPECFileCollection LoadInternal(string dir, bool isNeeded = false { foreach (var needed in NeededFiles) { - if (collection.Files.TryGetValue(needed.Key, out var found)) + if (collection.Files.TryGetValue(needed.Key, out XPECFile found)) { if (!found.IsEqualType(needed.Value)) { diff --git a/XPSystem/EventHandlers/LoaderSpecific/ExiledEventHandlers.cs b/XPSystem/EventHandlers/LoaderSpecific/ExiledEventHandlers.cs index 022eb50..c356bc6 100644 --- a/XPSystem/EventHandlers/LoaderSpecific/ExiledEventHandlers.cs +++ b/XPSystem/EventHandlers/LoaderSpecific/ExiledEventHandlers.cs @@ -1,7 +1,6 @@ namespace XPSystem.EventHandlers.LoaderSpecific { using System; - using Exiled.Events.EventArgs.Interfaces; using Exiled.Events.EventArgs.Player; using Exiled.Events.EventArgs.Scp049; using Exiled.Events.EventArgs.Scp914; diff --git a/XPSystem/EventHandlers/UnifiedEventHandlers.cs b/XPSystem/EventHandlers/UnifiedEventHandlers.cs index 85c51d9..8d23b43 100644 --- a/XPSystem/EventHandlers/UnifiedEventHandlers.cs +++ b/XPSystem/EventHandlers/UnifiedEventHandlers.cs @@ -3,11 +3,13 @@ using System; using System.Diagnostics; using System.Linq; + using System.Reflection; using MEC; using PlayerRoles; using XPSystem.API; using XPSystem.API.StorageProviders; using XPSystem.Config.Events; + using XPSystem.Config.Events.Types; using static XPSystem.API.XPAPI; public class UnifiedEventHandlers @@ -34,7 +36,7 @@ protected bool IsNull(T obj) { if (obj == null) { - var method = new StackTrace() + MethodBase method = new StackTrace() .GetFrame(1) .GetMethod(); @@ -59,7 +61,7 @@ protected void OnPlayerJoined(XPPlayer player) Timing.CallDelayed(.5f + Config.ExtraDelay, () => { - var playerInfo = player.GetPlayerInfo(); + PlayerInfoWrapper playerInfo = player.GetPlayerInfo(); XPPlayerJoined.Invoke(player, playerInfo); #if STORENICKS UpdateNickname(player); @@ -85,7 +87,7 @@ protected void OnRoundEnded(RoundSummary.LeadingTeam leadingTeam) if (!Config.XPAfterRoundEnd) XPGainPaused = true; - var roundwin = XPECManager.GetItem("win"); + XPECItem roundwin = XPECManager.GetItem("win"); foreach (var kvp in XPPlayer.Players) { if (kvp.Value.LeadingTeam == leadingTeam) diff --git a/XPSystem/FodyWeavers.xml b/XPSystem/FodyWeavers.xml index 524cebe..1794ad5 100644 --- a/XPSystem/FodyWeavers.xml +++ b/XPSystem/FodyWeavers.xml @@ -13,6 +13,7 @@ System.Buffers System.Diagnostics.DiagnosticSource + System.Memory System.Numerics.Vectors System.Threading.Tasks.Extensions diff --git a/XPSystem/Main.cs b/XPSystem/Main.cs index cbad0ab..692d541 100644 --- a/XPSystem/Main.cs +++ b/XPSystem/Main.cs @@ -21,7 +21,7 @@ public class Main : Exiled.API.Features.Plugin #endif { - public const string VersionString = "2.0.7"; + public const string VersionString = "2.0.8"; /// /// This number is increased every time the plugin is reloaded. @@ -133,9 +133,9 @@ public void OnReloaded() public void SetDisplayProviders(IEnumerable typeNames) { - foreach (var typeName in typeNames) + foreach (string typeName in typeNames) { - if (!TryCreate(typeName, out var exception, out IXPDisplayProvider provider)) + if (!TryCreate(typeName, out Exception exception, out IXPDisplayProvider provider)) { LogError($"Could not create display provider {typeName}: {exception}"); continue; @@ -179,7 +179,7 @@ public static bool TryCreate(string typeName, out Exception exception, out T try { - var type = Type.GetType(typeName) ?? throw new TypeLoadException("Type not found!"); + Type type = Type.GetType(typeName) ?? throw new TypeLoadException("Type not found!"); obj = (T)Activator.CreateInstance(type); } catch (Exception e) diff --git a/XPSystem/XPSystem.csproj b/XPSystem/XPSystem.csproj index b6ec2c8..3a80ba1 100644 --- a/XPSystem/XPSystem.csproj +++ b/XPSystem/XPSystem.csproj @@ -53,6 +53,7 @@ MySqlConnector System.Threading.Tasks.Extensions System.Buffers + System.Memory System.Numerics.Vectors Microsoft.Extensions.Logging.Abstractions System.Diagnostics.DiagnosticSource @@ -85,35 +86,35 @@ ..\packages\Lib.Harmony.2.2.2\lib\net48\0Harmony.dll - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Assembly-CSharp-Publicized.dll + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Assembly-CSharp-Publicized.dll - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\CommandSystem.Core.dll + ..\packages\ExMod.Exiled.9.1.1\lib\net48\CommandSystem.Core.dll ..\packages\Costura.Fody.5.8.0-alpha0098\lib\netstandard1.0\Costura.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.API.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.API.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.CreditTags.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CreditTags.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.CustomItems.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CustomItems.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.CustomRoles.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.CustomRoles.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.Events.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Events.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.Loader.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Loader.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.Permissions.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\Exiled.Permissions.dll ..\packages\Flee.1.2.2\lib\net45\Flee.Net45.dll @@ -130,14 +131,14 @@ ..\packages\MySqlConnector.2.3.7\lib\net48\MySqlConnector.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\NorthwoodLib.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\NorthwoodLib.dll ..\refs\NWAPIPermissionSystem.dll - - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\PluginAPI.dll + + ..\packages\ExMod.Exiled.9.1.1\lib\net48\PluginAPI.dll @@ -175,7 +176,7 @@ - ..\packages\EXILEDOFFICIAL.8.11.0\lib\net48\YamlDotNet.dll + ..\packages\ExMod.Exiled.9.1.1\lib\net48\YamlDotNet.dll @@ -196,8 +197,10 @@ - + + + diff --git a/XPSystem/packages.config b/XPSystem/packages.config index 7211b2a..686b6f3 100644 --- a/XPSystem/packages.config +++ b/XPSystem/packages.config @@ -1,7 +1,7 @@  - +