Merge pull request #468 from Scavenger3/CommandEvent
Added PlayerCommand Event
This commit is contained in:
commit
2e13cae16f
2 changed files with 33 additions and 0 deletions
|
|
@ -241,6 +241,9 @@ namespace TShockAPI
|
||||||
string cmdName = args[0].ToLower();
|
string cmdName = args[0].ToLower();
|
||||||
args.RemoveAt(0);
|
args.RemoveAt(0);
|
||||||
|
|
||||||
|
if (Hooks.PlayerHooks.OnPlayerCommand(player, cmdName, cmdText, args))
|
||||||
|
return true;
|
||||||
|
|
||||||
IEnumerable<Command> cmds = ChatCommands.Where(c => c.HasAlias(cmdName));
|
IEnumerable<Command> cmds = ChatCommands.Where(c => c.HasAlias(cmdName));
|
||||||
|
|
||||||
if (cmds.Count() == 0)
|
if (cmds.Count() == 0)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
@ -14,10 +15,21 @@ namespace TShockAPI.Hooks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PlayerCommandEventArgs : HandledEventArgs
|
||||||
|
{
|
||||||
|
public TSPlayer Player { get; set; }
|
||||||
|
public string CommandName { get; set; }
|
||||||
|
public string CommandText { get; set; }
|
||||||
|
public List<string> Parameters { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public static class PlayerHooks
|
public static class PlayerHooks
|
||||||
{
|
{
|
||||||
public delegate void PlayerLoginD(PlayerLoginEventArgs e);
|
public delegate void PlayerLoginD(PlayerLoginEventArgs e);
|
||||||
public static event PlayerLoginD PlayerLogin;
|
public static event PlayerLoginD PlayerLogin;
|
||||||
|
public delegate void PlayerCommandD(PlayerCommandEventArgs e);
|
||||||
|
public static event PlayerCommandD PlayerCommand;
|
||||||
|
|
||||||
public static void OnPlayerLogin(TSPlayer ply)
|
public static void OnPlayerLogin(TSPlayer ply)
|
||||||
{
|
{
|
||||||
if(PlayerLogin == null)
|
if(PlayerLogin == null)
|
||||||
|
|
@ -28,5 +40,23 @@ namespace TShockAPI.Hooks
|
||||||
PlayerLoginEventArgs args = new PlayerLoginEventArgs(ply);
|
PlayerLoginEventArgs args = new PlayerLoginEventArgs(ply);
|
||||||
PlayerLogin(args);
|
PlayerLogin(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args)
|
||||||
|
{
|
||||||
|
if (PlayerCommand == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
|
||||||
|
{
|
||||||
|
Player = player,
|
||||||
|
CommandName = cmdName,
|
||||||
|
CommandText = cmdText,
|
||||||
|
Parameters = args
|
||||||
|
|
||||||
|
};
|
||||||
|
PlayerCommand(playerCommandEventArgs);
|
||||||
|
return playerCommandEventArgs.Handled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue