89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Gets the author(s) of this plugin
|
|||
|
/// </summary>
|
|||
|
public override string Author => "wymiller";
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the description of this plugin.
|
|||
|
/// A short, one lined description that tells people what your plugin does.
|
|||
|
/// </summary>
|
|||
|
public override string Description => "A hello world plugin";
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the name of this plugin.
|
|||
|
/// </summary>
|
|||
|
public override string Name => "Hello World Plugin";
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the version of this plugin.
|
|||
|
/// </summary>
|
|||
|
public override Version Version => new Version(1, 0, 0, 0);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Initializes a new instance of the HelloWorldPlugin class.
|
|||
|
/// This is where you set the plugin's order and perfrom other constructor logic
|
|||
|
/// </summary>
|
|||
|
public HelloWorldPlugin(Main game) : base(game)
|
|||
|
{
|
|||
|
Console.WriteLine("[HelloWorldPlugin] Plugin is being loaded...");
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Handles plugin initialization.
|
|||
|
/// Fired when the server is started and the plugin is being loaded.
|
|||
|
/// You may register hooks, perform loading procedures etc here.
|
|||
|
/// </summary>
|
|||
|
public override void Initialize()
|
|||
|
{
|
|||
|
Console.WriteLine("[HelloWorldPlugin] Hello, World!");
|
|||
|
ServerApi.Hooks.NetGreetPlayer.Register(this, OnPlayerJoin);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Handles the OnPlayerJoin event (called a hook)
|
|||
|
/// Fired on any player joining the game
|
|||
|
/// </summary>
|
|||
|
/// <param name="args"></param>
|
|||
|
private void OnPlayerJoin(GreetPlayerEventArgs args)
|
|||
|
{
|
|||
|
var player = TShock.Players[args.Who];
|
|||
|
if (player != null && player.Active)
|
|||
|
{
|
|||
|
player.SendMessage($"Hello, {player}!", Color.Green);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Handles plugin disposal logic.
|
|||
|
/// *Supposed* to fire when the server shuts down.
|
|||
|
/// You should deregister hooks and free all resources here.
|
|||
|
/// </summary>
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|