Skip to content

Commit

Permalink
Paginate /store list output (Thanks spicycombo)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Apr 1, 2023
1 parent ef12811 commit c9f2de6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 12 additions & 7 deletions MCGalaxy/Commands/Economy/CmdStore.cs
Expand Up @@ -16,10 +16,13 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Eco;

namespace MCGalaxy.Commands.Eco {
public sealed class CmdStore : Command2 {
namespace MCGalaxy.Commands.Eco
{
public sealed class CmdStore : Command2
{
public override string name { get { return "Store"; } }
public override string shortcut { get { return "Shop"; } }
public override string type { get { return CommandTypes.Economy; } }
Expand All @@ -29,11 +32,9 @@ public sealed class CmdStore : Command2 {
}

public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0) {
foreach (Item item in Economy.Items) {
if (!item.Enabled) continue;
item.OnStoreOverview(p);
}
if (message.Length == 0 || IsListModifier(message)) {
Paginator.Output(p, Economy.GetEnabledItems(),
PrintItemOverview, "Store", "enabled Items", message);
p.Message("&HUse &T/Store [item] &Hto see more information about that item.");
} else {
Item item = Economy.GetItem(message);
Expand All @@ -46,6 +47,10 @@ public sealed class CmdStore : Command2 {
}
}

static void PrintItemOverview(Player p, Item item) {
item.OnStoreOverview(p);
}

public override void Help(Player p) {
p.Message("&T/Store [item]");
p.Message("&HViews information about the specific item, such as its cost.");
Expand Down
9 changes: 9 additions & 0 deletions MCGalaxy/Economy/Economy.cs
Expand Up @@ -135,6 +135,15 @@ public static partial class Economy
return null;
}

public static List<Item> GetEnabledItems() {
List<Item> enabled = new List<Item>();
foreach (Item item in Economy.Items)
{
if (item.Enabled) enabled.Add(item);
}
return enabled;
}

/// <summary> Gets comma separated list of enabled items. </summary>
public static string EnabledItemNames() {
string items = Items.Join(x => x.Enabled ? x.ShopName : null);
Expand Down

0 comments on commit c9f2de6

Please sign in to comment.