From 6a11995882b6952131a7a0b1fe92d9c99dd419d3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 22 Oct 2017 18:55:14 +1100 Subject: [PATCH] Combine fakerank/hackrank shared code --- MCGalaxy/Commands/Moderation/ModActionCmd.cs | 10 ---------- MCGalaxy/Commands/other/CmdFakerank.cs | 17 +++++++++-------- MCGalaxy/Commands/other/CmdHackRank.cs | 10 +--------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/MCGalaxy/Commands/Moderation/ModActionCmd.cs b/MCGalaxy/Commands/Moderation/ModActionCmd.cs index 6ecccef16..12379e17a 100644 --- a/MCGalaxy/Commands/Moderation/ModActionCmd.cs +++ b/MCGalaxy/Commands/Moderation/ModActionCmd.cs @@ -77,16 +77,6 @@ namespace MCGalaxy.Commands.Moderation { } } - - /// Gets a formatted rank change message for the given name. - internal static string FormatRankChange(Group curRank, Group newRank, string name, string reason) { - string direction = newRank.Permission >= curRank.Permission ? " %Swas promoted to " : " %Swas demoted to "; - Player who = PlayerInfo.FindExact(name); - - if (who != null) name = who.ColoredName; - return name + direction + newRank.ColoredName + "%S. (" + reason + "%S)"; - } - /// Changes the rank of the given player from the old to the new rank. internal static void ChangeRank(string name, Group oldRank, Group newRank, Player who, bool saveToNewRank = true) { diff --git a/MCGalaxy/Commands/other/CmdFakerank.cs b/MCGalaxy/Commands/other/CmdFakerank.cs index 2016ad04e..f91b75082 100644 --- a/MCGalaxy/Commands/other/CmdFakerank.cs +++ b/MCGalaxy/Commands/other/CmdFakerank.cs @@ -34,15 +34,16 @@ namespace MCGalaxy.Commands.Misc { if (p != null && who.Rank > p.Rank) { MessageTooHighRank(p, "fakerank", true); return; } - + DoFakerank(p, who, newRank); + } + + internal static void DoFakerank(Player p, Player who, Group newRank) { if (newRank.Permission == LevelPermission.Banned) { - string banner = p == null ? "console" : p.ColoredName; - Chat.MessageGlobal("{0} %Swas &8banned %Sby {1}%S.", - who.ColoredName, banner); + Chat.MessageGlobal("{0} %Swas &8banned%S.", who.ColoredName); } else { - string reason = newRank.Permission >= who.Rank ? - ServerConfig.DefaultPromoteMessage : ServerConfig.DefaultDemoteMessage; - string rankMsg = ModActionCmd.FormatRankChange(who.group, newRank, who.name, reason); + string reason = newRank.Permission >= who.Rank ? ServerConfig.DefaultPromoteMessage : ServerConfig.DefaultDemoteMessage; + string direction = newRank.Permission >= who.Rank ? " %Swas promoted to " : " %Swas demoted to "; + string rankMsg = who.ColoredName + direction + newRank.ColoredName + "%S. (" + reason + "%S)"; Chat.MessageGlobal(rankMsg); Player.Message(who, "You are now ranked {0}%S, type /help for your new set of commands.", @@ -51,7 +52,7 @@ namespace MCGalaxy.Commands.Misc { who.color = newRank.Color; Entities.GlobalRespawn(who); - who.SetPrefix(); + who.SetPrefix(); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/other/CmdHackRank.cs b/MCGalaxy/Commands/other/CmdHackRank.cs index 8cafa8368..1fa54c5b1 100644 --- a/MCGalaxy/Commands/other/CmdHackRank.cs +++ b/MCGalaxy/Commands/other/CmdHackRank.cs @@ -44,15 +44,7 @@ namespace MCGalaxy.Commands.Misc { void DoFakeRank(Player p, Group newRank) { p.hackrank = true; - string rankMsg = ModActionCmd.FormatRankChange(p.group, newRank, p.name, "Congratulations!"); - Chat.MessageGlobal(rankMsg); - - Player.Message(p, "You are now ranked " + newRank.ColoredName + "%S, type /help for your new set of commands."); - p.color = newRank.Color; - - Entities.GlobalRespawn(p); - p.SetPrefix(); - + CmdFakeRank.DoFakerank(p, p, newRank); DoKick(p, newRank); }