modified ConfigPlugin touse null prop
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user