You can partially match award names in /award now.

This commit is contained in:
UnknownShadow200 2016-09-02 08:44:32 +10:00
parent 9d390d88d9
commit 885872b017
2 changed files with 14 additions and 13 deletions

View File

@ -38,12 +38,9 @@ namespace MCGalaxy.Commands {
if (plName == null) return;
string award = args.Length > 1 ? args[1] : "";
award = Awards.Find(award);
if (award == null) {
Player.Message(p, "The award you entered doesn't exist");
Player.Message(p, "Use /awards for a list of awards");
return;
}
int matches = 0;
award = Awards.FindMatches(p, award, out matches);
if (award == null) { Player.Message(p, "Use /awards for a list of awards"); return; }
if (!take) {
if (Awards.GiveAward(plName, award)) {

View File

@ -59,10 +59,7 @@ namespace MCGalaxy {
static void AwardsListLineProcessor(string key, string value) {
if (value == "") return;
Award award = new Award();
award.Name = key;
award.Description = value;
AwardsList.Add(award);
Add(key, value);
}
static void PlayerAwardsLineProcessor(string key, string value) {
@ -110,6 +107,7 @@ namespace MCGalaxy {
pl.Awards.Add(name);
return true;
}
PlayerAward newPl;
newPl.Name = playerName;
newPl.Awards = new List<string>();
@ -160,8 +158,8 @@ namespace MCGalaxy {
if (Exists(name)) return false;
Award award = new Award();
award.Name = name;
award.Description = desc;
award.Name = name.Trim();
award.Description = desc.Trim();
AwardsList.Add(award);
return true;
}
@ -184,12 +182,18 @@ namespace MCGalaxy {
}
/// <summary> Whether an award with that name exists. </summary>
public static string Find(string name) {
public static string FindExact(string name) {
foreach (Award award in AwardsList)
if (award.Name.CaselessEq(name)) return award.Name;
return null;
}
public static string FindMatches(Player p, string name, out int matches) {
Award award = Utils.FindMatches<Award>(p, name, out matches, AwardsList,
a => true, a => a.Name, "awards");
return award == null ? null : award.Name;
}
/// <summary> Gets the description of the award matching the given name,
/// or an empty string if no matching award was found. </summary>
public static string GetDescription(string name) {