Relative timespans in /balance

This commit is contained in:
UnknownShadow200 2016-09-06 08:26:33 +10:00
parent 329fdb24e9
commit a557a05703
3 changed files with 31 additions and 14 deletions

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Commands {
Level[] loaded = LevelInfo.Loaded.Items; Level[] loaded = LevelInfo.Loaded.Items;
if (LevelInfo.FindExact(map) == null) if (LevelInfo.FindExact(map) == null)
CmdLoad.LoadLevel(p, map, Server.AutoLoad); CmdLoad.LoadLevel(p, map, "0", Server.AutoLoad);
if (LevelInfo.FindExact(map) != null) if (LevelInfo.FindExact(map) != null)
PlayerActions.ChangeMap(p, map); PlayerActions.ChangeMap(p, map);
} else if (cmd == "LB" || cmd == "LEVELBLOCK") { } else if (cmd == "LB" || cmd == "LEVELBLOCK") {

View File

@ -26,17 +26,17 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.Economy; } } public override string type { get { return CommandTypes.Economy; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } 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) { public override void Use(Player p, string message) {
if (CheckSuper(p, message, "player name")) return; if (CheckSuper(p, message, "player name")) return;
if (!Formatter.ValidName(p, message, "player")) return; if (!Formatter.ValidName(p, message, "player")) return;
int matches = 1; int matches = 1;
Player who = message == "" ? p : PlayerInfo.FindMatches(p, message, out matches); Player who = message == "" ? p : PlayerInfo.FindMatches(p, message, out matches);
if (matches > 1) return; if (matches > 1) return;
string target = null; string target = null;
int money = 0; int money = 0;
if (matches == 0) { if (matches == 0) {
target = Economy.FindMatches(p, message, out money); target = Economy.FindMatches(p, message, out money);
if (target == null) return; if (target == null) return;
@ -50,20 +50,36 @@ namespace MCGalaxy.Commands {
Economy.EcoStats ecos = Economy.RetrieveStats(target); Economy.EcoStats ecos = Economy.RetrieveStats(target);
Player.Message(p, " Total spent: &f" + ecos.TotalSpent + " &3" + Server.moneys); Player.Message(p, " Total spent: &f" + ecos.TotalSpent + " &3" + Server.moneys);
if (!(String.IsNullOrEmpty(ecos.Purchase) || ecos.Purchase == "%cNone")) Output(p, ecos.Purchase, "purchase");
Player.Message(p, " Last purchase: " + ecos.Purchase); Output(p, ecos.Payment, "payment");
if (!(String.IsNullOrEmpty(ecos.Payment) || ecos.Payment == "%cNone")) Output(p, ecos.Salary, "receipt");
Player.Message(p, " Last payment: " + ecos.Payment); Output(p, ecos.Fine, "fine");
if (!(String.IsNullOrEmpty(ecos.Salary) || ecos.Salary == "%cNone")) }
Player.Message(p, " Last receipt: " + ecos.Salary);
if (!(String.IsNullOrEmpty(ecos.Fine) || ecos.Fine == "%cNone")) const string dateFormat = "MM'/'dd'/'yyyy hh:mm:ss";
Player.Message(p, " Last fine: " + ecos.Fine); 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) { public override void Help(Player p) {
Player.Message(p, "%T/balance [player]"); Player.Message(p, "%T/balance [player]");
Player.Message(p, "%HShows how much %3" + Server.moneys + " %H<player> has, " + Player.Message(p, "%HShows how much %3" + Server.moneys + " %H<player> has, " +
"plus their most recent transactions."); "plus their most recent transactions.");
Player.Message(p, "%HIf [player] is not given, shows your own balance."); Player.Message(p, "%HIf [player] is not given, shows your own balance.");
} }
} }

View File

@ -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); byte block = Block.Byte(msg);
extBlock = 0; extBlock = 0;
if (msg.CaselessEq("skip") || msg.CaselessEq("none")) return Block.Zero; if (msg.CaselessEq("skip") || msg.CaselessEq("none")) return Block.Zero;