Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: resolve offline Sk1er API crashing the game #77

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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