Skip to content

Commit

Permalink
hotfix: resolve offline Sk1er API crashing the game (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
xthe-dev authored May 9, 2023
1 parent a6a47f8 commit 96323e8
Showing 1 changed file with 1 addition and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public class LanguageHandler {

private final Gson gson = new GsonBuilder().create();
private final LanguageData fallback = new LanguageData();
private final Map<String, String> languageMappings = new HashMap<String, String>() {{
put("ENGLISH", "en");
put("FRENCH", "fr");
}};

private JsonObject regex = null;

Expand All @@ -55,19 +51,9 @@ public LanguageHandler() {

private void initialize() {
fallback.initialize();
final String username = Minecraft.getMinecraft().getSession().getUsername();
final JsonObject json = NetworkUtils.getJsonElement("https://api.sk1er.club/player/" + username).getAsJsonObject();
final JsonObject player = json.getAsJsonObject("player");
String userLanguage;
if (player.has("userLanguage")) {
userLanguage = player.get("userLanguage").getAsString();
} else {
userLanguage = "ENGLISH";
}
final String language = languageMappings.getOrDefault(userLanguage, "en");
regex = NetworkUtils.getJsonElement("https://data.woverflow.cc/regex.json").getAsJsonObject();
if (!regex.entrySet().isEmpty()) {
current = gson.fromJson(regex.has(language) ? regex.getAsJsonObject(language).toString() : regex.getAsJsonObject("en").toString(), LanguageData.class);
current = gson.fromJson(regex.getAsJsonObject("en").toString(), LanguageData.class);
}
current.initialize();
}
Expand Down

0 comments on commit 96323e8

Please sign in to comment.