Skip to content

Commit

Permalink
ran code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderBr committed Dec 14, 2023
1 parent 187d768 commit 07eee45
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 36 deletions.
6 changes: 3 additions & 3 deletions TSEconomy/Api/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static class Api
/// Private reference to our database, can only be accessed from Api class members
/// </summary>
private static IDatabase DB => TSEconomy.DB.DB;

// ? why are we splitting these?
private static List<Currency> currencies = new List<Currency>();
private static List<Currency> currencies = new();
public static List<Currency> Currencies
{
get
Expand All @@ -38,7 +38,7 @@ public static List<Currency> Currencies
InternalName = "sys",
Symbol = "^"
};

public static List<BankAccount> BankAccounts
{
get
Expand Down
2 changes: 1 addition & 1 deletion TSEconomy/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal abstract class CommandBase
public string[] GetAliases()
{
var aliases = TSEconomy.Config.Aliases.GetAliases(this);
if(aliases.Length < 1)
if (aliases.Length < 1)
{
Disabled = true;
}
Expand Down
4 changes: 2 additions & 2 deletions TSEconomy/Commands/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ internal class Commands
{
public static void RegisterAll()
{
foreach (CommandBase cmd in List.Where(x=>x.Disabled==false))
foreach (CommandBase cmd in List.Where(x => x.Disabled == false))
{
TShockAPI.Commands.ChatCommands.Add(cmd);
}
}

public static void Refresh()
{
foreach(CommandBase cmd in List.Where(x=>x.Disabled==false))
foreach (CommandBase cmd in List.Where(x => x.Disabled == false))
{
TShockAPI.Commands.ChatCommands.RemoveAll(x => x.CommandDelegate == cmd.Execute);
TShockAPI.Commands.ChatCommands.Add(cmd);
Expand Down
2 changes: 1 addition & 1 deletion TSEconomy/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void Save()
{
Instance ??= new Configuration();

if(!Directory.Exists(TSEconomy.PluginDirectory))
if (!Directory.Exists(TSEconomy.PluginDirectory))
Directory.CreateDirectory(TSEconomy.PluginDirectory);

File.WriteAllText(s_path, JsonConvert.SerializeObject(Instance, Formatting.Indented));
Expand Down
2 changes: 1 addition & 1 deletion TSEconomy/Configuration/Models/Aliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TSEconomy.Configuration.Models
[JsonObject(MemberSerialization.OptIn)]
public class Aliases
{
internal string[] GetAliases(CommandBase command)
internal string[] GetAliases(CommandBase command)
{
return command switch
{
Expand Down
6 changes: 3 additions & 3 deletions TSEconomy/Configuration/Models/Currency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Currency
public bool IsSystemCurrency()
{
// uses a not frequenly used symbol, quite a goofy ahh implementation, we could switch to IDs and add a constructor for Currencies
return (DisplayName == "System-Cash" || InternalName == "sys" || Symbol == "^");
return DisplayName == "System-Cash" || InternalName == "sys" || Symbol == "^";
}

public static Currency? GetFirst()
Expand All @@ -28,8 +28,8 @@ public bool IsSystemCurrency()
public string GetName(double amount, bool showSymbol = true, bool showName = false, int DecimalsKept = 2)
{
string name;
string symbol = (showSymbol ? Symbol : "");
string symbol = showSymbol ? Symbol : "";

if (amount <= 1)
name = PrefixSymbol ? $"{symbol} {Math.Round(amount, DecimalsKept)} {(showName ? DisplayName : "")}" : $"{(showName ? DisplayName : "")} {Math.Round(amount, DecimalsKept)} {symbol}";

Expand Down
8 changes: 4 additions & 4 deletions TSEconomy/Database/Models/BankAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BankAccount
public static BankAccount? TryCreateNewAccount(double initialbalance, string internalCurrencyName, int userID, BankAccountProperties flags = BankAccountProperties.Default,
string transLog = "{0} has created a new bank account ({1}), with the initial value of {2}.")
{
if(transLog == "{0} has created a new bank account ({1}), with the initial value of {2}.")
if (transLog == "{0} has created a new bank account ({1}), with the initial value of {2}.")
transLog = Localization.TryGetString("{0} has created a new bank account ({1}), with the initial value of {2}.");

var curr = Currency.Get(internalCurrencyName);
Expand Down Expand Up @@ -75,7 +75,7 @@ public class BankAccount
// we have two variants as we might not want the logs to show -amount
public bool TryAddBalance(double amount, string transLog = "{0}'s balance has been increased by {1}. Old bal: {2} new bal: {3}")
{
if(transLog == "{0}'s balance has been increased by {1}. Old bal: {2} new bal: {3}")
if (transLog == "{0}'s balance has been increased by {1}. Old bal: {2} new bal: {3}")
transLog = Localization.TryGetString("{0}'s balance has been increased by {1}. Old bal: {2} new bal: {3}");

if (amount < 0)
Expand All @@ -96,7 +96,7 @@ public class BankAccount

public bool TryRemoveBalance(double amount, string transLog = "{0}'s balance has been decreased by {1}. Old bal: {2} new bal: {3}")
{
if(transLog == "{0}'s balance has been decreased by {1}. Old bal: {2} new bal: {3}")
if (transLog == "{0}'s balance has been decreased by {1}. Old bal: {2} new bal: {3}")
transLog = Localization.TryGetString("{0}'s balance has been decreased by {1}. Old bal: {2} new bal: {3}");

if (_balance < amount && !IsWorldAccount())
Expand All @@ -120,7 +120,7 @@ public class BankAccount
/// </summary>
public void SetBalance(double amount, string transLog = "{0}'s balance has been set to {1}. Old bal: {2}")
{
if(transLog == "{0}'s balance has been set to {1}. Old bal: {2}")
if (transLog == "{0}'s balance has been set to {1}. Old bal: {2}")
transLog = Localization.TryGetString("{0}'s balance has been set to {1}. Old bal: {2}");

double oldBalance = _balance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSEconomy.Database.Models.Properties
namespace TSEconomy.Database.Models.Properties
{
public enum TransactionProperties
{
Expand Down
6 changes: 3 additions & 3 deletions TSEconomy/Database/SqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public static string GenerateCreateTableStatement(Type type, DBType dbProvider)
private static string GetColumnType(Type type, DBType dbProvider)
{
// Simplified mapping, needs to be expanded based on actual requirements
if (type == typeof(int) || type == typeof(BankAccountProperties)
if (type == typeof(int) || type == typeof(BankAccountProperties)
|| type == typeof(TransactionProperties)) return "INTEGER";
if (type == typeof(double)) return "REAL";
if (type == typeof(string)) return (dbProvider == DBType.SQLite ? "TEXT" : "VARCHAR(255)");
if (type == typeof(string)) return dbProvider == DBType.SQLite ? "TEXT" : "VARCHAR(255)";
if (type == typeof(DateTime)) return "DATETIME";
if (type == typeof(byte[])) return "BLOB";
if (type == typeof(bool)) return (dbProvider == DBType.MySQL ? "BOOLEAN" : "INTEGER");
if (type == typeof(bool)) return dbProvider == DBType.MySQL ? "BOOLEAN" : "INTEGER";

throw new NotSupportedException($"Type {type} not supported.");
}
Expand Down
4 changes: 2 additions & 2 deletions TSEconomy/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public static class Helpers
// ?? is this necessary when TShock.UserAccounts.GetUserAccountByID exists
public static string? GetAccountName(int UserID)
{
if(UserID == -1)
if (UserID == -1)
{
return TSPlayer.Server.Name;
}

var user = TShock.UserAccounts.GetUserAccountByID(UserID);
if(user == null)
if (user == null)
{
return null;
}
Expand Down
18 changes: 9 additions & 9 deletions TSEconomy/Lang/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ public class KeyValue
{
public string Key { get; set; }
public string Value { get; set; }
public KeyValue()
public KeyValue()
{
Key = "";
Value = "";
}
public KeyValue(string key, string value)
public KeyValue(string key, string value)
{
Key = key;
Value = value;
}
}
internal static class Localization
{
public static List<string> SupportedLanguages = new List<string> { "Lang_en", "Lang_es", "Lang_ru" };
public static List<string> SupportedLanguages = new() { "Lang_en", "Lang_es", "Lang_ru" };

private static Dictionary<string, string> _localizedPluginTexts = new();

Expand All @@ -51,11 +51,11 @@ public static void SetupLanguage()

}

XmlSerializer serializer = new XmlSerializer(typeof(List<KeyValue>));
XmlSerializer serializer = new(typeof(List<KeyValue>));

using(XmlReader xmlReader = XmlReader.Create(Path.Combine(localizationDirectory, fileName)))
using (XmlReader xmlReader = XmlReader.Create(Path.Combine(localizationDirectory, fileName)))
{
List<KeyValue> list= (List<KeyValue>)serializer.Deserialize(xmlReader);
List<KeyValue> list = (List<KeyValue>)serializer.Deserialize(xmlReader);

Check warning on line 58 in TSEconomy/Lang/Localization.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

_localizedPluginTexts = list.ToDictionary(i => i.Key, i => i.Value);

Check warning on line 60 in TSEconomy/Lang/Localization.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'Dictionary<string, string> Enumerable.ToDictionary<KeyValue, string, string>(IEnumerable<KeyValue> source, Func<KeyValue, string> keySelector, Func<KeyValue, string> elementSelector)'.
}
Expand All @@ -66,10 +66,10 @@ public static void SetupLanguage()

public static string TryGetString(string key, string tag = "")
{
if(!_localizedPluginTexts.TryGetValue(key, out string value))
if (!_localizedPluginTexts.TryGetValue(key, out string value))

Check warning on line 69 in TSEconomy/Lang/Localization.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
value = key;

if(tag == "")
if (tag == "")
return value;

if (tag.Equals("plugin", StringComparison.CurrentCultureIgnoreCase))
Expand All @@ -83,7 +83,7 @@ private static void getFileName(out string name)
{
if (SupportedLanguages.Any(i => i == TSEconomy.Config.Language))
name = TSEconomy.Config.Language + ".xml";

else
{
name = "Lang_en.xml";
Expand Down

0 comments on commit 07eee45

Please sign in to comment.