aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky
diff options
context:
space:
mode:
authorolim <bobq4582@gmail.com>2024-02-18 16:52:38 +0000
committerolim <bobq4582@gmail.com>2024-02-18 16:52:38 +0000
commit076522fa33965fce1345bbea8cb80f82645fc201 (patch)
treecb26563cabb64e131f191e6eee5f9733e5680448 /src/main/java/de/hysky
parent1aa1a1328f91f6cab39a958396a7eb854ad2ca13 (diff)
downloadSkyblocker-076522fa33965fce1345bbea8cb80f82645fc201.tar.gz
Skyblocker-076522fa33965fce1345bbea8cb80f82645fc201.tar.bz2
Skyblocker-076522fa33965fce1345bbea8cb80f82645fc201.zip
improve locations input
use actual locations names from the api for the input
Diffstat (limited to 'src/main/java/de/hysky')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java28
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java39
2 files changed, 50 insertions, 17 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
index 97431305..60a64fad 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
@@ -181,24 +181,26 @@ public class ChatRule {
}
String rawLocation = Utils.getLocationRaw();
Boolean isLocationValid = null;
- for (String validLocation : validLocations.replace(" ", "").split(",")) {//the locations are raw locations split by "," and start with ! if not locations
- if (validLocation.startsWith("!")) {//not location (
- if (Objects.equals(validLocation.substring(1), rawLocation)) {
- isLocationValid = false;
- break;
- }
- }else {
- if (Objects.equals(validLocation, rawLocation)) { //normal location
- isLocationValid = true;
- break;
- }
+ for (String validLocation : validLocations.replace(" ", "").toLowerCase().split(",")) {//the locations are raw locations split by "," and start with ! if not locations
+ String rawValidLocation = ChatRulesHandler.locations.get(validLocation.replace("!",""));
+ if (rawValidLocation == null) continue;
+ if (validLocation.startsWith("!")) {//not location
+ if (Objects.equals(rawValidLocation, rawLocation.toLowerCase())) {
+ isLocationValid = false;
+ break;
}
+ }
+ else {
+ if (Objects.equals(rawValidLocation, rawLocation.toLowerCase())) { //normal location
+ isLocationValid = true;
+ break;
+ }
+ }
}
- if (isLocationValid == null || isLocationValid){//if location is not in the list at all and is a not a "!" location or and is a normal location
+ if (isLocationValid != null && isLocationValid){//if location is not in the list at all and is a not a "!" location or and is a normal location
return true;
}
-
return false;
}
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 4afedc52..29faa856 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java
@@ -1,8 +1,11 @@
package de.hysky.skyblocker.skyblock.chat;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import de.hysky.skyblocker.SkyblockerMod;
+import de.hysky.skyblocker.utils.Http;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
@@ -20,19 +23,25 @@ import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class ChatRulesHandler {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final Logger LOGGER = LoggerFactory.getLogger(ChatRule.class);
private static final Path CHAT_RULE_FILE = SkyblockerMod.CONFIG_DIR.resolve("chat_rules.json");
-
+ /**
+ * 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<ChatRule> chatRuleList = new ArrayList<>();
public static void init() {
loadChatRules();
+ loadLocations();
ClientReceiveMessageEvents.ALLOW_GAME.register(ChatRulesHandler::checkMessage);
}
@@ -52,6 +61,28 @@ public class ChatRulesHandler {
}
}
+ 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] Failed to load locations!", e);
+ }
+ System.out.println(locations);
+ }
+
protected static void saveChatRules() {
JsonObject chatRuleJson = new JsonObject();
chatRuleJson.add("rules", SkyblockerMod.GSON.toJsonTree(chatRuleList));