From fff63aaea786a5f1c59bbf99c999a2aa7bb810e5 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 19 Oct 2025 16:16:05 +0100 Subject: Add farm, sleep and trade --- src/main/java/net/uomc/mineshaft/Mineshaft.java | 95 ++++++++++++++++--------- 1 file changed, 62 insertions(+), 33 deletions(-) (limited to 'src/main/java/net/uomc/mineshaft/Mineshaft.java') diff --git a/src/main/java/net/uomc/mineshaft/Mineshaft.java b/src/main/java/net/uomc/mineshaft/Mineshaft.java index 1584529..41e4ce4 100644 --- a/src/main/java/net/uomc/mineshaft/Mineshaft.java +++ b/src/main/java/net/uomc/mineshaft/Mineshaft.java @@ -10,7 +10,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import javax.security.auth.login.LoginException; @@ -31,6 +33,7 @@ import com.mouldycheerio.dbot.starboard.StarboardController; import com.mouldycheerio.dbot.util.PeelingUtils; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.uomc.mineshaft.resources.ResourceManager; import net.uomc.mineshaft.resources.market.MarketCommand; @@ -43,11 +46,13 @@ public class Mineshaft extends CustomBot { private Crafting crafting; private MineCommand mineCommand; private EnchantCommand enchantCommand; + private PlayerHealths healths; public Mineshaft(JSONObject config) throws LoginException, JSONException, IOException, InterruptedException { super(config); pickaxes = new Pickaxes(this); + healths = new PlayerHealths(this); crafting = new Crafting(this); getCommandController().addCommand(crafting); @@ -68,6 +73,7 @@ public class Mineshaft extends CustomBot { getCommandController().addCommand(new PickaxeCommand(this)); getCommandController().addCommand(new Portal(this)); + getCommandController().addCommand(new SleepCommand(this)); mineCommand = new MineCommand(this); getCommandController().addCommand(mineCommand); @@ -154,36 +160,9 @@ public class Mineshaft extends CustomBot { }); getCommandController().addCommand(CommandDetails.from("cooldowns,cd"), (e, b, args) -> { - StringBuilder cooldowns = new StringBuilder(); - b.getCommandController().getCommands().entrySet().stream().map((x) -> x.getValue()) - .filter(c -> c instanceof CooldownCommand) - .map(c -> (CooldownCommand) c) - .sorted((c1, c2) -> { - return Long.compareUnsigned(c1.getCooldownController().getNextTime(e.getMember(), c1.getName()), - c2.getCooldownController().getNextTime(e.getMember(), c2.getName())); - }) - .forEach(c -> { - long nextCooldownTime = ((CooldownCommand) c).getCooldownController() - .getNextTime(e.getMember(), ((CooldownCommand) c).getName()); - if (nextCooldownTime == 0) - return; - String timeLeft = PeelingUtils.formatTimeRelative(nextCooldownTime); - - if (System.currentTimeMillis() > nextCooldownTime) { - return; - } + String cooldowns = getCooldownsString(e.getMember()); - cooldowns.append("**"); - cooldowns.append(((CooldownCommand) c).getName()); - cooldowns.append("**\t"); - cooldowns.append(timeLeft); - cooldowns.append("\n"); - }); - if (cooldowns.length() == 0) { - cooldowns.append("You have no active cooldowns"); - } - - b.sendMessage(e, "Active cooldowns", cooldowns.toString()); + b.sendMessage(e, "Active cooldowns", cooldowns); }); getCommandController().removeCommand("top"); @@ -198,6 +177,48 @@ public class Mineshaft extends CustomBot { logger = new FullLogger(this); } + public String getCooldownsString(Member member) { + return getCooldownsString(member, List.of()); + } + + public String getCooldownsString(Member member, List omit) { + StringBuilder cooldowns = new StringBuilder(); + getCommandController().getCommands().entrySet().stream().map((x) -> x.getValue()) + .filter(c -> c instanceof CooldownCommand) + .map(c -> (CooldownCommand) c) + .filter(c -> !omit.contains(c.getName())) + .sorted((c1, c2) -> { + return Long.compareUnsigned(c1.getCooldownController().getNextTime(member, c1.getName()), + c2.getCooldownController().getNextTime(member, c2.getName())); + }) + .forEach(c -> { + long nextCooldownTime = ((CooldownCommand) c).getCooldownController() + .getNextTime(member, ((CooldownCommand) c).getName()); + if (nextCooldownTime == 0) + return; + String timeLeft = PeelingUtils.formatTimeRelative(nextCooldownTime); + + if (System.currentTimeMillis() > nextCooldownTime) { + cooldowns.append("**"); + cooldowns.append(((CooldownCommand) c).getName()); + cooldowns.append("**\t\t"); + cooldowns.append(":white_check_mark:"); + cooldowns.append("\n"); + return; + } + + cooldowns.append("**"); + cooldowns.append(((CooldownCommand) c).getName()); + cooldowns.append("**\t\t"); + cooldowns.append(timeLeft); + cooldowns.append("\n"); + }); + if (cooldowns.length() == 0) { + cooldowns.append("You have no active cooldowns"); + } + return cooldowns.toString(); + } + public StarboardController getStarboardController() { return starboardController; } @@ -226,8 +247,8 @@ public class Mineshaft extends CustomBot { resourceManager.addResource(member, item.toString(), amount); } - public void addItems(Member member, Map items) { - resourceManager.addResources(member, items.entrySet().stream() + public long addItems(Member member, Map items) { + return resourceManager.addResources(member, items.entrySet().stream() .collect(Collectors.toMap( e -> e.getKey().toString(), Map.Entry::getValue @@ -251,8 +272,8 @@ public class Mineshaft extends CustomBot { resourceManager.addResource(member, getItem(item).getName(), -amount); } - public void removeItems(Member member, Map items) { - addItems(member, items.entrySet().stream().collect(Collectors.toMap( + public long removeItems(Member member, Map items) { + return addItems(member, items.entrySet().stream().collect(Collectors.toMap( Map.Entry::getKey, e -> -e.getValue() ))); @@ -330,4 +351,12 @@ public class Mineshaft extends CustomBot { public EnchantCommand getEnchantCommand() { return enchantCommand; } + + public PlayerHealths getHealths() { + return healths; + } + + public boolean isEmpty(Map items) { + return items.entrySet().stream().mapToLong(e -> e.getValue()).sum() == 0; + } } -- cgit v1.2.3