From a61716710d41cc19cf3c6cb5725d9fd59be356b1 Mon Sep 17 00:00:00 2001 From: NK Date: Tue, 21 Feb 2023 09:04:32 +0000 Subject: [PATCH] check hub --- src/main/java/me/night0721/lilase/Main.java | 6 ----- .../me/night0721/lilase/config/AHConfig.java | 3 +++ .../lilase/features/ah/AuctionHouse.java | 26 +++++++++++-------- .../java/me/night0721/lilase/utils/Utils.java | 18 ++++++++----- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/night0721/lilase/Main.java b/src/main/java/me/night0721/lilase/Main.java index 4a0bb50..526437f 100644 --- a/src/main/java/me/night0721/lilase/Main.java +++ b/src/main/java/me/night0721/lilase/Main.java @@ -27,7 +27,6 @@ import org.lwjgl.input.Keyboard; import java.util.ArrayList; import java.util.Arrays; -import java.util.Objects; @Mod(modid = Main.MODID, name = Main.MOD_NAME, version = Main.VERSION, acceptedMinecraftVersions = "[1.8.9]") public class Main { @@ -83,11 +82,6 @@ public class Main { if (tickAmount % 20 == 0) { Utils.checkForDungeon(); - if (!Objects.equals(AHConfig.WEBHOOK, ConfigUtils.getString("main", "Webhook"))) { - ConfigUtils.writeStringConfig("main", "Webhook", AHConfig.WEBHOOK); - } else if (!Objects.equals(AHConfig.AUCTION_HOUSE_DELAY, ConfigUtils.getInt("main", "AuctionHouseDelay"))) { - ConfigUtils.writeIntConfig("main", "AuctionHouseDelay", Math.round(AHConfig.AUCTION_HOUSE_DELAY)); - } } AuctionHouse.switchStates(); } diff --git a/src/main/java/me/night0721/lilase/config/AHConfig.java b/src/main/java/me/night0721/lilase/config/AHConfig.java index 9696306..96118b6 100644 --- a/src/main/java/me/night0721/lilase/config/AHConfig.java +++ b/src/main/java/me/night0721/lilase/config/AHConfig.java @@ -7,11 +7,14 @@ import cc.polyfrost.oneconfig.config.annotations.Text; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.ModType; import me.night0721.lilase.gui.ConfigGUI; +import me.night0721.lilase.utils.ConfigUtils; public class AHConfig extends Config { public AHConfig() { super(new Mod("Lilase", ModType.UTIL_QOL), "lilase.json"); initialize(); + addListener("AUCTION_HOUSE_DELAY", () -> ConfigUtils.writeIntConfig("main", "AuctionHouseDelay", Math.round(AHConfig.AUCTION_HOUSE_DELAY))); + addListener("WEBHOOK", () -> ConfigUtils.writeStringConfig("main", "Webhook", AHConfig.WEBHOOK)); } @HUD(name = "Lilase") diff --git a/src/main/java/me/night0721/lilase/features/ah/AuctionHouse.java b/src/main/java/me/night0721/lilase/features/ah/AuctionHouse.java index e3f5ec9..06c2883 100644 --- a/src/main/java/me/night0721/lilase/features/ah/AuctionHouse.java +++ b/src/main/java/me/night0721/lilase/features/ah/AuctionHouse.java @@ -196,18 +196,22 @@ public class AuctionHouse { items.clear(); open = false; } else { - Utils.sendMessage("Started Auction House"); - thread = new Thread(() -> { - while (true) { - try { - getItem(); - thread.sleep(TimeUnit.SECONDS.toMillis(ConfigUtils.getInt("main", "AuctionHouseDelay"))); - } catch (IOException | JSONException | InterruptedException ignore) { + if (Utils.checkInHub()) { + Utils.sendMessage("Started Auction House"); + thread = new Thread(() -> { + while (true) { + try { + getItem(); + thread.sleep(TimeUnit.SECONDS.toMillis(ConfigUtils.getInt("main", "AuctionHouseDelay"))); + } catch (IOException | JSONException | InterruptedException ignore) { + } } - } - }); - thread.start(); - open = true; + }); + thread.start(); + open = true; + } else { + Utils.sendMessage("Detected not in hub, please go to hub to start"); + } } } public static void switchStates() { diff --git a/src/main/java/me/night0721/lilase/utils/Utils.java b/src/main/java/me/night0721/lilase/utils/Utils.java index 6ee5cd2..6c3175f 100644 --- a/src/main/java/me/night0721/lilase/utils/Utils.java +++ b/src/main/java/me/night0721/lilase/utils/Utils.java @@ -10,7 +10,6 @@ import java.util.List; public class Utils { public static boolean inDungeon; - public static boolean inHub; public static String translateAlternateColorCodes(String text) { char[] b = text.toCharArray(); @@ -43,16 +42,21 @@ public class Utils { inDungeon = false; } - public static void checkInHub() { + public static boolean checkInHub() { List scoreboard = ScoreboardUtils.getSidebarLines(); for (String s : scoreboard) { String sCleaned = ScoreboardUtils.cleanSB(s); - if (sCleaned.contains("Forest") || sCleaned.contains("Village") || sCleaned.contains("Farm") || sCleaned.contains("Mountain") || sCleaned.contains("Wilderness") || sCleaned.contains("Community Center") || sCleaned.contains("Graveyard")) { - inHub = true; - return; - } + return sCleaned.contains("Forest") || + sCleaned.contains("Village") || + sCleaned.contains("Farm") || + sCleaned.contains("Mountain") || + sCleaned.contains("Wilderness") || + sCleaned.contains("Community") || + sCleaned.contains("Graveyard") || + sCleaned.contains("Bazaar") || + sCleaned.contains("Auction"); } - inDungeon = true; + return false; } public static void sendMessage(String message) {