modified ConfigPlugin touse null prop

This commit is contained in:
2025-08-13 23:44:01 -04:00
parent 336af4e31a
commit a615c5851d
2 changed files with 6 additions and 11 deletions

View File

@@ -14,11 +14,6 @@ public class Config
public static Config? Read() public static Config? Read()
{ {
if (!File.Exists(ConfigPlugin.ConfigPath)) return !File.Exists(ConfigPlugin.ConfigPath) ? new Config() : JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigPlugin.ConfigPath));
{
return new Config();
}
return JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigPlugin.ConfigPath));
} }
} }

View File

@@ -14,8 +14,8 @@ namespace ConfigPlugin
public override Version Version => new Version(1, 0, 0, 0); public override Version Version => new Version(1, 0, 0, 0);
// instantiate our config class // instantiate our config class
public static string ConfigPath = Path.Combine(TShock.SavePath, "Config.json"); public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "Config.json");
private readonly Config _config = new Config(); private Config? _config = new Config();
public override void Initialize() public override void Initialize()
{ {
@@ -36,7 +36,7 @@ namespace ConfigPlugin
{ {
TSPlayer player = TShock.Players[args.Who]; TSPlayer player = TShock.Players[args.Who];
player.SendInfoMessage($"{player} has arrived!"); player.SendInfoMessage($"{player} has arrived!");
if (player.Name == _config.Player) if (player.Name == _config?.Player)
{ {
player.SendInfoMessage(_config.CustomMessage); player.SendInfoMessage(_config.CustomMessage);
} }
@@ -46,11 +46,11 @@ namespace ConfigPlugin
{ {
if (File.Exists(ConfigPath)) if (File.Exists(ConfigPath))
{ {
Config.Read(); _config = Config.Read();
} }
else else
{ {
_config.Write(); _config?.Write();
} }
} }