65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using Terraria;
|
|
using TShockAPI;
|
|
using TerrariaApi.Server;
|
|
using TShockAPI.Hooks;
|
|
|
|
namespace ConfigPlugin
|
|
{
|
|
[ApiVersion(2, 1)]
|
|
public class ConfigPlugin(Main game) : TerrariaPlugin(game)
|
|
{
|
|
public override string Author => "wymiller";
|
|
public override string Description => "A plugin that takes some configuration";
|
|
public override string Name => "Configuration Plugin";
|
|
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 override void Initialize()
|
|
{
|
|
GeneralHooks.ReloadEvent += OnReload;
|
|
ServerApi.Hooks.NetGreetPlayer.Register(this, OnJoin);
|
|
|
|
PerformConfigOperations();
|
|
|
|
Console.WriteLine("[ConfigPlugin] Plugin is loaded");
|
|
}
|
|
|
|
private void OnReload(ReloadEventArgs args)
|
|
{
|
|
PerformConfigOperations();
|
|
}
|
|
|
|
private void OnJoin(GreetPlayerEventArgs args)
|
|
{
|
|
TSPlayer player = TShock.Players[args.Who];
|
|
player.SendInfoMessage($"{player} has arrived!");
|
|
if (player.Name == _config.Player)
|
|
{
|
|
player.SendInfoMessage(_config.CustomMessage);
|
|
}
|
|
}
|
|
|
|
private void PerformConfigOperations()
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
Config.Read();
|
|
}
|
|
else
|
|
{
|
|
_config.Write();
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|
|
} |