mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-30 00:55:18 -04:00
Cleanup /pay.
This commit is contained in:
parent
24b220ff7d
commit
21ea77eba9
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 MCForge
|
Copyright 2011 MCForge
|
||||||
|
|
||||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||||
not use this file except in compliance with the Licenses. You may
|
not use this file except in compliance with the Licenses. You may
|
||||||
obtain a copy of the Licenses at
|
obtain a copy of the Licenses at
|
||||||
|
|
||||||
http://www.opensource.org/licenses/ecl2.php
|
http://www.opensource.org/licenses/ecl2.php
|
||||||
http://www.gnu.org/licenses/gpl-3.0.html
|
http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the Licenses are distributed on an "AS IS"
|
software distributed under the Licenses are distributed on an "AS IS"
|
||||||
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,49 +41,37 @@ 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 {
|
||||||
|
payer = Economy.RetrieveEcoStats(p.name);
|
||||||
|
receiver = Economy.RetrieveEcoStats(who.name);
|
||||||
|
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
|
||||||
|
|
||||||
|
receiver.money = who.money;
|
||||||
|
who.money += amount;
|
||||||
|
target = who.color + who.name;
|
||||||
|
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys);
|
||||||
}
|
}
|
||||||
if (who == p) { Player.SendMessage(p, "%cYou can't pay yourself %3" + Server.moneys); return; }
|
|
||||||
|
payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + target + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||||
payer = Economy.RetrieveEcoStats(p.name);
|
|
||||||
receiver = Economy.RetrieveEcoStats(who.name);
|
|
||||||
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
|
|
||||||
|
|
||||||
p.money -= amount;
|
|
||||||
who.money += amount;
|
|
||||||
|
|
||||||
payer.money = p.money;
|
|
||||||
receiver.money = who.money;
|
|
||||||
|
|
||||||
payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + who.color + who.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.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) {
|
||||||
if (receiver + amount > 16777215) { Player.SendMessage(p, "%cPlayers cannot have over %f16777215 %3" + Server.moneys); return false; }
|
if (receiver + amount > 16777215) { Player.SendMessage(p, "%cPlayers cannot have over %f16777215 %3" + Server.moneys); return false; }
|
||||||
@ -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]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user