From 5d5d1347644a798551100d22feddc92d4049cb59 Mon Sep 17 00:00:00 2001 From: olim88 Date: Fri, 24 May 2024 03:19:48 +0100 Subject: fix bugs + refactor (#719) fix crash when adding new rule after selecting last rule, let location input length be 96, add mineshaft location and stop grabing from api --- .../skyblocker/skyblock/chat/ChatRulesHandler.java | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java index d1c7f4fd..90a3b641 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java @@ -8,6 +8,7 @@ import com.mojang.serialization.JsonOps; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.mixins.accessors.MessageHandlerAccessor; import de.hysky.skyblocker.utils.Http; +import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.minecraft.client.MinecraftClient; @@ -33,20 +34,34 @@ public class ChatRulesHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ChatRule.class); private static final Path CHAT_RULE_FILE = SkyblockerMod.CONFIG_DIR.resolve("chat_rules.json"); private static final Codec>> MAP_CODEC = Codec.unboundedMap(Codec.STRING, ChatRule.LIST_CODEC); - /** - * look up table for the locations input by the users to raw locations - */ - protected static final HashMap locations = new HashMap<>(); /** * list of possible locations still formatted for the tool tip */ - protected static final List locationsList = new ArrayList<>(); + protected static final List locationsList = List.of ( + "The Farming Islands", + "Crystal Hollows", + "Jerry's Workshop", + "The Park", + "Dark Auction", + "Dungeons", + "The End", + "Crimson Isle", + "Hub", + "Kuudra's Hollow", + "Private Island", + "Dwarven Mines", + "The Garden", + "Gold Mine", + "Blazing Fortress", + "Deep Caverns", + "Spider's Den", + "Mineshaft" + ); protected static final List chatRuleList = new ArrayList<>(); public static void init() { CompletableFuture.runAsync(ChatRulesHandler::loadChatRules); - CompletableFuture.runAsync(ChatRulesHandler::loadLocations); ClientReceiveMessageEvents.ALLOW_GAME.register(ChatRulesHandler::checkMessage); } @@ -76,26 +91,6 @@ public class ChatRulesHandler { chatRuleList.add(miningAbilityRule); } - private static void loadLocations() { - try { - String response = Http.sendGetRequest("https://api.hypixel.net/v2/resources/games"); - JsonObject locationsJson = JsonParser.parseString(response).getAsJsonObject().get("games").getAsJsonObject().get("SKYBLOCK").getAsJsonObject().get("modeNames").getAsJsonObject(); - for (Map.Entry entry : locationsJson.entrySet()) { - //fix old naming todo remove when hypixel fix - if (Objects.equals(entry.getKey(), "instanced")) { - locationsList.add(entry.getValue().getAsString()); - locations.put(entry.getValue().getAsString().replace(" ", "").toLowerCase(), "kuudra"); - continue; - } - locationsList.add(entry.getValue().getAsString()); - //add to list in a simplified for so more lenient for user input - locations.put(entry.getValue().getAsString().replace(" ", "").toLowerCase(), entry.getKey()); - } - } catch (Exception e) { - LOGGER.error("[Skyblocker Chat Rules] Failed to load locations!", e); - } - } - protected static void saveChatRules() { JsonObject chatRuleJson = new JsonObject(); chatRuleJson.add("rules", ChatRule.LIST_CODEC.encodeStart(JsonOps.INSTANCE, chatRuleList).getOrThrow()); -- cgit