Allow partial matching of rank names in some commands.

This commit is contained in:
UnknownShadow200 2016-05-30 22:13:35 +10:00
parent 532a9964a9
commit 6bfa243d12
12 changed files with 43 additions and 43 deletions

View File

@ -35,8 +35,8 @@ namespace MCGalaxy.Commands {
string[] args = message.Split(trimChars, 2);
string rank = args.Length == 1 ? p.group.name : args[0];
string text = args[args.Length - 1];
Group grp = Group.Find(rank);
if (grp == null) { Player.Message(p, "Could not find rank specified."); return; }
Group grp = Group.FindOrShowMatches(p, rank);
if (grp == null) return;
Player[] players = PlayerInfo.Online.Items;
string toSend = p.color + p.name + ": %S" + text.Trim();

View File

@ -57,8 +57,8 @@ namespace MCGalaxy.Commands {
}
} else if (message.CaselessStarts("set ")) {
string[] args = message.Split(trimChars, 3);
Group grp = Group.Find(args[1]);
if (grp == null) { Player.Message(p, "Could not find group"); return; }
Group grp = Group.FindOrShowMatches(p, args[1]);
if (grp == null) return;
string path = "text/rankreqs/" + grp.name + ".txt";
if (args.Length == 2) {
@ -71,8 +71,8 @@ namespace MCGalaxy.Commands {
Player.Message(p, "Updated rank requirements for " + grp.ColoredName + "%S.");
}
} else {
Group grp = Group.Find(message);
if (grp == null) { Player.Message(p, "Could not find group"); return; }
Group grp = Group.FindOrShowMatches(p, message);
if (grp == null) return;
ShowRequirements(p, grp);
}
}

View File

