Cleanup /pay.

This commit is contained in:
UnknownShadow200 2016-03-14 16:23:14 +11:00
parent 24b220ff7d
commit 21ea77eba9

View File

@ -14,7 +14,7 @@
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
@ -41,48 +41,36 @@ namespace MCGalaxy.Commands
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 pay negative %3" + Server.moneys); return; } if (amount < 0) { Player.SendMessage(p, "Cannot pay negative %3" + Server.moneys); return; }
if (p != null && p == who) { Player.SendMessage(p, "You cannot pay yourself %3" + Server.moneys); return; }
string target = null;
if (who == null) if (who == null) {
{ //player is offline OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
OfflinePlayer off = PlayerInfo.FindOffline(message.Split()[0]); if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
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; }
payer = Economy.RetrieveEcoStats(p.name); payer = Economy.RetrieveEcoStats(p.name);
receiver = Economy.RetrieveEcoStats(message.Split()[0]); receiver = Economy.RetrieveEcoStats(args[0]);
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return; if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
p.money -= amount; target = off.color + off.name;
payer.money = p.money;
receiver.money += amount;
payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + off.color + off.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.salary = "%f" + amount + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Economy.UpdateEcoStats(payer);
Economy.UpdateEcoStats(receiver);
Player.GlobalMessage(p.FullName + " %Spaid %f" + off.color + off.name + "%S(offline) %f" + amount + " %3" + Server.moneys); Player.GlobalMessage(p.FullName + " %Spaid %f" + off.color + off.name + "%S(offline) %f" + amount + " %3" + Server.moneys);
return; } else {
}
if (who == p) { Player.SendMessage(p, "%cYou can't pay yourself %3" + Server.moneys); return; }
payer = Economy.RetrieveEcoStats(p.name); payer = Economy.RetrieveEcoStats(p.name);
receiver = Economy.RetrieveEcoStats(who.name); receiver = Economy.RetrieveEcoStats(who.name);
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return; if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
p.money -= amount;
who.money += amount;
payer.money = p.money;
receiver.money = who.money; receiver.money = who.money;
who.money += amount;
target = who.color + who.name;
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys);
}
payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + who.color + who.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + target + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.salary = "%f" + amount + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); receiver.salary = "%f" + amount + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.money += amount;
p.money -= amount;
payer.money = p.money;
Economy.UpdateEcoStats(payer); Economy.UpdateEcoStats(payer);
Economy.UpdateEcoStats(receiver); Economy.UpdateEcoStats(receiver);
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys);
} }
bool IsLegalPayment(Player p, int payer, int receiver, int amount) { bool IsLegalPayment(Player p, int payer, int receiver, int amount) {
@ -92,7 +80,8 @@ namespace MCGalaxy.Commands
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.SendMessage(p, "%f/pay [player] <amount> " + Server.DefaultColor + "- Pays <amount> " + Server.moneys + " to [player]"); Player.SendMessage(p, "%T/pay [player] [amount] ");
Player.SendMessage(p, "%HPays <amount> %3" + Server.moneys + " %Hto [player]");
} }
} }
} }