Error check and autocomplete player names provided to /map realmowner

This commit is contained in:
Goodlyay 2025-08-20 23:51:48 -07:00
parent 69ef58fd9c
commit 852ccb0e65
2 changed files with 23 additions and 4 deletions

View File

@ -102,9 +102,23 @@ namespace MCGalaxy {
}
static void SetOwner(Player p, Level lvl, string value) {
lvl.Config.RealmOwner = value.Replace(", ", ",").Replace(" ", ",");
if (value.Length == 0) p.Message("Removed realm owner for this level.");
else p.Message("Set realm owner/owners of this level to {0}.", value);
if (value.Length == 0) {
lvl.Config.RealmOwner = "";
p.Message("Removed realm owner for this level.");
return;
}
value = value.Replace(", ", ",");
value = value.Replace(",", " ");
string[] names = value.SplitSpaces();
for (int i = 0; i < names.Length; i++) {
names[i] = PlayerInfo.FindMatchesPreferOnline(p, names[i]);
if (names[i] == null) return;
}
lvl.Config.RealmOwner = names.Join(","); ;
p.Message("Set realm owner/owners of this level to {0}.", names.Join((n) => p.FormatNick(n)));
}
static void SetTree(Player p, Level lvl, string value) {

View File

@ -71,7 +71,12 @@ namespace MCGalaxy
return Matcher.Find(pl, name, out matches, Online.Items,
p => pl.CanSee(p), p => p.name, p => p.color + p.name, "online players");
}
/// <summary>
/// Matches given name against the names of all online players that the given player can see.
/// If no online player is matched, attempts to find an offline player name match.
/// </summary>
/// <returns>A player name if exactly one found. Otherwise, null.</returns>
public static string FindMatchesPreferOnline(Player p, string name) {
if (!Formatter.ValidPlayerName(p, name)) return null;
int matches;