use of gartham.c10ver.economy.items.ItemCategory in project c10ver by Gartham.
the class InventoryCommand method displayRoot.
private void displayRoot(CommandInvocation inv) {
EmbedBuilder eb = new EmbedBuilder();
UserInventory inventory = clover.getEconomy().getInventory(inv.event.getAuthor().getId());
if (inventory.isEmpty()) {
eb.appendDescription("Your inventory is empty!");
eb.setColor(new Color(0xc20000));
inv.event.getChannel().sendMessageEmbeds(eb.build()).queue();
} else {
Map<ItemCategory, BigInteger> ics = new HashMap<>();
for (var e : inventory) for (var is : e) if (ics.containsKey(is.getItem().getCategory()))
ics.put(is.getItem().getCategory(), ics.get(is.getItem().getCategory()).add(is.count()));
else
ics.put(is.getItem().getCategory(), is.count());
eb.appendDescription("You have **" + Utilities.formatNumber(inventory.getTotalItemCount()) + "** items.\n\n");
eb.setTitle(inv.event.getAuthor().getAsTag() + "'s Inventory").setAuthor(inv.event.isFromGuild() ? inv.event.getMember().getEffectiveName() : inv.event.getAuthor().getName(), null, inv.event.getAuthor().getEffectiveAvatarUrl());
eb.appendDescription("Page **1** of **1**.");
ButtonPaginator bp = new ButtonPaginator(clover.getEventHandler().getButtonClickProcessor());
bp.setTarget(inv.event.getAuthor());
bp.getMah().new Action(Button.primary("sel", "\u200b").asDisabled()).reposition(2);
bp.setHandler(t -> {
var cat = ItemCategory.valueOf(t.getComponentId());
displayCategory(cat, inv, bp.getMsg());
// return whether we updated the event.
return false;
});
bp.setMaxPage(0);
bp.setOneTime(true);
for (var i : ics.entrySet()) {
eb.addField(i.getKey().getDisplayName() + " " + i.getKey().getIcon(), "Items: " + (i.getValue().equals(BigInteger.ZERO) ? "None" : "**" + Utilities.formatNumber(i.getValue()) + "**"), true);
bp.getMah().new Action(Button.success(i.getKey().name(), Emoji.fromMarkdown(i.getKey().getIcon())).withLabel(i.getKey().getDisplayName()));
}
bp.attachAndSend(inv.event.getChannel().sendMessageEmbeds(eb.build()));
}
}
Aggregations