Skip to content

Commit

Permalink
Rethink MessageFrom/GetPlayerDataMessageInfo in EntityPropertyCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jun 29, 2021
1 parent 3550a68 commit 329bee6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/CPE/CmdSkin.cs
Expand Up @@ -58,7 +58,7 @@ public class CmdSkin : EntityPropertyCmd {
if (p == who) {
p.Message("Changed your own skin to &c" + skin);
} else {
MessageFrom(target, who, "had their skin changed to &c" + skin);
MessageAction(p, target, who, "λACTOR &Schanged λTARGET skin to &c" + skin);
}

if (who != null) who.SkinName = skin;
Expand Down
13 changes: 5 additions & 8 deletions MCGalaxy/Commands/Chat/CmdColor.cs
Expand Up @@ -49,23 +49,20 @@ public class CmdColor : EntityPropertyCmd {

protected override void SetPlayerData(Player p, string target, string colName) {
string col = "";
Player who; string editee; bool globalMessage;
GetPlayerDataMessageInfo(p, target, out who, out editee, out globalMessage);
Player who = PlayerInfo.FindExact(target);

string message;
if (colName.Length == 0) {
col = Group.GroupIn(target).Color;
message = p.ColoredName+" &Sremoved "+editee+" color";

PlayerDB.Update(target, PlayerData.ColumnColor, "");
MessageAction(p, target, who, "λACTOR &Sremoved λTARGET color");
} else {
col = Matcher.FindColor(p, colName);
if (col == null) return;
message = p.ColoredName+" &Schanged "+editee+" color to " + col + Colors.Name(col);

PlayerDB.Update(target, PlayerData.ColumnColor, col);
MessageAction(p, target, who, "λACTOR &Schanged λTARGET color to " + col + Colors.Name(col));
}
if (globalMessage) { Chat.MessageAll(message); }
else { Chat.MessageFrom(p, message); }

if (who != null) who.UpdateColor(col);
}

Expand Down
10 changes: 3 additions & 7 deletions MCGalaxy/Commands/Chat/CmdNick.cs
Expand Up @@ -58,20 +58,16 @@ public class CmdNick : EntityPropertyCmd {

protected override void SetPlayerData(Player p, string target, string nick) {
if (Colors.Strip(nick).Length >= 30) { p.Message("Nick must be under 30 letters."); return; }
Player who; string editee; bool globalMessage;
GetPlayerDataMessageInfo(p, target, out who, out editee, out globalMessage);
Player who = PlayerInfo.FindExact(target);

string message;
if (nick.Length == 0) {
message = p.ColoredName+" &Sremoved "+editee+" nick";
MessageAction(p, target, who, "λACTOR &Sremoved λTARGET nick");
nick = target.RemoveLastPlus();
} else {
// TODO: select color from database?
string color = who != null ? who.color : Group.GroupIn(target).Color;
message = p.ColoredName+" &Schanged "+editee+" nick to " + color + nick;
MessageAction(p, target, who, "λACTOR &Schanged λTARGET nick to " + color + nick);
}
if (globalMessage) { Chat.MessageAll(message); }
else { Chat.MessageFrom(p, message); }

if (who != null) who.DisplayName = nick;
if (who != null) TabList.Update(who, true);
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Commands/Chat/CmdTColor.cs
Expand Up @@ -37,11 +37,11 @@ public class CmdTColor : EntityPropertyCmd {
Player who = PlayerInfo.FindExact(target);

if (colName.Length == 0) {
MessageFrom(target, who, "had their title color removed");
MessageAction(p, target, who, "λACTOR &Sremoved λTARGET title color");
} else {
col = Matcher.FindColor(p, colName);
if (col == null) return;
MessageFrom(target, who, "had their title color changed to " + col + Colors.Name(col));
MessageAction(p, target, who, "λACTOR &Schanged λTARGET title color" + col + Colors.Name(col));
}

if (who != null) who.titlecolor = col;
Expand Down
12 changes: 4 additions & 8 deletions MCGalaxy/Commands/Chat/CmdTitle.cs
Expand Up @@ -35,18 +35,14 @@ public class CmdTitle : EntityPropertyCmd {
}

protected override void SetPlayerData(Player p, string target, string title) {
if (title.Length >= 20) { p.Message("Title must be under 20 letters."); return; }
Player who; string editee; bool globalMessage;
GetPlayerDataMessageInfo(p, target, out who, out editee, out globalMessage);
if (title.Length >= 20) { p.Message("Title must be under 20 letters."); return; }
Player who = PlayerInfo.FindExact(target);

string message;
if (title.Length == 0) {
message = p.ColoredName+" &Sremoved "+editee+" title";
MessageAction(p, target, who, "λACTOR &Sremoved λTARGET title");
} else {
message = p.ColoredName+" &Schanged "+editee+" title to &b[" + title + "&b]";
MessageAction(p, target, who, "λACTOR &Schanged λTARGET title to &b[" + title + "&b]");
}
if (globalMessage) { Chat.MessageAll(message); }
else { Chat.MessageFrom(p, message); }

if (who != null) who.title = title;
if (who != null) who.SetPrefix();
Expand Down
38 changes: 20 additions & 18 deletions MCGalaxy/Commands/EntityPropertyCmd.cs
Expand Up @@ -34,7 +34,7 @@ public abstract class EntityPropertyCmd : Command2 {
UsePlayer(p, data, message, type);
}
}
void UseBot(Player p, CommandData data, string message, string type) {
string[] args = message.SplitSpaces(3);
PlayerBot bot = Matcher.FindBots(p, args[1]);
Expand Down Expand Up @@ -80,24 +80,26 @@ public abstract class EntityPropertyCmd : Command2 {
protected virtual void SetOnlineData(Player p, Player who, string args) { }
protected virtual void SetPlayerData(Player p, string target, string args) { }

protected void MessageFrom(string target, Player who, string message) {
if (who == null) {
string nick = Player.Console.FormatNick(target);
Chat.MessageGlobal(nick + " &S" + message);
} else {
Chat.MessageFrom(who, "λNICK &S" + message);
}
}

protected void GetPlayerDataMessageInfo(Player p, string target, out Player who, out string editee, out bool globalMessage) {
who = PlayerInfo.FindExact(target);
editee = "&S's";
if (who != null) {
editee = (who.name == p.name) ? "their" : who.ColoredName+editee;
globalMessage = p.IsSuper || (!p.level.SeesServerWideChat && who.level != p.level);
/// <remarks> λACTOR is replaced with nick of player performing the action </remarks>
/// <remarks> λTARGET is replaced with either "their" or "[target nick]'s", depending
/// on whether the actor is the same player as the target or not </remarks>
protected void MessageAction(Player actor, string target, Player who, string message) {
// TODO: this needs to be compoletely rethought
bool global = who == null || actor.IsSuper
|| (!actor.level.SeesServerWideChat && actor.level != who.level);

if (actor == who) {
message = message.Replace("λACTOR", "λNICK")
.Replace("λTARGET", "their");
Chat.MessageFrom(who, message);
} else if (!global) {
message = message.Replace("λACTOR", actor.ColoredName)
.Replace("λTARGET", "λNICK&S's");
Chat.MessageFrom(who, message);
} else {
editee = Player.Console.FormatNick(target)+editee;
globalMessage = false;
message = message.Replace("λACTOR", actor.ColoredName)
.Replace("λTARGET", Player.Console.FormatNick(target) + "&S's");
Chat.MessageAll(message);
}
}
}
Expand Down

0 comments on commit 329bee6

Please sign in to comment.