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