mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Allow providing reasons in give/pay/take, fix /pay not working from console.
This commit is contained in:
parent
c345f01d2e
commit
ad5f38f486
@ -28,12 +28,12 @@ namespace MCGalaxy.Commands {
|
||||
if (who == null) return;
|
||||
if (data.Amount >= 16777215) { Player.Message(p, "You can only fakepay up to 16777215."); return; }
|
||||
|
||||
Chat.MessageAll("{0} %Swas given {1} {2}", who.ColoredName, data.Amount, Server.moneys);
|
||||
MessageAll(p, "{0} %Sgave {1} &f{2} &3{3}{4}", who.name, data);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/fakepay [name] [amount]");
|
||||
Player.Message(p, "%HSends a fake give change message.");
|
||||
Player.Message(p, "%T/fakepay [name] [amount] <reason>");
|
||||
Player.Message(p, "%HSends a fake %T/give %Hchange message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +47,10 @@ namespace MCGalaxy.Commands {
|
||||
if (ReachedMax(p, money, data.Amount)) return;
|
||||
who.SetMoney(who.money + data.Amount);
|
||||
}
|
||||
|
||||
string targetName = PlayerInfo.GetColoredName(p, target);
|
||||
Chat.MessageAll("{0} %Sgave {1} &f{2} &3{3}",
|
||||
data.Source, targetName, data.Amount, Server.moneys);
|
||||
MessageAll(p, "{0} %Sgave {1} &f{2} &3{3}{4}", target, data);
|
||||
|
||||
Economy.EcoStats stats = Economy.RetrieveStats(target);
|
||||
stats.Salary = "%f" + data.Amount + "%3 " + Server.moneys + " by "
|
||||
+ data.SourceRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
stats.Salary = Format(p, " by " + data.SourceRaw, data);
|
||||
Economy.UpdateStats(stats);
|
||||
}
|
||||
|
||||
@ -66,8 +62,8 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/give [player] <amount>");
|
||||
Player.Message(p, "%HGives [player] <amount> %3" + Server.moneys);
|
||||
Player.Message(p, "%T/give [player] [amount] <reason>");
|
||||
Player.Message(p, "%HGives [player] [amount] %3" + Server.moneys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,46 +34,47 @@ namespace MCGalaxy.Commands {
|
||||
if (matches > 1) return;
|
||||
if (p != null && p == who) { Player.Message(p, "You cannot pay yourself %3" + Server.moneys); return; }
|
||||
string target = null;
|
||||
int money;
|
||||
int money, srcMoney = Player.IsSuper(p) ? int.MaxValue : p.money;
|
||||
|
||||
if (who == null) {
|
||||
target = Economy.FindMatches(p, data.Name, out money);
|
||||
if (target == null) return;
|
||||
|
||||
if (!IsLegalPayment(p, p.money, money, data.Amount)) return;
|
||||
if (!IsLegalPayment(p, srcMoney, money, data.Amount)) return;
|
||||
money += data.Amount;
|
||||
Economy.UpdateMoney(target, money);
|
||||
} else {
|
||||
target = who.name; money = who.money;
|
||||
if (!IsLegalPayment(p, p.money, money, data.Amount)) return;
|
||||
if (!IsLegalPayment(p, srcMoney, money, data.Amount)) return;
|
||||
who.SetMoney(who.money + data.Amount);
|
||||
}
|
||||
if (!Player.IsSuper(p)) p.SetMoney(p.money - data.Amount);
|
||||
MessageAll(p, "{0} %Spaid {1} &f{2} &3{3}{4}", target, data);
|
||||
|
||||
p.SetMoney(p.money - data.Amount);
|
||||
string targetName = PlayerInfo.GetColoredName(p, target);
|
||||
Chat.MessageAll("{0} %Spaid {1} &f{2} &3{3}",
|
||||
data.Source, targetName, data.Amount, Server.moneys);
|
||||
|
||||
Economy.EcoStats stats = Economy.RetrieveStats(p.name);
|
||||
stats.Payment = "%f" + data.Amount + " %3" + Server.moneys + " to "
|
||||
+ target + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
Economy.EcoStats stats = Economy.RetrieveStats(target);
|
||||
stats.Salary = Format(p, " by " + data.SourceRaw, data);
|
||||
Economy.UpdateStats(stats);
|
||||
|
||||
stats = Economy.RetrieveStats(target);
|
||||
stats.Salary = "%f" + data.Amount + " %3" + Server.moneys + " by "
|
||||
+ p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
if (Player.IsSuper(p)) return;
|
||||
stats = Economy.RetrieveStats(p.name);
|
||||
string targetName = PlayerInfo.GetColoredName(p, target);
|
||||
stats.Payment = Format(p, " to " + targetName, data);
|
||||
Economy.UpdateStats(stats);
|
||||
}
|
||||
|
||||
bool IsLegalPayment(Player p, int payer, int receiver, int amount) {
|
||||
if (receiver + amount > 16777215) { Player.Message(p, "%cPlayers cannot have over %f16777215 %3" + Server.moneys); return false; }
|
||||
if (payer - amount < 0) { Player.Message(p, "%cYou don't have enough %3" + Server.moneys); return false; }
|
||||
static bool IsLegalPayment(Player p, int payer, int receiver, int amount) {
|
||||
if (receiver + amount > 16777215) {
|
||||
Player.Message(p, "%cPlayers cannot have over %f16777215 %3" + Server.moneys); return false;
|
||||
}
|
||||
if (payer < amount) {
|
||||
Player.Message(p, "%cYou don't have enough %3" + Server.moneys); return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/pay [player] [amount] ");
|
||||
Player.Message(p, "%HPays [amount] &3" + Server.moneys + " %Hto [player]");
|
||||
Player.Message(p, "%T/pay [player] [amount] <reason>");
|
||||
Player.Message(p, "%HPays [amount] &3{0} %Hto [player]", Server.moneys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,14 +46,10 @@ namespace MCGalaxy.Commands {
|
||||
Take(ref money, ref data);
|
||||
who.SetMoney(money);
|
||||
}
|
||||
|
||||
string targetName = PlayerInfo.GetColoredName(p, target);
|
||||
Chat.MessageAll("{0} %Stook &f{2} &3{3} %Sfrom {1}",
|
||||
data.Source, targetName, data.Amount, Server.moneys);
|
||||
MessageAll(p, "{0} %Stook &f{2} &3{3} %Sfrom {1}{4}", target, data);
|
||||
|
||||
Economy.EcoStats stats = Economy.RetrieveStats(target);
|
||||
stats.Fine = "%f" + data.Amount + "%3 " + Server.moneys + " by "
|
||||
+ data.SourceRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
stats.Fine = Format(p, " by " + data.SourceRaw, data);
|
||||
Economy.UpdateStats(stats);
|
||||
}
|
||||
|
||||
@ -67,9 +63,9 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
public override void Help(Player p){
|
||||
Player.Message(p, "%T/take [player] [amount[");
|
||||
Player.Message(p, "%T/take [player] [amount] <reason>");
|
||||
Player.Message(p, "%HTakes [amount] of &3" + Server.moneys + " %Sfrom [player]");
|
||||
Player.Message(p, "%T/take [player] all");
|
||||
Player.Message(p, "%T/take [player] all <reason>");
|
||||
Player.Message(p, "%HTakes all the &3" + Server.moneys + " %Sfrom [player]");
|
||||
}
|
||||
}
|
||||
|
@ -17,42 +17,72 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using MCGalaxy.SQL;
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
public abstract class MoneyCmd : Command {
|
||||
public override string type { get { return CommandTypes.Economy; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Economy; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Economy; } }
|
||||
|
||||
protected bool ParseArgs(Player p, string message, bool canAll,
|
||||
protected bool ParseArgs(Player p, string message, bool canAll,
|
||||
string action, out MoneyCmdData data) {
|
||||
data = default(MoneyCmdData);
|
||||
string[] args = message.Split(' ');
|
||||
if (args.Length != 2) { Help(p); return false; }
|
||||
string[] args = message.SplitSpaces(3);
|
||||
if (args.Length < 2) { Help(p); return false; }
|
||||
data.Name = args[0];
|
||||
data.Reason = args.Length > 2 ? args[2] : "";
|
||||
|
||||
if (p == null) {
|
||||
data.SourceRaw = "(console)"; data.Source = "(console)";
|
||||
} else {
|
||||
data.SourceRaw = p.color + p.name; data.Source = p.ColoredName;
|
||||
if (p == null) {
|
||||
data.SourceRaw = "(console)"; data.Source = "(console)";
|
||||
} else {
|
||||
data.SourceRaw = p.color + p.name; data.Source = p.ColoredName;
|
||||
}
|
||||
|
||||
int amount = 0;
|
||||
data.All = canAll && args[1].CaselessEq("all");
|
||||
if (!data.All && !int.TryParse(args[1], out amount)) {
|
||||
Player.Message(p, "Amount to {0} must be an integer.", action); return false;
|
||||
if (!data.All && !int.TryParse(args[1], out amount)) {
|
||||
Player.Message(p, "Amount to {0} must be an integer.", action); return false;
|
||||
}
|
||||
if (amount < 0) {
|
||||
Player.Message(p, "You cannot {0} negative &3" + Server.moneys, action); return false;
|
||||
if (amount < 0) {
|
||||
Player.Message(p, "You cannot {0} negative &3{1}", action, Server.moneys); return false;
|
||||
}
|
||||
data.Amount = amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected struct MoneyCmdData {
|
||||
public string Source, SourceRaw, Name;
|
||||
public string Source, SourceRaw, Name, Reason;
|
||||
public int Amount;
|
||||
public bool All;
|
||||
}
|
||||
|
||||
protected static void MessageAll(Player p, string format,
|
||||
string target, MoneyCmdData data) {
|
||||
string targetName = PlayerInfo.GetColoredName(p, target);
|
||||
string msgReason = data.Reason == "" ? "" : " %S(" + data.Reason + "%S)";
|
||||
|
||||
Chat.MessageAll(format, data.Source, targetName,
|
||||
data.Amount, Server.moneys, msgReason);
|
||||
}
|
||||
|
||||
protected static string Format(Player p, string action,
|
||||
MoneyCmdData data) {
|
||||
string entry = "%f" + data.Amount + "%3 " + Server.moneys + action
|
||||
+ "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
string reason = data.Reason;
|
||||
|
||||
if (reason == "") return entry;
|
||||
if (!Database.Backend.EnforcesTextLength)
|
||||
return entry + " (" + reason + ")";
|
||||
|
||||
int totalLen = entry.Length + 3 + reason.Length;
|
||||
if (totalLen >= 256) {
|
||||
int truncatedLen = reason.Length - (totalLen - 255);
|
||||
reason = reason.Substring(0, truncatedLen);
|
||||
Player.Message(p, "Reason too long, truncating to: {0}", reason);
|
||||
}
|
||||
return entry + " (" + reason + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ namespace MCGalaxy {
|
||||
Player.GlobalIRCMessage("%I[IRC] " + newNick + " %Sis back");
|
||||
Server.ircafkset.Remove(newNick);
|
||||
} else {
|
||||
Player.GlobalIRCMessage("%I[IRC] " + user.Nick + " %Sis now known as " + newNick);
|
||||
Player.GlobalIRCMessage("%I[IRC] " + user.Nick + " %Sis now known as %I" + newNick);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,11 @@ namespace MCGalaxy {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
bool first = true;
|
||||
foreach (T item in items) {
|
||||
if (!first) builder.Append(separator);
|
||||
builder.Append(formatter(item));
|
||||
string value = formatter(item);
|
||||
if (value == null) continue;
|
||||
|
||||
if (!first) builder.Append(separator);
|
||||
builder.Append(value);
|
||||
first = false;
|
||||
}
|
||||
return builder.ToString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user