mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Use generic PlayerInfo.FindMatchesPreferOnline (searches through online players for a match, then searches through the PlayerDB), also add PlayerInfo.GetColoredName().
This commit is contained in:
parent
eee95f7a10
commit
4738e7d83f
@ -34,19 +34,14 @@ namespace MCGalaxy.Commands {
|
||||
if (message == "") { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (target == null) return;
|
||||
|
||||
Player target = PlayerInfo.Find(args[0]);
|
||||
string name = target != null ? target.name : args[0];
|
||||
|
||||
if (target == null && PlayerInfo.FindName(name) == null) {
|
||||
Player.Message(p, "There is no player with the given name."); return;
|
||||
}
|
||||
PlayerDB.SetLoginMessage(name, args[1]);
|
||||
|
||||
string fullName = target != null ? target.ColoredName : name;
|
||||
Player.Message(p, "The login message of " + fullName + " %Shas been changed to: " + args[1]);
|
||||
PlayerDB.SetLoginMessage(target, args[1]);
|
||||
Player.Message(p, "The login message of {0} %Shas been changed to: {1}",
|
||||
PlayerInfo.GetColoredName(p, target), args[1]);
|
||||
string changer = p == null ? "(console)" : p.name;
|
||||
Server.s.Log(changer + " changed " + name + "'s login message to: " + args[1]);
|
||||
Server.s.Log(changer + " changed " + target + "'s login message to: " + args[1]);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -34,17 +34,12 @@ namespace MCGalaxy.Commands {
|
||||
if (message == "") { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (target == null) return;
|
||||
|
||||
Player target = PlayerInfo.Find(args[0]);
|
||||
string name = target != null ? target.name : args[0];
|
||||
|
||||
if (target == null && PlayerInfo.FindName(name) == null) {
|
||||
Player.Message(p, "There is no player with the given name."); return;
|
||||
}
|
||||
PlayerDB.SetLogoutMessage(name, args[1]);
|
||||
|
||||
string fullName = target != null ? target.ColoredName : name;
|
||||
Player.Message(p, "The logout message of " + fullName + " %Shas been changed to: " + args[1]);
|
||||
PlayerDB.SetLogoutMessage(target, args[1]);
|
||||
Player.Message(p, "The logout message of {0} %Shas been changed to: {1}",
|
||||
PlayerInfo.GetColoredName(p, target), args[1]);
|
||||
string changer = p == null ? "(console)" : p.name;
|
||||
Server.s.Log(changer + " changed " + name + "'s logout message to:");
|
||||
}
|
||||
|
@ -32,10 +32,9 @@ namespace MCGalaxy.Commands {
|
||||
string[] parts = message.SplitSpaces(2);
|
||||
if (message == "" || parts.Length == 1) { Help(p); return; }
|
||||
|
||||
Player receiver = PlayerInfo.Find(parts[0]);
|
||||
string receiverName = receiver == null ? parts[0] : receiver.name;
|
||||
string receiverName = PlayerInfo.FindMatchesPreferOnline(p, message);
|
||||
if (receiverName == null) return;
|
||||
string senderName = p == null ? "(console)" : p.name;
|
||||
if (!ValidName(p, receiverName, "player")) return;
|
||||
|
||||
message = parts[1];
|
||||
//DB
|
||||
@ -50,8 +49,10 @@ namespace MCGalaxy.Commands {
|
||||
Database.Execute("INSERT INTO `Inbox" + receiverName + "` (PlayerFrom, TimeSent, Contents) VALUES (@0, @1, @2)",
|
||||
senderName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message);
|
||||
|
||||
Player receiver = PlayerInfo.FindExact(receiverName);
|
||||
Player.Message(p, "Message sent to &5" + receiverName + ".");
|
||||
if (receiver != null) receiver.SendMessage("Message recieved from &5" + senderName + "%S.");
|
||||
if (receiver != null)
|
||||
receiver.SendMessage("Message recieved from &5" + senderName + "%S.");
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -34,9 +34,8 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
string[] args = message.SplitSpaces(2);
|
||||
string plName = args[0];
|
||||
Player who = PlayerInfo.Find(plName);
|
||||
if (who != null) plName = who.name;
|
||||
string plName = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (plName == null) return;
|
||||
|
||||
string award = args.Length > 1 ? args[1] : "";
|
||||
award = Awards.Find(award);
|
||||
@ -48,13 +47,15 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
if (!take) {
|
||||
if (Awards.GiveAward(plName, award)) {
|
||||
Chat.MessageAll("{0}{1} %Swas awarded: &b{2}", Server.FindColor(plName), plName, award);
|
||||
Chat.MessageAll("{0} %Swas awarded: &b{1}",
|
||||
PlayerInfo.GetColoredName(p, plName), award);
|
||||
} else {
|
||||
Player.Message(p, "The player already has that award."); return;
|
||||
}
|
||||
} else {
|
||||
if (Awards.TakeAward(plName, award)) {
|
||||
Chat.MessageAll("{0}{1} %Shad their &b{2} %Saward removed", Server.FindColor(plName), plName, award);
|
||||
Chat.MessageAll("{0} %Shad their &b{1} %Saward removed",
|
||||
PlayerInfo.GetColoredName(p, plName), award);
|
||||
} else {
|
||||
Player.Message(p, "The player didn't have the award you tried to take"); return;
|
||||
}
|
||||
|
@ -35,16 +35,14 @@ namespace MCGalaxy.Commands {
|
||||
int page = 0;
|
||||
string plName = "";
|
||||
if (args.Length == 2) {
|
||||
plName = args[0];
|
||||
Player who = PlayerInfo.Find(plName);
|
||||
if (who != null) plName = who.name;
|
||||
plName = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (plName == null) return;
|
||||
|
||||
if (!int.TryParse(args[1], out page)) { Help(p); return; }
|
||||
} else if (message != "") {
|
||||
if (!int.TryParse(args[0], out page)) {
|
||||
plName = args[0];
|
||||
Player who = PlayerInfo.Find(plName);
|
||||
if (who != null) plName = who.name;
|
||||
plName = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (plName == null) return;
|
||||
}
|
||||
}
|
||||
if (page < 0) {
|
||||
@ -81,10 +79,12 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
static void OutputAwards(Player p, int page, int start,
|
||||
string plName, List<Awards.Award> awards) {
|
||||
if (plName != "")
|
||||
Player.Message(p, Server.FindColor(plName) + plName + " %Shas the following awards:");
|
||||
else
|
||||
if (plName != "") {
|
||||
Player.Message(p, "{0} %Shas the following awards:",
|
||||
PlayerInfo.GetColoredName(p, plName));
|
||||
} else {
|
||||
Player.Message(p, "Awards available: ");
|
||||
}
|
||||
|
||||
if (page == 0) {
|
||||
foreach (Awards.Award award in awards)
|
||||
|
@ -83,10 +83,9 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
static void Output(Player p, string user, byte block, bool deleted, TimeSpan delta) {
|
||||
string bName = Block.Name(block);
|
||||
user = Server.FindColor(user) + user;
|
||||
|
||||
Player.Message(p, "{0} ago {1} {2}", delta.Shorten(true, false), user,
|
||||
string bName = Block.Name(block);
|
||||
Player.Message(p, "{0} ago {1} {2}",
|
||||
delta.Shorten(true, false), PlayerInfo.GetColoredName(p, user),
|
||||
deleted ? "&4deleted%S (using " + bName + ")" : "&3placed%S " + bName);
|
||||
}
|
||||
|
||||
|
@ -107,8 +107,8 @@ namespace MCGalaxy.Commands {
|
||||
if (String.IsNullOrEmpty(data.RealmOwner))
|
||||
data.RealmOwner = GetRealmMapOwner(data.Name);
|
||||
if (String.IsNullOrEmpty(data.RealmOwner)) return;
|
||||
Player.Message(p, " This map is a personal realm of {0}{1}",
|
||||
Server.FindColor(data.RealmOwner), data.RealmOwner);
|
||||
Player.Message(p, " This map is a personal realm of {0}",
|
||||
PlayerInfo.GetColoredName(p, data.RealmOwner));
|
||||
}
|
||||
|
||||
static string GetRealmMapOwner(string lvlName) {
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (reason == null) return;
|
||||
string banReason = reason == "-" ? "" : " (" + reason + ")";
|
||||
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
string target = who == null ? args[0] : who.name;
|
||||
if (!ValidName(p, target, "player")) return;
|
||||
Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group;
|
||||
|
@ -63,7 +63,8 @@ namespace MCGalaxy.Commands {
|
||||
if (!done) UndoFormat.DoHighlight(p, name.ToLower(), start, ref found);
|
||||
|
||||
if (found) {
|
||||
Player.Message(p, "Now highlighting &b" + seconds + " %Sseconds for " + Server.FindColor(name) + name);
|
||||
Player.Message(p, "Now highlighting &b{0} %Sseconds for {1}",
|
||||
seconds, PlayerInfo.GetColoredName(p, name));
|
||||
Player.Message(p, "&cUse /reload to un-highlight");
|
||||
} else {
|
||||
Player.Message(p, "Could not find player specified.");
|
||||
|
@ -49,43 +49,42 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
}
|
||||
|
||||
static void Assign(Player p, string[] args) {
|
||||
string player = args[0];
|
||||
Player who = PlayerInfo.Find(player);
|
||||
if (who == null) {
|
||||
player = PlayerInfo.FindOfflineNameMatches(p, player);
|
||||
if (player == null) return;
|
||||
} else {
|
||||
player = who.name;
|
||||
}
|
||||
|
||||
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||
if (target == null) return;
|
||||
Player who = PlayerInfo.FindExact(target);
|
||||
|
||||
Group group = Group.FindMatches(p, args[1]);
|
||||
if (group == null) return;
|
||||
TimeSpan delta;
|
||||
if (!args[2].TryParseShort(p, 'h', "temp rank for", out delta)) return;
|
||||
|
||||
foreach (string line in Server.TempRanks.Find(player)) {
|
||||
foreach (string line in Server.TempRanks.Find(target)) {
|
||||
Player.Message(p, "&cThe player already has a temporary rank assigned!"); return;
|
||||
}
|
||||
|
||||
if (p != null && who != null && p == who) {
|
||||
Player.Message(p, "&cYou cannot assign yourself a temporary rank."); return;
|
||||
}
|
||||
Group pGroup = who != null ? who.group : Group.findPlayerGroup(player);
|
||||
Group pGroup = who != null ? who.group : Group.findPlayerGroup(target);
|
||||
if (p != null && pGroup.Permission >= p.Rank) {
|
||||
Player.Message(p, "Cannot change the temporary rank of someone equal or higher to yourself."); return;
|
||||
}
|
||||
if (p != null && group.Permission >= p.Rank) {
|
||||
Player.Message(p, "Cannot change the temporary rank to a higher rank than yourself."); return;
|
||||
}
|
||||
|
||||
AssignTempRank(p, who, delta, pGroup, group, target);
|
||||
}
|
||||
|
||||
static void AssignTempRank(Player p, Player who, TimeSpan delta,
|
||||
Group pGroup, Group group, string target) {
|
||||
DateTime now = DateTime.Now;
|
||||
string assigner = p == null ? "Console" : p.name;
|
||||
string data = player + " " + args[1] + " " + pGroup.name + " " + delta.Hours + " " + now.Minute + " " +
|
||||
string data = target + " " + group.name + " " + pGroup.name + " " + delta.Hours + " " + now.Minute + " " +
|
||||
now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner + " " + delta.Minutes;
|
||||
Server.TempRanks.Append(data);
|
||||
|
||||
Command.all.Find("setrank").Use(null, player + " " + group.name + " assigning temp rank");
|
||||
Player.Message(p, "Temp ranked {0} to {1}%S for {2}", player, group.ColoredName, delta.Shorten());
|
||||
Command.all.Find("setrank").Use(null, target + " " + group.name + " assigning temp rank");
|
||||
Player.Message(p, "Temp ranked {0} to {1}%S for {2}", target, group.ColoredName, delta.Shorten());
|
||||
if (who != null)
|
||||
Player.Message(who, "You have been temp ranked to {0}%S for {1}", group.ColoredName, delta.Shorten());
|
||||
}
|
||||
|
@ -32,29 +32,33 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
if (args[0] == "add") {
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
Player pl = PlayerInfo.Find(args[1]);
|
||||
if (pl != null) args[1] = pl.name;
|
||||
args[1] = PlayerInfo.FindMatchesPreferOnline(p, args[1]);
|
||||
if (args[1] == null) return;
|
||||
|
||||
if (Server.vip.Contains(args[1])) {
|
||||
Player.Message(p, Name(pl, args[1]) + " %Sis already a VIP.");
|
||||
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis already a VIP.");
|
||||
} else {
|
||||
Server.vip.Add(args[1]);
|
||||
Server.vip.Save(false);
|
||||
Player.Message(p, Name(pl, args[1]) + " %Sis now a VIP.");
|
||||
if (pl != null) Player.Message(pl, "You are now a VIP!");
|
||||
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis now a VIP.");
|
||||
|
||||
Player who = PlayerInfo.FindExact(args[1]);
|
||||
if (who != null) Player.Message(who, "You are now a VIP!");
|
||||
}
|
||||
} else if (args[0] == "remove") {
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
Player pl = PlayerInfo.Find(args[1]);
|
||||
if (pl != null) args[1] = pl.name;
|
||||
args[1] = PlayerInfo.FindMatchesPreferOnline(p, args[1]);
|
||||
if (args[1] == null) return;
|
||||
|
||||
if (Server.vip.Contains(args[1])) {
|
||||
Player.Message(p, Name(pl, args[1]) + " %Sis not a VIP.");
|
||||
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis not a VIP.");
|
||||
} else {
|
||||
Server.vip.Remove(args[1]);
|
||||
Server.vip.Save(false);
|
||||
Player.Message(p, Name(pl, args[1]) + " %Sis no longer a VIP.");
|
||||
if (pl != null) Player.Message(pl, "You are no longer a VIP!");
|
||||
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis no longer a VIP.");
|
||||
|
||||
Player who = PlayerInfo.FindExact(args[1]);
|
||||
if (who != null) Player.Message(who, "You are no longer a VIP!");
|
||||
}
|
||||
} else if (args[0] == "list") {
|
||||
List<string> list = Server.vip.All();
|
||||
@ -69,9 +73,7 @@ namespace MCGalaxy.Commands {
|
||||
Help(p);
|
||||
}
|
||||
}
|
||||
|
||||
static string Name(Player pl, string name) { return pl == null ? name : pl.ColoredName; }
|
||||
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/vip <add/remove> [player]");
|
||||
Player.Message(p, "%HAdds or removes [player] from the VIP list.");
|
||||
|
@ -135,8 +135,8 @@ namespace MCGalaxy.Commands.Building {
|
||||
DrawOp.DoDrawOp(op, null, p, new Vec3S32[] { Vec3U16.MaxVal, Vec3U16.MaxVal } );
|
||||
|
||||
if (op.found) {
|
||||
Chat.MessageAll("{0}{1}%S's actions for the past &b{2} %Sseconds were undone.",
|
||||
Server.FindColor(whoName), whoName, seconds);
|
||||
Chat.MessageAll("{0}%S's actions for the past &b{1} %Sseconds were undone.",
|
||||
PlayerInfo.GetColoredName(p, whoName), seconds);
|
||||
Server.s.Log(whoName + "'s actions for the past " + seconds + " seconds were undone.");
|
||||
if (p != null) p.level.Save(true);
|
||||
} else {
|
||||
|
@ -31,6 +31,13 @@ namespace MCGalaxy {
|
||||
|
||||
public static string GetColor(string name) { return GetGroup(name).color; }
|
||||
|
||||
public static string GetColoredName(Player p, string name) {
|
||||
Player target = FindExact(name);
|
||||
return target != null && Entities.CanSee(p, target) ?
|
||||
target.ColoredName : GetColor(name) + name; // TODO: select color from database?
|
||||
}
|
||||
|
||||
|
||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||
public static Player Find(string name) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
@ -62,6 +69,19 @@ namespace MCGalaxy {
|
||||
p => p.name, "online players");
|
||||
}
|
||||
|
||||
public static string FindMatchesPreferOnline(Player p, string name) {
|
||||
if (!Player.ValidName(name)) {
|
||||
Player.Message(p, "\"{0}\" is not a valid player name.", name); return null;
|
||||
}
|
||||
int matches = 0;
|
||||
Player target = FindMatches(p, name, out matches);
|
||||
|
||||
if (matches > 1) return null;
|
||||
if (target != null) return target.name;
|
||||
Player.Message(p, "Searching PlayerDB..");
|
||||
return FindOfflineNameMatches(p, name);
|
||||
}
|
||||
|
||||
/// <summary> Finds the online player whose name caselessly exactly matches the given name. </summary>
|
||||
/// <returns> Player instance if an exact match is found, null if not. </returns>
|
||||
public static Player FindExact(string name) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user