use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class AxeCommand method upgrades.
@Command(value = "upgrades", description = "View all the upgrades you can use on a axe")
@CommandId(430)
@Examples({ "pickaxe upgrades" })
public void upgrades(Sx4CommandEvent event) {
EnumSet<Upgrade> upgrades = Upgrade.getUpgrades(ItemType.AXE);
PagedResult<Upgrade> paged = new PagedResult<>(event.getBot(), Arrays.asList(upgrades.toArray(Upgrade[]::new))).setPerPage(3).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setTitle("Axe Upgrades");
page.forEach((upgrade, index) -> embed.addField(upgrade.getName(), upgrade.getDescription(), false));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class AxeCommand method shop.
@Command(value = "shop", description = "View all the axes you are able to buy or craft")
@CommandId(388)
@Examples({ "axe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
List<Axe> axes = event.getBot().getEconomyManager().getItems(Axe.class);
PagedResult<Axe> paged = new PagedResult<>(event.getBot(), axes).setPerPage(12).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Axe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Axes are a good way to get some wood for crafting").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
page.forEach((axe, index) -> {
List<ItemStack<CraftItem>> items = axe.getCraft();
String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
embed.addField(axe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", axe.getPrice(), craft, axe.getMaxDurability()), true);
});
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class AxeCommand method repair.
@Command(value = "repair", description = "Repair your current axe with the material it is made from")
@CommandId(392)
@Examples({ "axe repair 10", "axe repair all" })
public void repair(Sx4CommandEvent event, @Argument(value = "durability") @AlternativeOptions("all") Alternative<Integer> option) {
Bson filter = Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.AXE.getId()));
Document data = event.getMongo().getItem(filter, Projections.include("item"));
if (data == null) {
event.replyFailure("You do not have a axe").queue();
return;
}
Axe axe = Axe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
CraftItem item = axe.getRepairItem();
if (item == null) {
event.replyFailure("That axe is not repairable").queue();
return;
}
int maxDurability = axe.getMaxDurability() - axe.getDurability();
if (maxDurability <= 0) {
event.replyFailure("Your axe is already at full durability").queue();
return;
}
int durability;
if (option.isAlternative()) {
durability = maxDurability;
} else {
int amount = option.getValue();
if (amount > maxDurability) {
event.reply("You can only repair your axe by **" + maxDurability + "** durability :no_entry:").queue();
return;
}
durability = amount;
}
int itemCount = (int) Math.ceil((((double) axe.getPrice() / item.getPrice()) / axe.getMaxDurability()) * durability);
List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
event.reply("It will cost you `" + itemCount + " " + item.getName() + "` to repair your axe by **" + durability + "** durability, are you sure you want to repair it?").setActionRow(buttons).submit().thenCompose(message -> {
return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
}).whenComplete((e, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof CancelException) {
GenericEvent cancelEvent = ((CancelException) cause).getEvent();
if (cancelEvent != null) {
((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
}
return;
} else if (cause instanceof TimeoutException) {
event.reply("Timed out :stopwatch:").queue();
return;
} else if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
List<Bson> update = List.of(Operators.set("amount", Operators.let(new Document("amount", Operators.ifNull("$amount", 0L)), Operators.cond(Operators.lte(itemCount, "$$amount"), Operators.subtract("$$amount", itemCount), "$$amount"))));
event.getMongo().updateItem(Filters.and(Filters.eq("item.id", item.getId()), Filters.eq("userId", event.getAuthor().getIdLong())), update, new UpdateOptions()).thenCompose(result -> {
if (result.getMatchedCount() == 0 || result.getModifiedCount() == 0) {
e.reply("You do not have `" + itemCount + " " + item.getName() + "` " + event.getConfig().getFailureEmote()).queue();
return CompletableFuture.completedFuture(null);
}
List<Bson> itemUpdate = List.of(Operators.set("item.durability", Operators.cond(Operators.eq("$item.durability", axe.getDurability()), Operators.add("$item.durability", durability), "$item.durability")));
return event.getMongo().updateItem(Filters.and(Filters.eq("item.id", axe.getId()), Filters.eq("userId", event.getAuthor().getIdLong())), itemUpdate, new UpdateOptions());
}).whenComplete((result, databaseException) -> {
if (ExceptionUtility.sendExceptionally(event, databaseException) || result == null) {
return;
}
if (result.getMatchedCount() == 0) {
e.reply("You no longer have that axe " + event.getConfig().getFailureEmote()).queue();
return;
}
if (result.getMatchedCount() == 0) {
e.reply("The durability of your axe has changed " + event.getConfig().getFailureEmote()).queue();
return;
}
e.reply("You just repaired your axe by **" + durability + "** durability " + event.getConfig().getSuccessEmote()).queue();
});
});
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class AxeCommand method info.
@Command(value = "info", aliases = { "information" }, description = "View information on a users axe")
@CommandId(391)
@Examples({ "axe info", "axe info @Shea#6653", "axe info Shea" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void info(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
Member effectiveMember = member == null ? event.getMember() : member;
User user = member == null ? event.getAuthor() : effectiveMember.getUser();
Bson filter = Filters.and(Filters.eq("userId", effectiveMember.getIdLong()), Filters.eq("item.type", ItemType.AXE.getId()));
Document data = event.getMongo().getItem(filter, Projections.include("item"));
if (data == null) {
event.replyFailure("That user does not have an axe").queue();
return;
}
Axe axe = Axe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s " + axe.getName(), null, user.getEffectiveAvatarUrl()).setColor(effectiveMember.getColorRaw()).setThumbnail("https://www.shareicon.net/data/2016/09/02/823994_ax_512x512.png").addField("Durability", axe.getDurability() + "/" + axe.getMaxDurability(), false).addField("Current Price", String.format("$%,d", axe.getCurrentPrice()), false).addField("Price", String.format("$%,d", axe.getPrice()), false).addField("Max Materials", String.valueOf(axe.getMaxMaterials()), false).addField("Multiplier", NumberUtility.DEFAULT_DECIMAL_FORMAT.format(axe.getMultiplier()), false);
event.reply(embed.build()).queue();
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method shop.
@Command(value = "shop", description = "View all the pickaxes you are able to buy or craft")
@CommandId(360)
@Examples({ "pickaxe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
List<Pickaxe> pickaxes = event.getBot().getEconomyManager().getItems(Pickaxe.class);
PagedResult<Pickaxe> paged = new PagedResult<>(event.getBot(), pickaxes).setPerPage(12).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Pickaxe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Pickaxes are a good way to gain some extra money aswell as some materials").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
page.forEach((pickaxe, index) -> {
List<ItemStack<CraftItem>> items = pickaxe.getCraft();
String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
embed.addField(pickaxe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", pickaxe.getPrice(), craft, pickaxe.getMaxDurability()), true);
});
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
Aggregations