2025-08-13 23:32:35 -04:00
|
|
|
|
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
|
2025-08-13 23:44:01 -04:00
|
|
|
|
public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "Config.json");
|
|
|
|
|
private Config? _config = new Config();
|
2025-08-13 23:32:35 -04:00
|
|
|
|
|
|
|
|
|
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!");
|
2025-08-13 23:44:01 -04:00
|
|
|
|
if (player.Name == _config?.Player)
|
2025-08-13 23:32:35 -04:00
|
|
|
|
{
|
|
|
|
|
player.SendInfoMessage(_config.CustomMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PerformConfigOperations()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(ConfigPath))
|
|
|
|
|
{
|
2025-08-13 23:44:01 -04:00
|
|
|
|
_config = Config.Read();
|
2025-08-13 23:32:35 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-08-13 23:44:01 -04:00
|
|
|
|
_config?.Write();
|
2025-08-13 23:32:35 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|