From fff6e1bcbcc16ebb7aef393c78fc49bffb85ec58 Mon Sep 17 00:00:00 2001 From: high Date: Tue, 14 Jun 2011 17:06:17 -0400 Subject: [PATCH] Changed Group. This isn't java. Don't use accessor/mutator methods. Use properties. --- TShockAPI/Group.cs | 147 ++++++++++++++++++++------------------------ TShockAPI/TShock.cs | 2 +- TShockAPI/Tools.cs | 6 +- 3 files changed, 69 insertions(+), 86 deletions(-) diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index db0d69c7..d0525120 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -14,86 +14,69 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ -using System; -using System.Collections.Generic; - -namespace TShockAPI -{ - public class Group - { - private string name; - private Group parent; - private List permissions = new List(); - private List negatedPermissions = new List(); - - public Group(string groupName, Group parentGroup = null) - { - name = groupName; - parent = parentGroup; - } - - public Group() - { - throw new Exception("Called Group constructor with no parameters"); - } - - public string GetName() - { - return name; - } - - public Group GetParent() - { - return parent; - } - - public virtual bool HasPermission(string permission) - { - if (permission.Equals("")) - { - return true; - } - if (negatedPermissions.Contains(permission)) - { - return false; - } - else if (permissions.Contains(permission)) - { - return true; - } - else if (parent != null) - { - //inception - return parent.HasPermission(permission); - } - return false; - } - - public void NegatePermission(string permission) - { - negatedPermissions.Add(permission); - } - - public void AddPermission(string permission) - { - permissions.Add(permission); - } - } - - public class SuperAdminGroup : Group - { - public SuperAdminGroup(string groupName, Group parentGroup = null) : base(groupName, parentGroup) - { - } - - public SuperAdminGroup() - { - } - - public override bool HasPermission(string permission) - { - return true; - } - } +*/ +using System; +using System.Collections.Generic; + +namespace TShockAPI +{ + public class Group + { + private readonly List permissions = new List(); + private readonly List negatedpermissions = new List(); + + public string Name { get; protected set; } + public Group Parent { get; protected set; } + + public Group(string groupname, Group parentgroup = null) + { + Name = groupname; + Parent = parentgroup; + } + + public virtual bool HasPermission(string permission) + { + if (permission.Equals("")) + { + return true; + } + if (negatedpermissions.Contains(permission)) + { + return false; + } + if (permissions.Contains(permission)) + { + return true; + } + if (Parent != null) + { + //inception + return Parent.HasPermission(permission); + } + return false; + } + + public void NegatePermission(string permission) + { + negatedpermissions.Add(permission); + } + + public void AddPermission(string permission) + { + permissions.Add(permission); + } + } + + public class SuperAdminGroup : Group + { + public SuperAdminGroup(string groupName, Group parentGroup = null) + : base(groupName, parentGroup) + { + } + + public override bool HasPermission(string permission) + { + return true; + } + } } \ No newline at end of file diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 3cb8d9d7..41188204 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -570,7 +570,7 @@ namespace TShockAPI if (Main.netMode != 2) return; - Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.GetName())); + Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.Name)); Tools.ShowMOTD(who); if (HackedHealth(who)) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 235f801a..6264fa50 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -415,7 +415,7 @@ namespace TShockAPI { for (int j = 0; j < groups.Count; j++) { - if (groups[j].GetName().Equals(parent)) + if (groups[j].Name.Equals(parent)) { group = new Group(name, groups[j]); break; @@ -455,7 +455,7 @@ namespace TShockAPI //first attempt on cached groups for (int i = 0; i < groups.Count; i++) { - if (groups[i].GetName().Equals(groupName)) + if (groups[i].Name.Equals(groupName)) { return groups[i]; } @@ -465,7 +465,7 @@ namespace TShockAPI for (int i = 0; i < groups.Count; i++) { - if (groups[i].GetName().Equals(groupName)) + if (groups[i].Name.Equals(groupName)) { return groups[i]; }