Changed Group. This isn't java. Don't use accessor/mutator methods. Use properties.

This commit is contained in:
high 2011-06-14 17:06:17 -04:00
parent c3bf304c0c
commit fff6e1bcbc
3 changed files with 69 additions and 86 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
namespace TShockAPI
{
public class Group
{
private string name;
private Group parent;
private List<string> permissions = new List<string>();
private List<string> negatedPermissions = new List<string>();
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<string> permissions = new List<string>();
private readonly List<string> negatedpermissions = new List<string>();
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;
}
}
}

View file

@ -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))

View file

@ -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];
}