Cleanup /take.

This commit is contained in:
UnknownShadow200 2016-03-14 19:45:38 +11:00
parent 69f5bdefc7
commit cb4890cb4d
2 changed files with 58 additions and 84 deletions

View File

@ -33,18 +33,14 @@ namespace MCGalaxy.Commands
if (args.Length != 2) { Help(p); return; } if (args.Length != 2) { Help(p); return; }
string giver = null, giverRaw = null; string giver = null, giverRaw = null;
if (p == null) { if (p == null) { giverRaw = "(console)"; giver = "(console)"; }
giverRaw = "(console)"; giver = "(console)"; else { giverRaw = p.color + p.name; giver = p.FullName; }
} else {
giverRaw = p.color + p.name; giver = p.FullName;
}
int amount; int amount;
if (!int.TryParse(args[1], out amount)) { if (!int.TryParse(args[1], out amount)) {
Player.SendMessage(p, "Amount must be an integer."); return; Player.SendMessage(p, "Amount must be an integer."); return;
} }
if (amount < 0) { Player.SendMessage(p, "Cannot give negative %3" + Server.moneys); return; } if (amount < 0) { Player.SendMessage(p, "Cannot give negative %3" + Server.moneys); return; }
Player who = PlayerInfo.Find(args[0]); Player who = PlayerInfo.Find(args[0]);
if (p != null && p == who) { Player.SendMessage(p, "You cannot give yourself %3" + Server.moneys); return; } if (p != null && p == who) { Player.SendMessage(p, "You cannot give yourself %3" + Server.moneys); return; }
Economy.EcoStats ecos; Economy.EcoStats ecos;

View File

@ -14,89 +14,67 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Globalization; using System.Globalization;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands
{ {
public sealed class CmdTake : Command public sealed class CmdTake : Command
{ {
public override string name { get { return "take"; } } public override string name { get { return "take"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } } public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdTake() { } public CmdTake() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ string[] args = message.Split(' ');
if (message.IndexOf(' ') == -1) { Help(p); return; } if (args.Length != 2) { Help(p); return; }
if (message.Split(' ').Length != 2) { Help(p); return; }
string user1 = ""; string taker = null, takerRaw = null;
string user2 = ""; if (p == null) { takerRaw = "(console)"; taker = "(console)"; }
if (p == null) { user1 = "%f[ " + Server.DefaultColor + "Console%f]"; user2 = String.Format("{0}Console [&a{1}{0}]", Server.DefaultColor, Server.ZallState); } else { user1 = p.color + p.name; user2 = p.prefix + p.name; } else { takerRaw = p.color + p.name; taker = p.FullName; }
int amountTaken = 0; int amount = 0;
bool all = false; bool all = args[1].CaselessEquals("all");
try { amountTaken = int.Parse(message.Split(' ')[1]); } if (!all && !int.TryParse(args[1], out amount)) {
catch Player.SendMessage(p, "Amount must be an integer."); return;
{ }
if (message.Split()[1].ToLower() != "all") if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; }
{ Player who = PlayerInfo.Find(args[0]);
Player.SendMessage(p, "%cInvalid amount"); if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; }
return;
} Economy.EcoStats ecos;
all = true; if (who == null) {
} OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
if (amountTaken < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; } if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
ecos = Economy.RetrieveEcoStats(args[0]);
Take(all, ref ecos, ref amount);
Player who = PlayerInfo.Find(message.Split()[0]); Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + off.color + off.name + "%f(offline)");
Economy.EcoStats ecos; } else {
if (who == null) ecos = Economy.RetrieveEcoStats(who.name);
{ //player is offline ecos.money = who.money;
OfflinePlayer off = PlayerInfo.FindOffline(message.Split()[0]); Take(all, ref ecos, ref amount);
if (off == null) { Player.SendMessage(p, "%cThe player %f" + message.Split()[0] + Server.DefaultColor + "(offline)%c does not exist or has never logged on to this server"); return; } who.money = ecos.money;
ecos = Economy.RetrieveEcoStats(message.Split()[0]); Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + who.prefix + who.name);
if (all || ecos.money - amountTaken < 0) }
{ ecos.fine = "%f" + amount + " %3" + Server.moneys + " by " + takerRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
amountTaken = ecos.money; Economy.UpdateEcoStats(ecos);
ecos.money = 0; }
}
else static void Take(bool all, ref Economy.EcoStats ecos, ref int amount) {
ecos.money -= amountTaken; if (all || ecos.money < amount) {
ecos.fine = "%f" + amountTaken + " %3" + Server.moneys + " by " + user1 + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); amount = ecos.money;
Economy.UpdateEcoStats(ecos); ecos.money = 0;
Player.GlobalMessage(user2 + Server.DefaultColor + " took %f" + amountTaken + " %3" + Server.moneys + Server.DefaultColor + " from " + off.color + off.name + "%f(offline)"); } else {
return; ecos.money -= amount;
} }
ecos = Economy.RetrieveEcoStats(who.name); }
if (who == p)
{ public override void Help(Player p){
Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); Player.SendMessage(p, "&f/take [player] <amount> " + Server.DefaultColor + "- Takes <amount> of " + Server.moneys + " from [player]");
return; Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]");
} }
}
if (all || ecos.money - amountTaken < 0)
{
amountTaken = who.money;
who.money = 0;
ecos.money = 0;
}
else
{
who.money -= amountTaken;
ecos.money = who.money;
}
ecos.fine = "%f" + amountTaken + " %3" + Server.moneys + " by " + user1 + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Economy.UpdateEcoStats(ecos);
Player.GlobalMessage(user2 + Server.DefaultColor + " took %f" + amountTaken + " %3" + Server.moneys + Server.DefaultColor + " from " + who.prefix + who.name);
}
public override void Help(Player p)
{
Player.SendMessage(p, "&f/take [player] <amount> " + Server.DefaultColor + "- Takes <amount> of " + Server.moneys + " from [player]");
Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]");
}
}
} }