mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-01 17:45:57 -04:00
Simplify OnBuyCommand for economy items
This commit is contained in:
parent
02663729ae
commit
6508dc3fca
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
// Custom command, so can still be used even when economy is disabled
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
Item item = Economy.GetItem("Snack");
|
||||
item.OnBuyCommand(p, message, message.SplitSpaces());
|
||||
item.OnPurchase(p, message);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.Eco {
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
string[] parts = message.SplitSpaces();
|
||||
string[] parts = message.SplitSpaces(2);
|
||||
Item item = Economy.GetItem(parts[0]);
|
||||
if (item == null) { Help(p); return; }
|
||||
|
||||
@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.Eco {
|
||||
if (data.Rank < item.PurchaseRank) {
|
||||
Formatter.MessageNeedMinPerm(p, "+ can purchase a " + item.Name, item.PurchaseRank); return;
|
||||
}
|
||||
item.OnBuyCommand(p, message, parts);
|
||||
item.OnPurchase(p, parts.Length == 1 ? "" : parts[1]);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -64,7 +64,7 @@ namespace MCGalaxy.Commands.Eco {
|
||||
if (item == null) {
|
||||
p.Message("No item has that name, see %T/Eco help %Sfor a list of items.");
|
||||
} else {
|
||||
item.OnSetupCommandHelp(p);
|
||||
item.OnSetupHelp(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,13 +49,13 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
|
||||
/// <summary> Called when the player does /buy [item name] <value> </summary>
|
||||
protected internal abstract void OnBuyCommand(Player p, string message, string[] args);
|
||||
protected internal abstract void OnPurchase(Player p, string args);
|
||||
|
||||
/// <summary> Called when the player does /eco [item name] [option] <value> </summary>
|
||||
protected internal abstract void OnSetupCommand(Player p, string[] args);
|
||||
protected internal abstract void OnSetup(Player p, string[] args);
|
||||
|
||||
/// <summary> Called when the player does /eco help [item name] </summary>
|
||||
protected internal virtual void OnSetupCommandHelp(Player p) {
|
||||
protected internal virtual void OnSetupHelp(Player p) {
|
||||
p.Message("%T/Eco {0} enable/disable", Name.ToLower());
|
||||
p.Message("%HEnables/disables purchasing this item.");
|
||||
p.Message("%T/Eco {0} purchaserank [rank]", Name.ToLower());
|
||||
@ -85,7 +85,7 @@ namespace MCGalaxy.Eco {
|
||||
PurchaseRank = grp.Permission;
|
||||
p.Message("Min purchase rank for {0} item set to {1}%S.", Name, grp.ColoredName);
|
||||
} else {
|
||||
OnSetupCommand(p, args);
|
||||
OnSetup(p, args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
protected bool CheckPrice(Player p) { return CheckPrice(p, Price, "a " + Name); }
|
||||
|
||||
protected internal override void OnSetupCommand(Player p, string[] args) {
|
||||
protected internal override void OnSetup(Player p, string[] args) {
|
||||
if (args[1].CaselessEq("price")) {
|
||||
int cost = 0;
|
||||
if (!CommandParser.GetInt(p, args[2], "Price", ref cost)) return;
|
||||
@ -134,8 +134,8 @@ namespace MCGalaxy.Eco {
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnSetupCommandHelp(Player p) {
|
||||
base.OnSetupCommandHelp(p);
|
||||
protected internal override void OnSetupHelp(Player p) {
|
||||
base.OnSetupHelp(p);
|
||||
p.Message("%T/Eco {0} price [amount]", Name.ToLower());
|
||||
p.Message("%HSets how many &3{0} %Hthis item costs.", Server.Config.Currency);
|
||||
}
|
||||
|
@ -72,16 +72,17 @@ namespace MCGalaxy.Eco {
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length < 2) { OnStoreCommand(p); return; }
|
||||
LevelPreset preset = FindPreset(args[1]);
|
||||
protected internal override void OnPurchase(Player p, string raw) {
|
||||
string[] args = raw.SplitSpaces();
|
||||
if (raw.Length == 0) { OnStoreCommand(p); return; }
|
||||
LevelPreset preset = FindPreset(args[0]);
|
||||
|
||||
if (preset == null) { p.Message("%WThat isn't a level preset"); return; }
|
||||
if (!CheckPrice(p, preset.price, "that map")) return;
|
||||
|
||||
string name = null;
|
||||
if (args.Length >= 3) {
|
||||
name = p.name + "_" + args[2];
|
||||
if (args.Length > 1) {
|
||||
name = p.name + "_" + args[1];
|
||||
} else {
|
||||
// use a numbered map by default
|
||||
for (int i = 1; i < 100; i++) {
|
||||
@ -110,7 +111,7 @@ namespace MCGalaxy.Eco {
|
||||
Economy.MakePurchase(p, preset.price, "%3Map: %f" + preset.name);
|
||||
}
|
||||
|
||||
protected internal override void OnSetupCommand(Player p, string[] args) {
|
||||
protected internal override void OnSetup(Player p, string[] args) {
|
||||
LevelPreset preset = FindPreset(args[2]);
|
||||
string cmd = args[1];
|
||||
|
||||
@ -121,7 +122,7 @@ namespace MCGalaxy.Eco {
|
||||
} else if (Command.IsEditCommand(cmd)) {
|
||||
EditPreset(p, args, preset);
|
||||
} else {
|
||||
OnSetupCommandHelp(p);
|
||||
OnSetupHelp(p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,8 +189,8 @@ namespace MCGalaxy.Eco {
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnSetupCommandHelp(Player p) {
|
||||
base.OnSetupCommandHelp(p);
|
||||
protected internal override void OnSetupHelp(Player p) {
|
||||
base.OnSetupHelp(p);
|
||||
p.Message("%T/Eco level add [name] [x] [y] [z] [theme] [price]");
|
||||
p.Message("%T/Eco level remove [name]");
|
||||
p.Message("%T/Eco level edit [name] [name/x/y/z/type/price] [value]");
|
||||
|
@ -28,15 +28,14 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "LoginMessage"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length == 1) {
|
||||
protected internal override void OnPurchase(Player p, string msg) {
|
||||
if (msg.Length == 0) {
|
||||
PlayerDB.SetLoginMessage(p.name, "");
|
||||
p.Message("&aYour login message was removed for free.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
string msg = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
if (msg == PlayerDB.GetLoginMessage(p)) {
|
||||
p.Message("%WYou already have that login message."); return;
|
||||
}
|
||||
@ -57,15 +56,14 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "LogoutMessage"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length == 1) {
|
||||
protected internal override void OnPurchase(Player p, string msg) {
|
||||
if (msg.Length == 0) {
|
||||
PlayerDB.SetLogoutMessage(p.name, "");
|
||||
p.Message("&aYour logout message was removed for free.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
string msg = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
if (!CheckPrice(p)) return;
|
||||
if (msg == PlayerDB.GetLogoutMessage(p)) {
|
||||
p.Message("%WYou already have that logout message."); return;
|
||||
}
|
||||
|
@ -27,14 +27,13 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Title"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length == 1) {
|
||||
protected internal override void OnPurchase(Player p, string title) {
|
||||
if (title.Length == 0) {
|
||||
UseCommand(p, "Title", "-own");
|
||||
p.Message("&aYour title was removed for free."); return;
|
||||
}
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
string title = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
if (title == p.title) {
|
||||
p.Message("%WYou already have that title."); return;
|
||||
}
|
||||
@ -55,14 +54,13 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Nickname"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length == 1) {
|
||||
protected internal override void OnPurchase(Player p, string nick) {
|
||||
if (nick.Length == 0) {
|
||||
UseCommand(p, "Nick", "-own");
|
||||
p.Message("&aYour nickname was removed for free."); return;
|
||||
}
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
string nick = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
if (nick == p.DisplayName) {
|
||||
p.Message("%WYou already have that nickname."); return;
|
||||
}
|
||||
@ -83,13 +81,14 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "TitleColor"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length < 2) { OnStoreCommand(p); return; }
|
||||
string color = Matcher.FindColor(p, args[1]);
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (args.Length == 0) { OnStoreCommand(p); return; }
|
||||
string color = Matcher.FindColor(p, args);
|
||||
|
||||
if (color == null) return;
|
||||
string colName = Colors.Name(color);
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
|
||||
if (color == p.titlecolor) {
|
||||
p.Message("%WYour title color is already " + color + colName); return;
|
||||
}
|
||||
@ -107,13 +106,14 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Color"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length < 2) { OnStoreCommand(p); return; }
|
||||
string color = Matcher.FindColor(p, args[1]);
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (args.Length == 0) { OnStoreCommand(p); return; }
|
||||
string color = Matcher.FindColor(p, args);
|
||||
|
||||
if (color == null) return;
|
||||
string colName = Colors.Name(color);
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
|
||||
if (color == p.color) {
|
||||
p.Message("%WYour color is already " + color + colName); return;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Snack"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (DateTime.UtcNow < p.NextEat) {
|
||||
p.Message("You're still full - you need to wait at least " +
|
||||
"10 seconds between snacks."); return;
|
||||
|
@ -79,8 +79,8 @@ namespace MCGalaxy.Eco {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length >= 2) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (args.Length > 0) {
|
||||
p.Message("%WYou cannot provide a rank name, use %T/Buy rank %Wto buy the NEXT rank."); return;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ namespace MCGalaxy.Eco {
|
||||
Economy.MakePurchase(p, nextRank.Price, "&3Rank: " + rank.ColoredName);
|
||||
}
|
||||
|
||||
protected internal override void OnSetupCommand(Player p, string[] args) {
|
||||
protected internal override void OnSetup(Player p, string[] args) {
|
||||
if (args[1].CaselessEq("price")) {
|
||||
Group grp = Matcher.FindRanks(p, args[2]);
|
||||
if (grp == null) return;
|
||||
@ -117,12 +117,12 @@ namespace MCGalaxy.Eco {
|
||||
p.Message("%WThat rank was not buyable to begin with.");
|
||||
}
|
||||
} else {
|
||||
OnSetupCommandHelp(p);
|
||||
OnSetupHelp(p);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnSetupCommandHelp(Player p) {
|
||||
base.OnSetupCommandHelp(p);
|
||||
protected internal override void OnSetupHelp(Player p) {
|
||||
base.OnSetupHelp(p);
|
||||
p.Message("%T/Eco rank price [rank] [amount]");
|
||||
p.Message("%HSets how many &3{0} %Hthat rank costs.", Server.Config.Currency);
|
||||
p.Message("%T/Eco rank remove [rank]");
|
||||
|
@ -32,10 +32,10 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "10Blocks"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
int count = 1;
|
||||
const string group = "Number of groups of 10 blocks";
|
||||
if (args.Length >= 2 && !CommandParser.GetInt(p, args[1], group, ref count, 0, 10)) return;
|
||||
if (args.Length > 0 && !CommandParser.GetInt(p, args, group, ref count, 0, 10)) return;
|
||||
|
||||
if (!CheckPrice(p, count * Price, (count * 10) + " blocks")) return;
|
||||
|
||||
@ -60,13 +60,13 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "QueueLevel"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (ZSGame.Instance.Picker.QueuedMap != null) {
|
||||
p.Message("Someone else has already queued a level."); return;
|
||||
}
|
||||
|
||||
if (args.Length < 2) { OnStoreCommand(p); return; }
|
||||
string map = Matcher.FindMaps(p, args[1]);
|
||||
if (args.Length == 0) { OnStoreCommand(p); return; }
|
||||
string map = Matcher.FindMaps(p, args);
|
||||
if (map == null) return;
|
||||
|
||||
if (!CheckPrice(p)) return;
|
||||
@ -91,12 +91,12 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "InfectMessage"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
if (args.Length < 2) { OnStoreCommand(p); return; }
|
||||
string text = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
protected internal override void OnPurchase(Player p, string msg) {
|
||||
if (msg.Length == 0) { OnStoreCommand(p); return; }
|
||||
bool hasAToken = false;
|
||||
for (int i = 0; i < text.Length; i++) {
|
||||
if (!CheckEscape(text, i, ref hasAToken)) {
|
||||
|
||||
for (int i = 0; i < msg.Length; i++) {
|
||||
if (!CheckEscape(msg, i, ref hasAToken)) {
|
||||
p.Message("You can only use {0} and {1} for tokens in infect messages."); return;
|
||||
}
|
||||
}
|
||||
@ -108,11 +108,11 @@ namespace MCGalaxy.Eco {
|
||||
if (!CheckPrice(p)) return;
|
||||
ZSData data = ZSGame.Get(p);
|
||||
if (data.InfectMessages == null) data.InfectMessages = new List<string>();
|
||||
data.InfectMessages.Add(text);
|
||||
data.InfectMessages.Add(msg);
|
||||
|
||||
ZSConfig.AppendPlayerInfectMessage(p.name, text);
|
||||
p.Message("&aAdded infect message: &f" + text);
|
||||
Economy.MakePurchase(p, Price, "%3InfectMessage: " + message);
|
||||
ZSConfig.AppendPlayerInfectMessage(p.name, msg);
|
||||
p.Message("&aAdded infect message: &f" + msg);
|
||||
Economy.MakePurchase(p, Price, "%3InfectMessage: " + msg);
|
||||
}
|
||||
|
||||
static bool CheckEscape(string text, int i, ref bool hasAToken) {
|
||||
@ -134,7 +134,7 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Invisibility"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (!CheckPrice(p, Price, "an invisibility potion")) return;
|
||||
if (!ZSGame.Instance.Running || !ZSGame.Instance.RoundInProgress) {
|
||||
p.Message("You can only buy an invisiblity potion " +
|
||||
@ -184,7 +184,7 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
public override string Name { get { return "Revive"; } }
|
||||
|
||||
protected internal override void OnBuyCommand(Player p, string message, string[] args) {
|
||||
protected internal override void OnPurchase(Player p, string args) {
|
||||
if (!CheckPrice(p, Price, "a revive potion")) return;
|
||||
if (!ZSGame.Instance.Running || !ZSGame.Instance.RoundInProgress) {
|
||||
p.Message("You can only buy a revive potion " +
|
||||
|
Loading…
x
Reference in New Issue
Block a user