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