mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Allow partial matching of rank names in some commands.
This commit is contained in:
parent
532a9964a9
commit
6bfa243d12
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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":
|
||||
|
@ -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 + ")";
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user