Cleanup a number of the economy commands.

This commit is contained in:
UnknownShadow200 2016-03-14 16:02:50 +11:00
parent d8298a5010
commit 24b220ff7d
6 changed files with 130 additions and 165 deletions

View File

@ -1,20 +1,20 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Globalization;
namespace MCGalaxy.Commands
@ -28,78 +28,58 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdGive() { }
public override void Use(Player p, string message)
{
if (message.IndexOf(' ') == -1) { Help(p); return; }
if (message.Split(' ').Length != 2) { Help(p); return; }
public override void Use(Player p, string message) {
string[] args = message.Split(' ');
if (args.Length != 2) { Help(p); return; }
string user1 = "";
string user2 = "";
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; }
int amountGiven;
try { amountGiven = int.Parse(message.Split(' ')[1]); }
catch { Player.SendMessage(p, "%cInvalid amount"); return; }
if (amountGiven < 0) { Player.SendMessage(p, "%cCannot give negative %3" + Server.moneys); return; }
Player who = PlayerInfo.Find(message.Split(' ')[0]);
Economy.EcoStats ecos;
if (who == null)
{ //player is offline
OfflinePlayer off = PlayerInfo.FindOffline(message.Split()[0]);
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; }
ecos = Economy.RetrieveEcoStats(message.Split()[0]);
if (ReachedMax(p, ecos.money, amountGiven)) return;
ecos.money += amountGiven;
ecos.salary = "%f" + amountGiven + "%3 " + Server.moneys + " by " + user1 + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Economy.UpdateEcoStats(ecos);
//Player.GlobalMessage("%f" + ecos.playerName + Server.DefaultColor + "(offline) was given %f" + amountGiven + " %3" + Server.moneys + Server.DefaultColor + " by " + user2);
Player.GlobalMessage(user2 + Server.DefaultColor + " gave %f" + ecos.playerName + Server.DefaultColor + "(offline)" + " %f" + amountGiven + " %3" + Server.moneys);
return;
string giver = null, giverRaw = null;
if (p == null) {
giverRaw = "(console)"; giver = "(console)";
} else {
giverRaw = p.color + p.name; giver = p.FullName;
}
if (who == p /*&& p.name != Server.server_owner*/)
{
Player.SendMessage(p, "%cYou can't give yourself %3" + Server.moneys);
return;
}//I think owners should be able to give themselves money, for testing reasons..
//although questionable, because console could give money too
/* else if (who == p && p.name == Server.server_owner) {
if (ReachedMax(p, who.money, amountGiven)) return;
p.money += amountGiven;
ecos = Economy.RetrieveEcoStats(p.name);
ecos.money = p.money;
ecos.salary = "%f" + amountGiven + " %3 " + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Economy.UpdateEcoStats(ecos);
Player.SendMessage(p, "You gave yourself %f" + amountGiven + " %3" + Server.moneys);
return;
}*/
int amount;
if (!int.TryParse(args[1], out amount)) {
Player.SendMessage(p, "Amount must be an integer."); return;
}
if (amount < 0) { Player.SendMessage(p, "Cannot give negative %3" + Server.moneys); return; }
if (ReachedMax(p, who.money, amountGiven)) return;
who.money += amountGiven;
ecos = Economy.RetrieveEcoStats(who.name);
ecos.money = who.money;
ecos.salary = "%f" + amountGiven + "%3 " + Server.moneys + " by " + user1 + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Player who = PlayerInfo.Find(args[0]);
if (p != null && p == who) { Player.SendMessage(p, "You cannot give yourself %3" + Server.moneys); return; }
Economy.EcoStats ecos;
if (who == null) {
OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
ecos = Economy.RetrieveEcoStats(args[0]);
if (ReachedMax(p, ecos.money, amount)) return;
Player.GlobalMessage(giver + " %Sgave %f" + ecos.playerName + "%S(offline)" + " %f" + amount + " %3" + Server.moneys);
} else {
if (ReachedMax(p, who.money, amount)) return;
ecos.money = who.money;
who.money += amount;
ecos = Economy.RetrieveEcoStats(who.name);
Player.GlobalMessage(giver + " %Sgave " + who.FullName + " %f" + amount + " %3" + Server.moneys);
}
ecos.money += amount;
ecos.salary = "%f" + amount + "%3 " + Server.moneys + " by " +
giverRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
Economy.UpdateEcoStats(ecos);
Player.GlobalMessage(user2 + " %Sgave " + who.FullName + " %f" + amountGiven + " %3" + Server.moneys);
//Player.GlobalMessage(who.color + who.prefix + who.name + Server.DefaultColor + " was given %f" + amountGiven + " %3" + Server.moneys + Server.DefaultColor + " by " + user2);
}
public override void Help(Player p)
{
Player.SendMessage(p, "%f/give [player] <amount>" + Server.DefaultColor + " - Gives [player] <amount> %3" + Server.moneys);
}
private bool ReachedMax(Player p, int current, int amount)
{
if (current + amount > 16777215)
{
Player.SendMessage(p, "%cPlayers cannot have over %316777215 %3" + Server.moneys);
return true;
static bool ReachedMax(Player p, int current, int amount) {
if (current + amount > 16777215) {
Player.SendMessage(p, "%cPlayers cannot have over %316,777,215 %3" + Server.moneys); return true;
}
return false;
}
public override void Help(Player p) {
Player.SendMessage(p, "%T/give [player] <amount>");
Player.SendMessage(p, "%HGives [player] <amount> %3" + Server.moneys);
}
}
}

