Skip to content

Commit

Permalink
Improve multiple messages of players/ranks/loaded levels to also incl…
Browse files Browse the repository at this point in the history
…ude colours of names
  • Loading branch information
UnknownShadow200 committed Nov 24, 2022
1 parent e04ca53 commit 73f7ba3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 236 deletions.
7 changes: 0 additions & 7 deletions MCGalaxy/Player/List/PlayerExtList.cs
Expand Up @@ -99,13 +99,6 @@ public class PlayerExtList {
return idx == -1 ? "" : line.Substring(idx + 1);
}
}


[Obsolete("Use Update instead")]
public void Add(string name, string data) { Update(name, data); }

[Obsolete("Use Update instead")]
public void AddOrReplace(string name, string data) { Update(name, data); }


public void Save() { Save(true); }
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Player/PlayerInfo.cs
Expand Up @@ -69,7 +69,7 @@ public static class PlayerInfo
if (exact != null && pl.CanSee(exact)) { matches = 1; return exact; }

return Matcher.Find(pl, name, out matches, Online.Items,
p => pl.CanSee(p), p => p.name, "online players");
p => pl.CanSee(p), p => p.name, p => p.color + p.name, "online players");
}

public static string FindMatchesPreferOnline(Player p, string name) {
Expand Down
21 changes: 15 additions & 6 deletions MCGalaxy/util/Formatting/Matcher.cs
Expand Up @@ -55,7 +55,7 @@ public static class Matcher {
public static Level FindLevels(Player p, string name) {
int matches;
return Find(p, name, out matches, LevelInfo.Loaded.Items,
null, l => l.name, "loaded levels");
null, l => l.name, l => l.ColoredName, "loaded levels");
}

/// <summary> Find partial matches of 'name' against the list of all map files. </summary>
Expand All @@ -71,7 +71,7 @@ public static class Matcher {
Group.MapName(ref name);
int matches;
return Find(p, name, out matches, Group.GroupList,
null, g => Colors.Strip(g.Name), "ranks");
null, g => Colors.Strip(g.Name), g => g.ColoredName, "ranks");
}

/// <summary> Find partial matches of 'name' against a list of warps. </summary>
Expand All @@ -94,8 +94,17 @@ public static class Matcher {
/// <returns> If exactly one match, the matching item. </returns>
public static T Find<T>(Player p, string name, out int matches, IEnumerable<T> items,
Predicate<T> filter, StringFormatter<T> nameGetter, string group, int limit = 5) {
return Find<T>(p, name, out matches, items, filter, nameGetter, nameGetter, group, limit);
}


/// <summary> Finds partial matches of 'name' against the names of the items in the 'items' enumerable. </summary>
/// <returns> If exactly one match, the matching item. </returns>
public static T Find<T>(Player p, string name, out int matches, IEnumerable<T> items,
Predicate<T> filter, StringFormatter<T> nameGetter,
StringFormatter<T> itemFormatter, string group, int limit = 5) {
T match = default(T); matches = 0;
StringBuilder nameMatches = new StringBuilder();
StringBuilder output = new StringBuilder();
const StringComparison comp = StringComparison.OrdinalIgnoreCase;

foreach (T item in items)
Expand All @@ -107,9 +116,9 @@ public static class Matcher {

match = item; matches++;
if (matches <= limit) {
nameMatches.Append(itemName).Append(", ");
output.Append(itemFormatter(item)).Append("&S, ");
} else if (matches == limit + 1) {
nameMatches.Append("(and more)").Append(", ");
output.Append("(and more), ");
}
}

Expand All @@ -119,7 +128,7 @@ public static class Matcher {
}

string count = matches > limit ? limit + "+ " : matches + " ";
string names = nameMatches.ToString(0, nameMatches.Length - 2);
string names = output.ToString(0, output.Length - 2);

p.Message("{0}{1} match \"{2}\":", count, group, name);
p.Message(names);
Expand Down
222 changes: 0 additions & 222 deletions tatic bool CanEditAny(Player p) {

This file was deleted.

0 comments on commit 73f7ba3

Please sign in to comment.