From 5aea4453b0af0210f25d3daa02824eb4a27b03e4 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 18 Aug 2025 22:50:41 -0400 Subject: [PATCH] initial commit got healing working only in the wrong way --- .envrc | 1 + .gitignore | 5 +++ HealingPlugin.cs | 61 ++++++++++++++++++++++++++++++++++++ TerrariaHealingPlugin.csproj | 12 +++++++ flake.lock | 40 +++++++++++++++++++++++ flake.nix | 46 +++++++++++++++++++++++++++ 6 files changed, 165 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 HealingPlugin.cs create mode 100644 TerrariaHealingPlugin.csproj create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5046e6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +.idea/ +.vscode/ +.vs/ diff --git a/HealingPlugin.cs b/HealingPlugin.cs new file mode 100644 index 0000000..09361d6 --- /dev/null +++ b/HealingPlugin.cs @@ -0,0 +1,61 @@ +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."); + } +} diff --git a/TerrariaHealingPlugin.csproj b/TerrariaHealingPlugin.csproj new file mode 100644 index 0000000..062f77b --- /dev/null +++ b/TerrariaHealingPlugin.csproj @@ -0,0 +1,12 @@ + + + net6.0 + enable + enable + + + + + + + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3c46761 --- /dev/null +++ b/flake.lock @@ -0,0 +1,40 @@ +{ + "nodes": { + "flake-schemas": { + "locked": { + "lastModified": 1721999734, + "narHash": "sha256-G5CxYeJVm4lcEtaO87LKzOsVnWeTcHGKbKxNamNWgOw=", + "rev": "0a5c42297d870156d9c57d8f99e476b738dcd982", + "revCount": 75, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.5/0190ef2f-61e0-794b-ba14-e82f225e55e6/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1755471983, + "narHash": "sha256-axUoWcm4cNQ36jOlnkD9D40LTfSQgk8ExfHSRm3rTtg=", + "rev": "48f4c982de68d966421d2b6f1ddbeb6227cc5ceb", + "revCount": 808437, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.808437%2Brev-48f4c982de68d966421d2b6f1ddbeb6227cc5ceb/0198be44-d6e9-7645-acdf-d6811d0e6b6b/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/%2A" + } + }, + "root": { + "inputs": { + "flake-schemas": "flake-schemas", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ba1ac56 --- /dev/null +++ b/flake.nix @@ -0,0 +1,46 @@ +# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.22) +{ + description = "Terraria Plugin flake"; + inputs = { + flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*"; + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*"; + }; + + outputs = { + self, + flake-schemas, + nixpkgs, + }: let + supportedSystems = ["x86_64-linux" "aarch64-darwin"]; + forEachSupportedSystem = f: + nixpkgs.lib.genAttrs supportedSystems (system: + f { + pkgs = import nixpkgs {inherit system;}; + }); + in { + schemas = flake-schemas.schemas; + + devShells = forEachSupportedSystem ({pkgs}: { + default = pkgs.mkShell { + packages = with pkgs; [ + curl + git + jq + wget + nixpkgs-fmt + dotnet-sdk_9 + dotnetPackages.Nuget + omnisharp-roslyn + mono + ]; + }; + + env = { + DOTNET_ROOT = "${pkgs.dotnet-sdk_9}/share/dotnet"; + DOTNET_GENERATE_ASPNET_CERTIFICATE = "false"; + DOTNET_NOLOGO = "true"; + DOTNET_CLI_TELEMETRY_OPTOUT = "false"; + }; + }); + }; +}