From a557a05703b73abb5157e60ba5891539a4947d73 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 6 Sep 2016 08:26:33 +1000 Subject: [PATCH] Relative timespans in /balance --- Commands/CmdOverseer.cs | 2 +- Commands/Economy/CmdBalance.cs | 40 ++++++++++++++++++++++++---------- Commands/building/DrawCmd.cs | 3 ++- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Commands/CmdOverseer.cs b/Commands/CmdOverseer.cs index b9fab7af1..a53611386 100644 --- a/Commands/CmdOverseer.cs +++ b/Commands/CmdOverseer.cs @@ -59,7 +59,7 @@ namespace MCGalaxy.Commands { Level[] loaded = LevelInfo.Loaded.Items; if (LevelInfo.FindExact(map) == null) - CmdLoad.LoadLevel(p, map, Server.AutoLoad); + CmdLoad.LoadLevel(p, map, "0", Server.AutoLoad); if (LevelInfo.FindExact(map) != null) PlayerActions.ChangeMap(p, map); } else if (cmd == "LB" || cmd == "LEVELBLOCK") { diff --git a/Commands/Economy/CmdBalance.cs b/Commands/Economy/CmdBalance.cs index 669b287f1..70589f400 100644 --- a/Commands/Economy/CmdBalance.cs +++ b/Commands/Economy/CmdBalance.cs @@ -26,17 +26,17 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Economy; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandEnable Enabled { get { return CommandEnable.Economy; } } + public override CommandEnable Enabled { get { return CommandEnable.Economy; } } public override void Use(Player p, string message) { if (CheckSuper(p, message, "player name")) return; - if (!Formatter.ValidName(p, message, "player")) return; + if (!Formatter.ValidName(p, message, "player")) return; int matches = 1; Player who = message == "" ? p : PlayerInfo.FindMatches(p, message, out matches); if (matches > 1) return; string target = null; - int money = 0; + int money = 0; if (matches == 0) { target = Economy.FindMatches(p, message, out money); if (target == null) return; @@ -50,20 +50,36 @@ namespace MCGalaxy.Commands { Economy.EcoStats ecos = Economy.RetrieveStats(target); Player.Message(p, " Total spent: &f" + ecos.TotalSpent + " &3" + Server.moneys); - if (!(String.IsNullOrEmpty(ecos.Purchase) || ecos.Purchase == "%cNone")) - Player.Message(p, " Last purchase: " + ecos.Purchase); - if (!(String.IsNullOrEmpty(ecos.Payment) || ecos.Payment == "%cNone")) - Player.Message(p, " Last payment: " + ecos.Payment); - if (!(String.IsNullOrEmpty(ecos.Salary) || ecos.Salary == "%cNone")) - Player.Message(p, " Last receipt: " + ecos.Salary); - if (!(String.IsNullOrEmpty(ecos.Fine) || ecos.Fine == "%cNone")) - Player.Message(p, " Last fine: " + ecos.Fine); + Output(p, ecos.Purchase, "purchase"); + Output(p, ecos.Payment, "payment"); + Output(p, ecos.Salary, "receipt"); + Output(p, ecos.Fine, "fine"); + } + + const string dateFormat = "MM'/'dd'/'yyyy hh:mm:ss"; + static void Output(Player p, string value, string type) { + if (String.IsNullOrEmpty(value) || value == "%cNone") return; + + int timeIndex = value.IndexOf(" on %f"); + if (timeIndex == -1) { + Player.Message(p, " Last {0}: {1}", type, value); return; + } + string msg = value.Substring(0, timeIndex); + string date = value.Substring(timeIndex + 6); + + // Attempt to show relative time + DateTime time; + if (DateTime.TryParseExact(date, dateFormat, null, 0, out time)) { + TimeSpan delta = DateTime.Now - time; + value = msg + " %f" + delta.Shorten() + " ago"; + } + Player.Message(p, " Last {0}: {1}", type, value); } public override void Help(Player p) { Player.Message(p, "%T/balance [player]"); Player.Message(p, "%HShows how much %3" + Server.moneys + " %H has, " + - "plus their most recent transactions."); + "plus their most recent transactions."); Player.Message(p, "%HIf [player] is not given, shows your own balance."); } } diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index d9822625d..c94ceabe9 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -79,7 +79,8 @@ namespace MCGalaxy.Commands.Building { } - internal static int GetBlock(Player p, string msg, out byte extBlock, bool checkPlacePerm = true) { + public static int GetBlock(Player p, string msg, out byte extBlock, + bool checkPlacePerm = true) { byte block = Block.Byte(msg); extBlock = 0; if (msg.CaselessEq("skip") || msg.CaselessEq("none")) return Block.Zero;