diff options
author | olim88 <bobq4582@gmail.com> | 2024-05-24 03:19:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-23 22:19:48 -0400 |
commit | 5d5d1347644a798551100d22feddc92d4049cb59 (patch) | |
tree | a3bc76cc1bcd58dc31c2c633a30f98357f7a26b9 /src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java | |
parent | 813df61af0b38371efa38c817fe6d406a37a3317 (diff) | |
download | Skyblocker-5d5d1347644a798551100d22feddc92d4049cb59.tar.gz Skyblocker-5d5d1347644a798551100d22feddc92d4049cb59.tar.bz2 Skyblocker-5d5d1347644a798551100d22feddc92d4049cb59.zip |
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
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java | 47 |
1 files changed, 21 insertions, 26 deletions
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; @@ -34,19 +35,33 @@ public class ChatRulesHandler { private static final Path CHAT_RULE_FILE = SkyblockerMod.CONFIG_DIR.resolve("chat_rules.json"); private static final Codec<Map<String, List<ChatRule>>> 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<String, String> locations = new HashMap<>(); - /** * list of possible locations still formatted for the tool tip */ - protected static final List<String> locationsList = new ArrayList<>(); + protected static final List<String> 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<ChatRule> 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<String, JsonElement> 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()); |