From d943367765f075bafa4f4588dee0260e262249ca Mon Sep 17 00:00:00 2001 From: Scavenger3 Date: Wed, 3 Oct 2012 23:27:59 +1000 Subject: [PATCH] Commands can have more than one permission. --- TShockAPI/Commands.cs | 23 ++++++++++++++++++----- TShockAPI/Permissions.cs | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index fbf800ae..9dd5f051 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -66,20 +66,26 @@ namespace TShockAPI public List Names { get; protected set; } public bool AllowServer { get; set; } public bool DoLog { get; set; } - public string Permission { get; protected set; } + public List Permissions { get; protected set; } private CommandDelegate command; + public Command(List permissionsneeded, CommandDelegate cmd, params string[] names) + : this(cmd, names) + { + Permissions = permissionsneeded; + } + public Command(string permissionneeded, CommandDelegate cmd, params string[] names) : this(cmd, names) { - Permission = permissionneeded; + Permissions = new List { permissionneeded }; } public Command(CommandDelegate cmd, params string[] names) { if (names == null || names.Length < 1) throw new NotSupportedException(); - Permission = null; + Permissions = null; Names = new List(names); command = cmd; AllowServer = true; @@ -88,7 +94,7 @@ namespace TShockAPI public bool Run(string msg, TSPlayer ply, List parms) { - if (!ply.Group.HasPermission(Permission)) + if (!CanRun(ply)) return false; try @@ -111,7 +117,14 @@ namespace TShockAPI public bool CanRun(TSPlayer ply) { - return ply.Group.HasPermission(Permission); + if (Permissions == null) + return true; + foreach (var Permission in Permissions) + { + if (ply.Group.HasPermission(Permission)) + return true; + } + return false; } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index f80ed598..08251a66 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -189,7 +189,7 @@ namespace TShockAPI { if (Commands.ChatCommands.Count < 1) Commands.InitCommands(); - return Commands.ChatCommands.Where(c => c.Permission == perm).ToList(); + return Commands.ChatCommands.Where(c => c.Permissions.Contains(perm)).ToList(); } ///