using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;

namespace PartySystem;

[ApiVersion(2, 1)]
public class Main : TerrariaPlugin
{
    public override string Name => "Parties";
    public static Version Version_Static => new Version(1, 0, 0);
    public override Version Version => Version_Static;
    public override string Author => "Discipile";
    public override string Description => "Adds a system that implements player-managed parties.";
    public Main(Terraria.Main game) : base(game)
    {

    }

    public override void Initialize()
    {

        Commands.ChatCommands.RemoveAll(c => c.HasAlias("party")); // Remove TShock's /party command
        Commands.ChatCommands.RemoveAll(c => c.HasAlias("p")); // Remove TShock's /p command

        Commands.ChatCommands.Add(new Command("partysys.cmdhandler", Controller.PartyCommandHandler, "party", "pa"));
        Commands.ChatCommands.Add(new Command("partysys.logoutmask", Controller.OnPlayerLogout, "logout"));


        ServerApi.Hooks.ServerLeave.Register(this, Controller.OnPlayerLeave);
        //ServerApi.Hooks.ServerJoin.Register(this, Controller.OnPlayerJoin);
        PlayerHooks.PlayerPostLogin += new PlayerHooks.PlayerPostLoginD(Controller.OnPlayerLogin);
        ServerApi.Hooks.GameUpdate.Register(this, Controller.OnUpdate);
    }
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {

            ServerApi.Hooks.ServerLeave.Deregister(this, Controller.OnPlayerLeave);
            //ServerApi.Hooks.ServerJoin.Deregister(this, Controller.OnPlayerJoin);
            PlayerHooks.PlayerPostLogin -= new PlayerHooks.PlayerPostLoginD(Controller.OnPlayerLogin);
            ServerApi.Hooks.GameUpdate.Deregister(this, Controller.OnUpdate);
        }
        base.Dispose(disposing);
    }
}