Use CanExecute instead of commands.Contains for future extensibility

This commit is contained in:
UnknownShadow200 2017-05-28 19:41:02 +10:00
parent 2c024c32a8
commit 0b5222f325
4 changed files with 8 additions and 9 deletions

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Core {
internal static void HandleConnect(Player p) { internal static void HandleConnect(Player p) {
CheckReviewList(p); CheckReviewList(p);
if (p.group.commands.Contains("reachdistance")) if (p.group.CanExecute("reachdistance"))
LoadReach(p); LoadReach(p);
LoadWaypoints(p); LoadWaypoints(p);

View File

@ -107,14 +107,14 @@ namespace MCGalaxy {
for (int i = 0; i < CanModify.Length; i++) for (int i = 0; i < CanModify.Length; i++)
CanModify[i] = BlockPerms.CanModify(Permission, (byte)i); CanModify[i] = BlockPerms.CanModify(Permission, (byte)i);
} }
/// <summary> Returns true if players in this group can use the given command. </summary>
public bool CanExecute(string cmdName) { public bool CanExecute(string cmdName) {
return commands.Contains(Command.all.Find(cmdName)); Command cmd = Command.all.Find(cmdName);
return cmd != null && commands.Contains(cmd);
} }
/// <summary> Check to see if this group can excute cmd </summary> /// <summary> Returns true if players in this group can use the given command. </summary>
/// <param name="cmd">The command object to check</param>
/// <returns>True if this group can use it, false if they cant</returns>
public bool CanExecute(Command cmd) { return commands.Contains(cmd); } public bool CanExecute(Command cmd) { return commands.Contains(cmd); }
public static List<Group> GroupList = new List<Group>(); public static List<Group> GroupList = new List<Group>();

View File

@ -168,7 +168,7 @@ namespace MCGalaxy {
} }
try { try {
if (group.commands.Contains("inbox") && Database.TableExists("Inbox" + name) ) { if (group.CanExecute("inbox") && Database.TableExists("Inbox" + name) ) {
using (DataTable table = Database.Backend.GetRows("Inbox" + name, "*")) { using (DataTable table = Database.Backend.GetRows("Inbox" + name, "*")) {
if (table.Rows.Count > 0) if (table.Rows.Count > 0)
SendMessage("You have &a" + table.Rows.Count + " %Smessages in /inbox"); SendMessage("You have &a" + table.Rows.Count + " %Smessages in /inbox");

View File

@ -18,13 +18,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net;
using System.Threading; using System.Threading;
using MCGalaxy.Commands.World; using MCGalaxy.Commands.World;
using MCGalaxy.Games; using MCGalaxy.Games;
using MCGalaxy.Generator; using MCGalaxy.Generator;
using MCGalaxy.Tasks;
using MCGalaxy.Network; using MCGalaxy.Network;
using MCGalaxy.Tasks;
namespace MCGalaxy { namespace MCGalaxy {