@ -32,8 +32,8 @@ namespace MCGalaxy.Commands {
if (cmd == null) { Player.Message(p, "Could not find command entered"); return; }
if (p != null && !p.group.CanExecute(cmd)) { Player.Message(p, "Your rank cannot use this command."); return; }
Group grp = Group.Find(args[1]);
if (grp == null) { Player.Message(p, "Could not find rank specified"); return; }
Group grp = Group.FindOrShowMatches(p, args[1]);
if (grp == null) return;
if (p != null && grp.Permission > p.group.Permission) {
Player.Message(p, "Cannot set permissions to a rank higher than yours."); return;
}

View File

@ -69,8 +69,8 @@ namespace MCGalaxy.Commands {
}
if (args.Length == 2) { Player.Message(p, "You need to provide a rank name for this type."); return; }
Group grp = Group.Find(args[2]);
if (grp == null) { Player.Message(p, "No rank found matching: " + args[2]); return; }
Group grp = Group.FindOrShowMatches(p, args[2]);
if (grp == null) return;
switch (args[0].ToLower()) {
case "dl":

View File

@ -31,10 +31,10 @@ namespace MCGalaxy.Commands.Moderation {
string[] args = message.Split(trimChars, 3);
if (args.Length < 2) { Help(p); return; }
Player who = PlayerInfo.Find(args[0]);
Group newRank = Group.Find(args[1]);
Group newRank = Group.FindOrShowMatches(p, args[1]);
string reason = args.Length > 2 ? args[2] : "Congratulations!";
if (newRank == null) { Player.Message(p, "Could not find specified rank."); return; }
if (newRank == null) return;
string rankMsg;
string rankReason = "%S. (" + reason + ")";

View File

@ -59,8 +59,8 @@ namespace MCGalaxy.Commands.Moderation {
player = who.name;
}
Group group = Group.Find(rank);
if (group == null) { Player.Message(p, "&cRank &a" + rank + "&c does not exist."); return; }
Group group = Group.FindOrShowMatches(p, rank);
if (group == null) return;
int periodTime;
if (!Int32.TryParse(period, out periodTime)) {
Player.Message(p, "&cThe period needs to be a number."); return;

View File

@ -29,12 +29,8 @@ namespace MCGalaxy.Commands
string[] args = message.Split(' ');
if (message == "" || args.Length < 2) { Help(p); return; }
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
Group grp = Group.Find(args[1]);
if (who == null) return;
if (grp == null) {
Player.Message(p, "No rank found with the name \"" + args[1] + "\"." ); return;
}
Group grp = Group.FindOrShowMatches(p, args[1]);
if (who == null || grp == null) return;
if (grp.Permission == LevelPermission.Banned) {
string banner = p == null ? "console" : p.ColoredName;

View File

@ -34,8 +34,8 @@ namespace MCGalaxy.Drawing.Ops {
public override bool CanDraw(Vec3S32[] marks, Player p, out long affected) {
affected = GetBlocksAffected(p.level, marks);
if (affected > p.group.maxBlocks) {
Player.Message(p, "You tried to fill over " + p.group.maxBlocks + " blocks.");
Player.Message(p, "You cannot fill more than " + p.group.maxBlocks + ".");
Player.Message(p, "You rank can only fill up to {0} blocks. " +
"This fill would affect more than {0} blocks.", p.group.maxBlocks);
return false;
}
return true;

View File

@ -42,8 +42,7 @@ namespace MCGalaxy {
}
public static Level FindOrShowMatches(Player pl, string name) {
int matches = 0;
return FindOrShowMatches(pl, name, out matches);
int matches = 0; return FindOrShowMatches(pl, name, out matches);
}
public static Level FindOrShowMatches(Player pl, string name, out int matches) {

View File

@ -152,38 +152,44 @@ namespace MCGalaxy
OnGroupSaveEvent.Call();
}
/// <summary> Check to see if group /name/ exists </summary>
/// <param name="name">The name of the group to search for</param>
/// <returns>Return true if it does exists, returns false if it doesnt</returns>
/// <summary> Check whether a group with that name exists. </summary>
public static bool Exists(string name) {
name = name.ToLower();
return GroupList.Any(gr => gr.name == name);
}
/// <summary> Find the group with the name /name/ </summary>
/// <param name="name">The name of the group</param>
/// <returns>The group object with that name</returns>
/// <summary> Find the group which has the given name. </summary>
public static Group Find(string name) {
name = name.ToLower();
if (name == "adv") name = "advbuilder";
MapName(ref name);
return GroupList.Find(gr => gr.name == name);
}
/// <summary> Find the group(s) which contain the given name. </summary>
public static Group FindOrShowMatches(Player p, string name, out int matches) {
name = name.ToLower();
MapName(ref name);
return Extensions.FindOrShowMatches(p, name, out matches, GroupList, g => true, g => g.name, "ranks");
}
/// <summary> Find the group(s) which contain the given name. </summary>
public static Group FindOrShowMatches(Player p, string name) {
int matches = 0; return FindOrShowMatches(p, name, out matches);
}
static void MapName(ref string name) {
if (name == "adv") name = "advbuilder";
if (name == "op") name = "operator";
if (name == "super" || (name == "admin" && !Group.Exists("admin"))) name = "superop";
if (name == "noone") name = "nobody";
return GroupList.Find(gr => gr.name == name.ToLower());
}
/// <summary> Find the group with the permission /Perm/ </summary>
/// <param name="Perm">The level permission to search for</param>
/// <returns>The group object with that level permission</returns>
/// <summary> Finds the group with has the given permission level. </summary>
public static Group findPerm(LevelPermission Perm) {
return GroupList.Find(grp => grp.Permission == Perm);
}
/// <summary> Find the group with the permission /Perm/ </summary>
/// <param name="Perm">The level permission to search for</param>
/// <returns>The group object with that level permission</returns>
/// <summary> Find the group which has the given permission level. </summary>
public static Group findPermInt(int Perm) {
return GroupList.Find(grp => (int)grp.Permission == Perm);
}

View File

@ -49,8 +49,7 @@ namespace MCGalaxy {
}
public static Player FindOrShowMatches(Player pl, string name, bool onlyCanSee = true) {
int matches = 0;
return FindOrShowMatches(pl, name, out matches, onlyCanSee);
int matches = 0; return FindOrShowMatches(pl, name, out matches, onlyCanSee);
}
public static Player FindOrShowMatches(Player pl, string name, out int matches, bool onlyCanSee = true) {

View File

@ -152,7 +152,7 @@ namespace MCGalaxy {
}
}
public static T FindOrShowMatches<T>(Player pl, string name, out int matches, T[] items,
public static T FindOrShowMatches<T>(Player pl, string name, out int matches, IEnumerable<T> items,
Predicate<T> filter, Func<T, string> nameGetter, string type) {
T match = default(T); matches = 0;
name = name.ToLower();