View File

@ -1,68 +1,52 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
namespace MCGalaxy.Commands
{
public sealed class CmdMoney : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdMoney : Command {
public override string name { get { return "money"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Economy; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
bool emptyMessage = message == "" || message == null || message == string.Empty;
if (p != null && emptyMessage)
{
Player.SendMessage(p, "You currently have %f" + p.money + " %3" + Server.moneys);
}
else if (message.Split().Length == 1)
{
Player who = PlayerInfo.Find(message);
if (who == null)
{ //player is offline
Economy.EcoStats ecos = Economy.RetrieveEcoStats(message);
Player.SendMessage(p, ecos.playerName + "(%foffline" + Server.DefaultColor + ") currently has %f" + ecos.money + " %3" + Server.moneys);
return;
}
//you can see everyone's stats with /eco stats [player]
/*if (who.group.Permission >= p.group.Permission) {
Player.SendMessage(p, "%cCannot see the money of someone of equal or greater rank.");
return;
}*/
Player.SendMessage(p, who.color + who.name + Server.DefaultColor + " currently has %f" + who.money + " %3" + Server.moneys);
}
else if (p == null && emptyMessage)
{
Player.SendMessage(p, "%Console can't have %3" + Server.moneys);
}
else
{
Player.SendMessage(p, "%cInvalid parameters!");
Help(p);
public override void Use(Player p, string message) {
if (message == "") {
if (p != null) Player.SendMessage(p, "You currently have %f" + p.money + " %3" + Server.moneys);
else Player.SendMessage(p, "You must provide a player name when using this command from console.");
return;
}
Player who = PlayerInfo.Find(message);
if (who == null) {
Economy.EcoStats ecos = Economy.RetrieveEcoStats(message);
Player.SendMessage(p, ecos.playerName + "(%foffline%S) currently has %f" + ecos.money + " %3" + Server.moneys);
} else {
Player.SendMessage(p, who.FullName + " %Scurrently has %f" + who.money + " %3" + Server.moneys);
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "%f/money <player>" + Server.DefaultColor + " - Shows how much %3" + Server.moneys + Server.DefaultColor + " <player> has");
public override void Help(Player p) {
Player.SendMessage(p, "%T/money <player>");
Player.SendMessage(p, "%HShows how much %3" + Server.moneys + " %H<player> has.");
Player.SendMessage(p, "%HIf <player> is not given, shows how much %3" + Server.moneys + " %Hyou have.");
}
}
}

View File

@ -30,17 +30,17 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message)
{
if (message.IndexOf(' ') == -1) { Help(p); return; }
if (message.Split(' ').Length != 2) { Help(p); return; }
Player who = PlayerInfo.Find(message.Split(' ')[0]);
string[] args = message.Split(' ');
if (args.Length != 2) { Help(p); return; }
Player who = PlayerInfo.Find(args[0]);
Economy.EcoStats payer;
Economy.EcoStats receiver;
int amountPaid;
try { amountPaid = int.Parse(message.Split(' ')[1]); }
catch { Player.SendMessage(p, "%cInvalid amount"); return; }
if (amountPaid < 0) { Player.SendMessage(p, "%cCannot pay negative %3" + Server.moneys); return; }
int amount;
if (!int.TryParse(args[1], out amount)) {
Player.SendMessage(p, "Amount must be an integer."); return;
}
if (amount < 0) { Player.SendMessage(p, "Cannot pay negative %3" + Server.moneys); return; }
if (who == null)
{ //player is offline
@ -49,51 +49,50 @@ namespace MCGalaxy.Commands
payer = Economy.RetrieveEcoStats(p.name);
receiver = Economy.RetrieveEcoStats(message.Split()[0]);
if (!IsLegalPayment(p, payer.money, receiver.money, amountPaid)) return;
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
p.money -= amountPaid;
p.money -= amount;
payer.money = p.money;
receiver.money += amountPaid;
receiver.money += amount;
payer.payment = "%f" + amountPaid + " %3" + Server.moneys + " to " + off.color + off.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.salary = "%f" + amountPaid + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
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" + amountPaid + " %3" + Server.moneys);
Player.GlobalMessage(p.FullName + " %Spaid %f" + off.color + off.name + "%S(offline) %f" + amount + " %3" + Server.moneys);
return;
}
if (who == p) { Player.SendMessage(p, "%cYou can't pay yourself %3" + Server.moneys); return; }
payer = Economy.RetrieveEcoStats(p.name);
receiver = Economy.RetrieveEcoStats(who.name);
if (!IsLegalPayment(p, payer.money, receiver.money, amountPaid)) return;
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
p.money -= amountPaid;
who.money += amountPaid;
p.money -= amount;
who.money += amount;
payer.money = p.money;
receiver.money = who.money;
payer.payment = "%f" + amountPaid + " %3" + Server.moneys + " to " + who.color + who.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.salary = "%f" + amountPaid + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
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);
Economy.UpdateEcoStats(payer);
Economy.UpdateEcoStats(receiver);
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amountPaid + " %3" + Server.moneys);
}
public override void Help(Player p)
{
Player.SendMessage(p, "%f/pay [player] <amount> " + Server.DefaultColor + "- Pays <amount> " + Server.moneys + " to [player]");
}
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys);
}
private 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 (payer - amount < 0) { Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys); return false; }
return true;
}
public override void Help(Player p) {
Player.SendMessage(p, "%f/pay [player] <amount> " + Server.DefaultColor + "- Pays <amount> " + Server.moneys + " to [player]");
}
}
}

View File

@ -192,7 +192,11 @@ namespace MCGalaxy {
}
public void SendMessage(CpeMessageType id, string message, bool colorParse = true) {
if (id != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) return;
if (id != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) {
if (id == CpeMessageType.Announcement) id = CpeMessageType.Normal;
else return;
}
if (colorParse)
message = Colors.EscapeColors(message);
StringBuilder sb = new StringBuilder(message);

View File

@ -475,7 +475,7 @@ namespace MCGalaxy {
if (p.ignoreAll || (global && p.ignoreGlobalChat)) continue;
if (p.level.worldChat && p.Chatroom == null)
Player.SendMessage(p, message, !global);
p.SendMessage(message, !global);
}
}

View File

@ -198,12 +198,10 @@ namespace MCGalaxy
public static string level = "main";
public static string errlog = "error.log";
// public static bool console = false; // never used
public static bool reportBack = true;
public static bool irc = false;
public static bool ircColorsEnable = true;
// public static bool safemode = false; //Never used
public static int ircPort = 6667;
public static string ircNick = "ForgeBot";
public static string ircServer = "irc.geekshed.net";