using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using TShockAPI; using Terraria; using TerrariaApi.Server; namespace HelloWorldPlugin { [ApiVersion(2, 1)] public class HelloWorldPlugin : TerrariaPlugin { /// /// Gets the author(s) of this plugin /// public override string Author => "wymiller"; /// /// Gets the description of this plugin. /// A short, one lined description that tells people what your plugin does. /// public override string Description => "A hello world plugin"; /// /// Gets the name of this plugin. /// public override string Name => "Hello World Plugin"; /// /// Gets the version of this plugin. /// public override Version Version => new Version(1, 0, 0, 0); /// /// Initializes a new instance of the HelloWorldPlugin class. /// This is where you set the plugin's order and perfrom other constructor logic /// public HelloWorldPlugin(Main game) : base(game) { Console.WriteLine("[HelloWorldPlugin] Plugin is being loaded..."); } /// /// Handles plugin initialization. /// Fired when the server is started and the plugin is being loaded. /// You may register hooks, perform loading procedures etc here. /// public override void Initialize() { Console.WriteLine("[HelloWorldPlugin] Hello, World!"); ServerApi.Hooks.NetGreetPlayer.Register(this, OnPlayerJoin); } /// /// Handles the OnPlayerJoin event (called a hook) /// Fired on any player joining the game /// /// private void OnPlayerJoin(GreetPlayerEventArgs args) { var player = TShock.Players[args.Who]; if (player != null && player.Active) { player.SendMessage($"Hello, {player}!", Color.Green); } } /// /// Handles plugin disposal logic. /// *Supposed* to fire when the server shuts down. /// You should deregister hooks and free all resources here. /// protected override void Dispose(bool disposing) { if (disposing) { // Deregister hooks here if (disposing) { ServerApi.Hooks.NetGreetPlayer.Deregister(this, OnPlayerJoin); Console.WriteLine("[HelloWorldPlugin] Plugin is being unloaded..."); } } base.Dispose(disposing); } } }