Skip to content

Commit

Permalink
1.2.0-beta.2
Browse files Browse the repository at this point in the history
Work around JsDelivr caching
  • Loading branch information
Wyvest committed Jul 25, 2024
1 parent 82aa3eb commit 9f4a3d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_id=skyclientcosmetics
mod_name=SkyClientCosmetics
mod_version=1.2.0-beta.1
mod_version=1.2.0-beta.2
mod_archives_name=SkyClientCosmetics

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/co/skyclient/scc/cosmetics/TagCosmetics.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import co.skyclient.scc.utils.Files;
import co.skyclient.scc.utils.JsDelivrUtils;
import com.google.gson.*;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void initialize() {
Multithreading.runAsync(() -> {
try {
try {
rawData = new JsonParser().parse(Objects.requireNonNull(NetworkUtils.getString("https://cdn.jsdelivr.net/gh/SkyblockClient/Website@main/docs/assets/tags.json")).replace('&', ChatColor.COLOR_CHAR)).getAsJsonObject();
rawData = new JsonParser().parse(Objects.requireNonNull(NetworkUtils.getString(JsDelivrUtils.getWebsiteUrl("/docs/assets/tags.json"))).replace('&', ChatColor.COLOR_CHAR)).getAsJsonObject();
Multithreading.runAsync(() -> {
try {
FileUtils.writeStringToFile(cacheFile, GSON.toJson(rawData), StandardCharsets.UTF_8);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/co/skyclient/scc/gui/CustomSplashProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import co.skyclient.scc.utils.JsDelivrUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.texture.TextureManager;
Expand Down Expand Up @@ -186,7 +187,7 @@ public void printStackTrace(final PrintStream s) {

Multithreading.runAsync(() -> {
try {
String text = NetworkUtils.getString("https://cdn.jsdelivr.net/gh/SkyblockClient/Website@main/docs/assets/funfacts.txt");
String text = NetworkUtils.getString(JsDelivrUtils.getWebsiteUrl("/docs/assets/funfacts.txt"));
if (text != null) {
String[] lines = text.split("\n");
int index = (int) (Math.random() * lines.length);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/co/skyclient/scc/mixins/MinecraftMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import co.skyclient.scc.config.Settings;
import co.skyclient.scc.gui.SkyClientMainMenu;
import co.skyclient.scc.utils.IconLoader;
import co.skyclient.scc.utils.JsDelivrUtils;
import co.skyclient.scc.utils.MixinHook;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
Expand All @@ -24,6 +25,11 @@ public abstract class MinecraftMixin {
@Shadow
public abstract void displayGuiScreen(GuiScreen guiScreenIn);

@Inject(method = "startGame", at = @At("HEAD"))
private void onStartGame(CallbackInfo ci) {
JsDelivrUtils.initialize();
}

@Inject(method = "displayGuiScreen", at = @At("HEAD"), cancellable = true)
private void onDisplayScreen(GuiScreen i, CallbackInfo ci) {
if (Settings.customMainMenu && SkyclientCosmetics.config.enabled) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/co/skyclient/scc/utils/JsDelivrUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package co.skyclient.scc.utils;

import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import com.google.gson.JsonArray;

public class JsDelivrUtils {
private static String dataCommitId = "main";
private static String websiteCommitId = "main";

public static String getWebsiteUrl(String path) {
return "https://cdn.jsdelivr.net/gh/SkyblockClient/Website@" + websiteCommitId + path;
}

public static String getDataUrl(String path) {
return "https://cdn.jsdelivr.net/gh/SkyblockClient/SkyblockClient-REPO@" + dataCommitId + path;
}

public static void initialize() {
Multithreading.runAsync(() -> {
try {
JsonArray websiteApi = NetworkUtils.getJsonElement("https://api.github.com/repos/SkyblockClient/Website/commits").getAsJsonArray();
websiteCommitId = websiteApi.get(0).getAsJsonObject().get("sha").getAsString();
} catch (Exception e) {
e.printStackTrace();
}
try {
JsonArray dataApi = NetworkUtils.getJsonElement("https://api.github.com/repos/SkyblockClient/SkyblockClient-REPO/commits").getAsJsonArray();
dataCommitId = dataApi.get(0).getAsJsonObject().get("sha").getAsString();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/co/skyclient/scc/gui/greeting/ImportSlide.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import cc.polyfrost.oneconfig.utils.NetworkUtils
import co.skyclient.scc.gui.greeting.components.ButtonComponent
import co.skyclient.scc.gui.greeting.components.CorrectOutsidePixelConstraint
import co.skyclient.scc.gui.greeting.components.GreetingSlide
import com.google.gson.JsonParser
import co.skyclient.scc.utils.JsDelivrUtils
import net.minecraft.client.Minecraft
import net.minecraft.launchwrapper.Launch
import java.awt.Color
Expand Down Expand Up @@ -70,7 +70,7 @@ class ImportSlide : GreetingSlide<OptimizationSlide>(OptimizationSlide::class.ja
progressText.setText("Downloading config locations...")
val configLocations = arrayListOf<String>()
try {
NetworkUtils.getJsonElement("https://cdn.jsdelivr.net/gh/SkyblockClient/SkyblockClient-REPO@main/files/config_locations.json").asJsonArray.forEach {
NetworkUtils.getJsonElement(JsDelivrUtils.getDataUrl("/files/config_locations.json")).asJsonArray.forEach {
configLocations.add(it.asString)
}
} catch (e: Exception) {
Expand Down

0 comments on commit 9f4a3d6

Please sign in to comment.