Skip to content

Commit

Permalink
Also make /title and /tcolor work on offline players
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 16, 2020
1 parent 118ff39 commit da8305f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
18 changes: 9 additions & 9 deletions MCGalaxy/Commands/Chat/CmdTColor.cs
Expand Up @@ -29,24 +29,24 @@ public class CmdTColor : EntityPropertyCmd {
get { return new[] { new CommandAlias("TColour"), new CommandAlias("XTColor", "-own") }; }
}
public override void Use(Player p, string message, CommandData data) {
UseOnline(p, data, message, "title color");
UsePlayer(p, data, message, "title color");
}

protected override void SetOnlineData(Player p, Player target, string colName) {
protected override void SetPlayerData(Player p, string target, string colName) {
string col = "";
Player who = PlayerInfo.FindExact(target);

if (colName.Length == 0) {
Chat.MessageFrom(target, "λNICK %Shad their title color removed");
MessageFrom(target, who, "had their title color removed");
} else {
col = Matcher.FindColor(p, colName);
if (col == null) return;
if (col == target.titlecolor) { p.Message("{0} %Salready has that title color.", p.FormatNick(target)); return; }

Chat.MessageFrom(target, "λNICK %Shad their title color changed to " + col + Colors.Name(col));
MessageFrom(target, who, "had their title color changed to " + col + Colors.Name(col));
}

target.titlecolor = col;
target.SetPrefix();
PlayerDB.Update(target.name, PlayerData.ColumnTColor, col);
if (who != null) who.titlecolor = col;
if (who != null) who.SetPrefix();
PlayerDB.Update(target, PlayerData.ColumnTColor, col);
}

public override void Help(Player p) {
Expand Down
17 changes: 9 additions & 8 deletions MCGalaxy/Commands/Chat/CmdTitle.cs
Expand Up @@ -31,21 +31,22 @@ public class CmdTitle : EntityPropertyCmd {

public override void Use(Player p, string message, CommandData data) {
if (!MessageCmd.CanSpeak(p, name)) return;
UseOnline(p, data, message, "title");
UsePlayer(p, data, message, "title");
}

protected override void SetOnlineData(Player p, Player who, string title) {
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 = PlayerInfo.FindExact(target);

if (title.Length == 0) {
Chat.MessageFrom(who, "λNICK %Shad their title removed");
MessageFrom(target, who, "had their title removed");
} else {
Chat.MessageFrom(who, "λNICK %Shad their title changed to &b[" + title + "&b]");
MessageFrom(target, who, "had their title changed to &b[" + title + "&b]");
}

who.title = title;
who.SetPrefix();
PlayerDB.Update(who.name, PlayerData.ColumnTitle, title.UnicodeToCp437());
if (who != null) who.title = title;
if (who != null) who.SetPrefix();
PlayerDB.Update(target, PlayerData.ColumnTitle, title.UnicodeToCp437());
}

public override void Help(Player p) {
Expand Down
11 changes: 10 additions & 1 deletion MCGalaxy/Commands/EntityPropertyCmd.cs
Expand Up @@ -52,7 +52,7 @@ public abstract class EntityPropertyCmd : Command2 {
if (!CheckRank(p, data, who, "change the " + type + " of", true)) return;
SetOnlineData(p, who, args.Length > 1 ? args[1] : "");
}
protected void UsePlayer(Player p, CommandData data, string message, string type) {
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces(2);
Expand All @@ -71,5 +71,14 @@ public abstract class EntityPropertyCmd : Command2 {
protected virtual void SetBotData(Player p, PlayerBot bot, string args) { }
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);
}
}
}
}

0 comments on commit da8305f

Please sign in to comment.