public void ParseCommands() { //potential shit idea and thread deadlocks. If this proves a problem and the mutex ends up indefinite //will need to revisit this lock (TShockAPI.Commands.ChatCommands) { TShockAPI.Commands.ChatCommands.RemoveAll(i => i.Names.Count(x => x.StartsWith("cmdalias.")) > 0); foreach (AliasCommand aliasCmd in Configuration.CommandAliases) { //The command delegate points to the same function for all aliases, which will generically handle all of them. TShockAPI.Command newCommand = new TShockAPI.Command(aliasCmd.Permissions, ChatCommand_AliasExecuted, new string[] { aliasCmd.CommandAlias, "cmdalias." + aliasCmd.CommandAlias }) { AllowServer = true }; TShockAPI.Commands.ChatCommands.Add(newCommand); } } lock (JScript.JScriptEngine.jsAliases) { foreach (JScript.JScriptAliasCommand jCmd in JScript.JScriptEngine.jsAliases) { TShockAPI.Command newCommand = new TShockAPI.Command(jCmd.Permissions, ChatCommand_AliasExecuted, new string[] { jCmd.CommandAlias, "cmdalias." + jCmd.CommandAlias }) { AllowServer = true }; TShockAPI.Commands.ChatCommands.Add(newCommand); } } }
/// <summary> /// Invokes a command ignoring permissions /// </summary> public static bool RunWithoutPermissions(this TShockAPI.Command cmd, string msg, TShockAPI.TSPlayer ply, List <string> parms) { try { TShockAPI.CommandDelegate cmdDelegateRef = SEconomyPlugin.GetPrivateField <TShockAPI.CommandDelegate>(cmd.GetType(), cmd, "command"); cmdDelegateRef(new TShockAPI.CommandArgs(msg, ply, parms)); } catch (Exception e) { ply.SendErrorMessage("Command failed, check logs for more details."); TShockAPI.Log.Error(e.ToString()); } return(true); }