62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Terraria;
|
|
using TShockAPI;
|
|
using TerrariaApi.Server;
|
|
|
|
namespace TerrariaHealingPlugin;
|
|
|
|
[ApiVersion(2, 1)]
|
|
public class HealingPlugin : TerrariaPlugin
|
|
{
|
|
public override string Author => "Sneefaria Maintainers";
|
|
public override string Name => "HealingPlugin";
|
|
public override string Description => "A healing plugin, duh";
|
|
public override Version Version => new Version(1, 0, 0);
|
|
private DateTime _lastCheck = DateTime.UtcNow;
|
|
|
|
public HealingPlugin(Main game) : base(game) { }
|
|
|
|
public override void Initialize()
|
|
{
|
|
ServerApi.Hooks.GamePostInitialize.Register(this, OnGamePostInitialize);
|
|
ServerApi.Hooks.ServerJoin.Register(this, OnServerJoin);
|
|
ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
ServerApi.Hooks.GamePostInitialize.Deregister(this, OnGamePostInitialize);
|
|
ServerApi.Hooks.ServerJoin.Deregister(this, OnServerJoin);
|
|
ServerApi.Hooks.GameUpdate.Deregister(this, OnUpdate);
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void OnUpdate(EventArgs args)
|
|
{
|
|
if ((DateTime.UtcNow - _lastCheck).TotalSeconds >= 1)
|
|
{
|
|
_lastCheck = DateTime.UtcNow;
|
|
|
|
foreach (var player in TShock.Players)
|
|
{
|
|
if (player != null && player.Active)
|
|
{
|
|
player.Heal(25); // heal all players 25 HP/second
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGamePostInitialize(EventArgs args)
|
|
{
|
|
TShock.Log.Info($"{Name} v{Version} has been initialized.");
|
|
}
|
|
|
|
private void OnServerJoin(JoinEventArgs args)
|
|
{
|
|
TShock.Log.Info($"{args.Who} has joined the server.");
|
|
}
|
|
}
|