package net.uomc.mineshaft; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Random; import java.util.stream.IntStream; import java.util.stream.LongStream; import com.mouldycheerio.dbot.CustomBot; import com.mouldycheerio.dbot.commands.CommandDetails; import com.mouldycheerio.dbot.commands.CommandFail; import com.mouldycheerio.dbot.commands.DetailedCommand; import com.mouldycheerio.dbot.commands.cooldowns.CooldownCommand; import com.mouldycheerio.dbot.util.PeelingUtils; import com.vdurmont.emoji.EmojiParser; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.emoji.CustomEmoji; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public class FurnaceCommand extends CooldownCommand { private static final String COMMAND_IMAGE = "https://minecraft.wiki/images/Lit_Furnace_%28S%29.gif?40e71"; private static final String COMMAND_TITLE = "Furnace"; private static final double COPPER_SPAWN_AMOUNT = 16; private static final double IRON_SPAWN_AMOUNT = 8; private static final double GOLD_SPAWN_AMOUNT = 4; private static final double EMERALD_SPAWN_AMOUNT = 1; private static final double DIAMOND_SPAWN_AMOUNT = 1; private static final double XP_SPAWN_AMOUNT = 1000; private static final long FURNACE_ITEMS = 3; Mineshaft bot; public FurnaceCommand(Mineshaft bot) { super(bot); setCommandDetails(CommandDetails.from("furnace", "get free ingots", "furnace")); this.bot = bot; setCooldown(60l * 60l * 1000l); } @Override public boolean trigger(MessageReceivedEvent e) { long furnaces = bot.getItem(e.getMember(), MineshaftItem.FURNACE); if (furnaces < 1) { bot.sendErrorMessage(e, ":x: You need to have at least **" + bot.getItem(MineshaftItem.FURNACE).prettyValue(1) + "** to use this!"); return false; } Map award = new LinkedHashMap<>(); for (int i = 0; i < furnaces * FURNACE_ITEMS; ++i) { award =bot.sumItems(award, getAwards()); }; String description = "You came back to your **" + bot.getItem(MineshaftItem.FURNACE).prettyValue(furnaces) + "** and collected the ingots:\n"; String awardsList = bot.createItemList(award, "+%s"); description += awardsList; EmbedBuilder em = new EmbedBuilder(); em.setTitle(COMMAND_TITLE); em.setDescription(description); em.setThumbnail(COMMAND_IMAGE); em.setColor(PeelingUtils.hex2Rgb("#5c5a5a")); e.getMessage().addReaction(Emoji.fromUnicode(EmojiParser.parseToUnicode(":fire:"))); bot.addItems(e.getMember(), award); e.getMessage().replyEmbeds(em.build()).queue(); return true; } public Map getAwards() { Map award = new HashMap<>(); Random random = new Random(); switch (random.nextInt(14)) { case 0: case 1: case 2: case 3: award.put(MineshaftItem.IRON, (long) Math.ceil(Math.random() * IRON_SPAWN_AMOUNT)); break; case 4: case 5: case 6: award.put(MineshaftItem.COPPER, (long) Math.ceil(Math.random() * COPPER_SPAWN_AMOUNT)); break; case 7: case 8: case 9: award.put(MineshaftItem.GOLD, (long) Math.ceil(Math.random() * GOLD_SPAWN_AMOUNT)); break; case 10: case 11: award.put(MineshaftItem.DIAMOND, (long) Math.ceil(Math.random() * DIAMOND_SPAWN_AMOUNT)); break; case 12: case 13: default: award.put(MineshaftItem.EMERALD, (long) Math.ceil(Math.random() * EMERALD_SPAWN_AMOUNT)); break; } award.put(MineshaftItem.XP, (long) Math.ceil(Math.random() * XP_SPAWN_AMOUNT)); return award; } }