From c197436b55d73ef6ceeff55ccdac389912454388 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 27 Aug 2016 21:58:51 +1000 Subject: [PATCH] Cleanup /eco help. --- Commands/Economy/CmdBuy.cs | 25 +++----- Commands/Economy/CmdEconomy.cs | 83 +++++++++++-------------- Commands/Economy/CmdStore.cs | 28 ++++----- Economy/Economy.cs | 10 ++- Economy/Item.cs | 13 ++++ Economy/LevelItem.cs | 13 +++- Economy/RankItem.cs | 10 ++- Games/ZombieSurvival/ZombieGame.Game.cs | 2 +- 8 files changed, 96 insertions(+), 88 deletions(-) diff --git a/Commands/Economy/CmdBuy.cs b/Commands/Economy/CmdBuy.cs index 33c08a895..514983a05 100644 --- a/Commands/Economy/CmdBuy.cs +++ b/Commands/Economy/CmdBuy.cs @@ -30,29 +30,24 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } string[] parts = message.Split(' '); + Item item = Economy.GetItem(parts[0]); + if (item == null) { Help(p); return; } - foreach (Item item in Economy.Items) - foreach (string alias in item.Aliases) - { - if (!parts[0].CaselessEq(alias)) continue; - - if (!item.Enabled) { - Player.Message(p, "%cThe {0} item is not currently buyable.", item.Name); return; - } - if (p.Rank < item.PurchaseRank) { - Formatter.MessageNeedMinPerm(p, "purchase a " + item.Name, item.PurchaseRank); return; - } - item.OnBuyCommand(this, p, message, parts); - return; + + if (!item.Enabled) { + Player.Message(p, "%cThe {0} item is not currently buyable.", item.Name); return; } - Help(p); + if (p.Rank < item.PurchaseRank) { + Formatter.MessageNeedMinPerm(p, "purchase a " + item.Name, item.PurchaseRank); return; + } + item.OnBuyCommand(this, p, message, parts); } public override void Help(Player p) { Player.Message(p, "%T/buy [item] [value] "); Player.Message(p, "%Hmap name is only used for %T/buy map%H."); Player.Message(p, "%HUse %T/store [item] %Hto see more information for an item."); - Player.Message(p, "%H Available items: %f" + Economy.GetItemNames(", ")); + Player.Message(p, "%H Available items: %S" + Economy.GetItemNames()); } } } diff --git a/Commands/Economy/CmdEconomy.cs b/Commands/Economy/CmdEconomy.cs index 8e48f1d53..fa28b8faf 100644 --- a/Commands/Economy/CmdEconomy.cs +++ b/Commands/Economy/CmdEconomy.cs @@ -1,7 +1,7 @@ /* 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 not use this file except in compliance with the Licenses. You may obtain a copy of the Licenses at @@ -16,10 +16,8 @@ permissions and limitations under the Licenses. */ using System; -using System.Globalization; -using System.Threading; using MCGalaxy.Eco; -using MCGalaxy.SQL; + namespace MCGalaxy.Commands { /// Economy Beta v1.0 QuantumHive @@ -44,60 +42,49 @@ namespace MCGalaxy.Commands { void HandleSetup(Player p, string[] args) { if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "setup the economy."); return; } - switch (args[0].ToLower()) { - case "apply": - Economy.Load(); - Player.Message(p, "%aApplied changes"); - return; - - case "enable": - Player.Message(p, "%aThe economy system is now enabled"); - Economy.Enabled = true; + if (args[0].CaselessEq("apply")) { + Economy.Load(); + Player.Message(p, "%aApplied changes"); + } else if (args[0].CaselessEq("enable")) { + Player.Message(p, "%aThe economy system is now enabled"); + Economy.Enabled = true; Economy.Save(); + } else if (args[0].CaselessEq("disable")) { + Player.Message(p, "%aThe economy system is now disabled"); + Economy.Enabled = false; Economy.Save(); + } else if (args[0].CaselessEq("help")) { + SetupHelp(p, args); + } else { + Item item = Economy.GetItem(args[0]); + if (item != null) { + item.OnSetupCommand(p, args); Economy.Save(); return; - - case "disable": - Player.Message(p, "%aThe economy system is now disabled"); - Economy.Enabled = false; - Economy.Save();return; - - case "help": - SetupHelp(p); return; - - default: - foreach (Item item in Economy.Items) - foreach (string alias in item.Aliases) - { - if (args[0].CaselessEq(alias)) { - item.OnSetupCommand(p, args); - Economy.Save(); return; - } - } - - if (args[1] == "") { SetupHelp(p); return; } - Player.Message(p, "%cThat wasn't a valid command addition!"); - return; + } + + if (args[1] == "") { SetupHelp(p, args); return; } + Player.Message(p, "%cThat wasn't a valid command addition!"); } } public override void Help(Player p) { Player.Message(p, "%cMost commands have been removed from /economy, " + - "use the appropriate command from %T/help economy %cinstead."); + "use the appropriate command from %T/help economy %cinstead."); if (CheckExtraPerm(p)) { - Player.Message(p, "%f/eco %e- to setup economy"); - Player.Message(p, "%f/eco help %e- get more specific help for setting up the economy"); + Player.Message(p, "%T/eco %H- to setup economy"); + Player.Message(p, "%T/eco help %H- get more specific help for setting up the economy"); } } - void SetupHelp(Player p) { - Player.Message(p, "%4/eco apply %e- reloads changes made to 'economy.properties'"); - Player.Message(p, "%4/eco [%aenable%4/%cdisable%4] %e- to enable/disable the economy system"); - Player.Message(p, "%4/eco [title/color/tcolor/rank/map] [%aenable%4/%cdisable%4] %e- to enable/disable that feature"); - Player.Message(p, "%4/eco [title/color/tcolor] [%3price%4] %e- to setup the prices for these features"); - Player.Message(p, "%4/eco rank price [%frank%4] [%3price%4] %e- to set the price for that rank"); - Player.Message(p, "%4/eco rank maxrank [%frank%4] %e- to set the max buyable rank"); - Player.Message(p, "%4/eco map new [%fname%4] [%fx%4] [%fy%4] [%fz%4] [%ftype%4] [%3price%4] %e- to setup a map preset"); - Player.Message(p, "%4/eco map delete [%fname%4] %e- to delete a map"); - Player.Message(p, "%4/eco map edit [%fname%4] [name/x/y/z/type/price] [%fvalue%4] %e- to edit a map preset"); + void SetupHelp(Player p, string[] args) { + if (args[1] == "") { + Player.Message(p, "%T/eco apply %H- Reload changes made to 'economy.properties'"); + Player.Message(p, "%T/eco enable/disable %H- Enables/disables the economy system"); + Player.Message(p, "%T/eco help [item] %H- Outputs help for setting up that item"); + Player.Message(p, " %HAll items: %S" + Economy.Items.Join(item => item.Name)); + } else { + Item item = Economy.GetItem(args[1]); + if (item == null) { Player.Message(p, "No item by that name, see %T/eco help %Sfor a list of items."); return; } + item.OnSetupCommandHelp(p); + } } } } diff --git a/Commands/Economy/CmdStore.cs b/Commands/Economy/CmdStore.cs index 451831b1d..152891fb0 100644 --- a/Commands/Economy/CmdStore.cs +++ b/Commands/Economy/CmdStore.cs @@ -18,7 +18,7 @@ using System; using MCGalaxy.Eco; -namespace MCGalaxy.Commands { +namespace MCGalaxy.Commands { public sealed class CmdStore : Command { public override string name { get { return "store"; } } public override string shortcut { get { return "shop"; } } @@ -28,30 +28,24 @@ namespace MCGalaxy.Commands { public override CommandEnable Enabled { get { return CommandEnable.Economy; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("item") }; } - } + } public override void Use(Player p, string message) { if (message == "") { foreach (Item item in Economy.Items) { if (!item.Enabled) continue; - item.OnStoreOverview(p); + item.OnStoreOverview(p); } Player.Message(p, "%HUse %T/store [item] %Hto see more information about that item."); - return; - } - - foreach (Item item in Economy.Items) - foreach (string alias in item.Aliases) - { - if (message.CaselessEq(alias)) { - if (!item.Enabled) { - Player.Message(p, "%cThe " + item.ShopName + " item is not currently buyable."); return; - } - item.OnStoreCommand(p); - return; + } else { + Item item = Economy.GetItem(message); + if (item == null) { Help(p); return; } + + if (!item.Enabled) { + Player.Message(p, "%cThe " + item.ShopName + " item is not currently buyable."); return; } + item.OnStoreCommand(p); } - Help(p); } public override void Help(Player p) { @@ -59,7 +53,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "%HViews information about the specific item, such as its cost."); Player.Message(p, "%T/store"); Player.Message(p, "%HViews information about all enabled items."); - Player.Message(p, "%H Available items: %f" + Economy.GetItemNames(", ")); + Player.Message(p, "%H Available items: %S" + Economy.GetItemNames()); } } } diff --git a/Economy/Economy.cs b/Economy/Economy.cs index 024420faa..a0711896b 100644 --- a/Economy/Economy.cs +++ b/Economy/Economy.cs @@ -153,12 +153,16 @@ PRIMARY KEY(player) public static Item GetItem(string name) { foreach (Item item in Items) { if (name.CaselessEq(item.Name)) return item; + + foreach (string alias in item.Aliases) { + if (name.CaselessEq(alias)) return item; + } } return null; } - - public static string GetItemNames(string separator) { - string items = Items.Join(x => x.Enabled ? x.ShopName : null, separator); + + public static string GetItemNames() { + string items = Items.Join(x => x.Enabled ? x.ShopName : null); return items.Length == 0 ? "(no enabled items)" : items; } diff --git a/Economy/Item.cs b/Economy/Item.cs index 6d1641174..9415dc77d 100644 --- a/Economy/Item.cs +++ b/Economy/Item.cs @@ -70,6 +70,13 @@ namespace MCGalaxy.Eco { } protected internal abstract void OnSetupCommandOther(Player p, string[] args); + + protected internal virtual void OnSetupCommandHelp(Player p) { + Player.Message(p, "%T/eco {0} enable/disable", Name.ToLower()); + Player.Message(p, "%HEnables/disables purchasing this item."); + Player.Message(p, "%T/eco {0} purchaserank [rank]", Name.ToLower()); + Player.Message(p, "%HSets the lowest rank which can purchase this item."); + } protected internal abstract void OnStoreOverview(Player p); @@ -125,6 +132,12 @@ namespace MCGalaxy.Eco { } } + protected internal override void OnSetupCommandHelp(Player p) { + base.OnSetupCommandHelp(p); + Player.Message(p, "%T/eco {0} price [amount]", Name.ToLower()); + Player.Message(p, "%HSets how many &3{0} %Hthis item costs.", Server.moneys); + } + protected internal override void OnStoreOverview(Player p) { if (p == null || p.Rank >= PurchaseRank) { Player.Message(p, "{0} - costs &f{1} &3{2}", Name, Price, Server.moneys); diff --git a/Economy/LevelItem.cs b/Economy/LevelItem.cs index ec96e6dc4..2be762ab2 100644 --- a/Economy/LevelItem.cs +++ b/Economy/LevelItem.cs @@ -204,17 +204,24 @@ namespace MCGalaxy.Eco { break; default: - Player.Message(p, "%cThat wasn't a valid command addition!"); + Player.Message(p, "Supported properties to edit: name, title, x, y, z, type, price"); break; } break; default: - Player.Message(p, "%cThat wasn't a valid command addition!"); - break; + OnSetupCommandHelp(p); break; } } + protected internal override void OnSetupCommandHelp(Player p) { + base.OnSetupCommandHelp(p); + Player.Message(p, "%T/eco level add [name] [x] [y] [z] [type] [price]"); + Player.Message(p, "%T/eco level remove [name]"); + Player.Message(p, "%T/eco level edit [name] [name/x/y/z/type/price] [value]"); + Player.Message(p, "%HAdds, removes, or edits a level preset."); + } + protected internal override void OnStoreOverview(Player p) { Player.Message(p, "Maps - see /store maps"); } diff --git a/Economy/RankItem.cs b/Economy/RankItem.cs index 2f372cc84..2071b509b 100644 --- a/Economy/RankItem.cs +++ b/Economy/RankItem.cs @@ -110,9 +110,17 @@ namespace MCGalaxy.Eco { UpdatePrices(); break; default: - Player.Message(p, "Supported actions: enable, disable, price [rank] [cost], maxrank [rank]"); break; + OnSetupCommandHelp(p); break; } } + + protected internal override void OnSetupCommandHelp(Player p) { + base.OnSetupCommandHelp(p); + Player.Message(p, "%T/eco rank price [rank] [amount]"); + Player.Message(p, "%HSets how many &3{0} %Hthat rank costs.", Server.moneys); + Player.Message(p, "%T/eco rank maxrank [rank]"); + Player.Message(p, "%HSets the maximum rank that can be bought.", Server.moneys); + } protected internal override void OnStoreOverview(Player p) { Group maxrank = Group.Find(MaxRank); diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index 3ab71faf0..5968b4b26 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -61,7 +61,7 @@ namespace MCGalaxy.Games { p.Game.BlocksLeft--; if ((p.Game.BlocksLeft % 10) == 0 || (p.Game.BlocksLeft >= 0 && p.Game.BlocksLeft <= 10)) - p.SendMessage("Blocks Left: " + Colors.maroon + p.Game.BlocksLeft); + p.SendMessage("Blocks Left: &4" + p.Game.BlocksLeft); } return false; }