diff options
-rw-r--r-- | build.gradle | 40 | ||||
-rw-r--r-- | settings.gradle | 2 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java | 25 |
3 files changed, 59 insertions, 8 deletions
diff --git a/build.gradle b/build.gradle index 8870e0a..289b2bf 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,8 @@ plugins { id 'com.github.johnrengelman.shadow' version '6.1.0' id "net.minecraftforge.gradle.forge" version "ddb1eb0" + id "maven-publish" + id "signing" id "java" } @@ -34,4 +36,42 @@ shadowJar { archiveClassifier.set('') configurations = [project.configurations.include] duplicatesStrategy DuplicatesStrategy.EXCLUDE +} + +publishing { + publications { + maven(MavenPublication) { + groupId = "cc.polyfrost" + artifactId = archivesBaseName + "-1.8.9-forge" + + from(components["java"]) + } + } + + repositories { + maven { + name = "releases" + url = "https://repo.polyfrost.cc/releases" + credentials(PasswordCredentials) + authentication { + basic(BasicAuthentication) + } + } + maven { + name = "snapshots" + url = "https://repo.polyfrost.cc/snapshots" + credentials(PasswordCredentials) + authentication { + basic(BasicAuthentication) + } + } + maven { + name = "private" + url = "https://repo.polyfrost.cc/private" + credentials(PasswordCredentials) + authentication { + basic(BasicAuthentication) + } + } + } }
\ No newline at end of file diff --git a/settings.gradle b/settings.gradle index faf279e..6bdb83e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,4 @@ pluginManagement { } } -rootProject.name = "OneConfigLoader"
\ No newline at end of file +rootProject.name = "oneconfig-loader"
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java b/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java index 7806a67..4d03236 100644 --- a/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java +++ b/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java @@ -13,6 +13,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.security.MessageDigest; @@ -27,22 +28,31 @@ public class OneConfigLoader implements IFMLLoadingPlugin { public OneConfigLoader() { File oneConfigDir = new File(Launch.minecraftHome, "OneConfig"); + boolean update = true; + String channel = "release"; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(new File(oneConfigDir, "OneConfig.json").toPath()), StandardCharsets.UTF_8))) { + JsonObject config = new JsonParser().parse(reader).getAsJsonObject(); + update = config.get("autoUpdate").getAsBoolean(); + channel = config.get("updateChannel").getAsInt() == 0 ? "release" : "snapshot"; + } catch (Exception ignored) { + } + if (!oneConfigDir.exists() && !oneConfigDir.mkdir()) throw new IllegalStateException("Could not create OneConfig dir!"); File oneConfigFile = new File(oneConfigDir, "OneConfig (1.8.9).jar"); if (!isInitialized(oneConfigFile)) { - JsonElement json = getRequest("https://polyfrost.cc/static/oneconfig-versions.json"); + JsonElement json = update ? getRequest("https://api.polyfrost.cc/oneconfig/1.8.9-forge") : null; if (json != null && json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); - if (jsonObject.has("oneconfig") && jsonObject.getAsJsonObject("oneconfig").has("url") - && jsonObject.getAsJsonObject("oneconfig").has("checksum")) { + if (jsonObject.has(channel) && jsonObject.getAsJsonObject(channel).has("url") + && jsonObject.getAsJsonObject(channel).has("sha256")) { - String checksum = jsonObject.getAsJsonObject("oneconfig").get("checksum").getAsString(); - String downloadUrl = jsonObject.getAsJsonObject("oneconfig").get("url").getAsString(); + String checksum = jsonObject.getAsJsonObject(channel).get("sha256").getAsString(); + String downloadUrl = jsonObject.getAsJsonObject(channel).get("url").getAsString(); if (!oneConfigFile.exists() || !checksum.equals(getChecksum(oneConfigFile))) { System.out.println("Updating OneConfig..."); @@ -54,7 +64,8 @@ public class OneConfigLoader implements IFMLLoadingPlugin { try { Files.move(newOneConfigFile.toPath(), oneConfigFile.toPath(), StandardCopyOption.REPLACE_EXISTING); System.out.println("Updated OneConfig"); - } catch (IOException ignored) {} + } catch (IOException ignored) { + } } else { if (newOneConfigFile.exists()) newOneConfigFile.delete(); System.out.println("Failed to update OneConfig, trying to continue..."); @@ -67,7 +78,7 @@ public class OneConfigLoader implements IFMLLoadingPlugin { addToClasspath(oneConfigFile); } try { - OneConfigTransformer = ((IFMLLoadingPlugin) Launch.classLoader.findClass("cc.polyfrost.oneconfig.lwjgl.plugin.LoadingPlugin").newInstance()); + OneConfigTransformer = ((IFMLLoadingPlugin) Launch.classLoader.findClass("cc.polyfrost.oneconfig.internal.plugin.LoadingPlugin").newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } |