diff --git a/api/src/main/java/com/seibel/distanthorizons/api/enums/config/EDhApiUpdateBranch.java b/api/src/main/java/com/seibel/distanthorizons/api/enums/config/EDhApiUpdateBranch.java index dc94d28f7..6b149a666 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/enums/config/EDhApiUpdateBranch.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/enums/config/EDhApiUpdateBranch.java @@ -1,14 +1,41 @@ package com.seibel.distanthorizons.api.enums.config; +import com.seibel.distanthorizons.coreapi.ModInfo; + /** + * AUTO,
* STABLE,
* NIGHTLY,

* - * @since API 2.0.0 - * @version 2024-4-6 + * @since API 2.1.0 + * @version 2024-6-8 */ public enum EDhApiUpdateBranch { + AUTO, STABLE, - NIGHTLY + NIGHTLY; + + + + /** + * If the updateBranch value is {@link EDhApiUpdateBranch#AUTO} + * this method will convert it either to {@link EDhApiUpdateBranch#STABLE} or {@link EDhApiUpdateBranch#NIGHTLY} + * based on this jar's state.

+ * + * If updateBranch is {@link EDhApiUpdateBranch#STABLE} or {@link EDhApiUpdateBranch#NIGHTLY} + * it just returns. + */ + public static EDhApiUpdateBranch convertAutoToStableOrNightly(EDhApiUpdateBranch updateBranch) + { + if (updateBranch != EDhApiUpdateBranch.AUTO) + { + return updateBranch; + } + else + { + return ModInfo.IS_DEV_BUILD ? EDhApiUpdateBranch.NIGHTLY : EDhApiUpdateBranch.STABLE; + } + } + } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 827177ed6..2ccfd9824 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -1054,11 +1054,12 @@ public class Config .build(); public static ConfigEntry updateBranch = new ConfigEntry.Builder() - .set( - ModInfo.IS_DEV_BUILD? EDhApiUpdateBranch.NIGHTLY: EDhApiUpdateBranch.STABLE // If it's already a nightly build, then download the nightly build ofc - ) + .set(EDhApiUpdateBranch.AUTO) .comment("" - + " If DH should use the nightly (provided by Gitlab), or stable (provided by Modrinth) build") + + "If DH should use the nightly (provided by Gitlab), or stable (provided by Modrinth) build. \n" + + "If ["+EDhApiUpdateBranch.AUTO+"] is selected DH will update to new stable releases if the current jar is a stable jar \n" + + "and will update to new nightly builds if the current jar is a nightly jar (IE the version number ends in '-dev')." + + "") .build(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java index 16df88e2b..92a6940de 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java @@ -19,6 +19,7 @@ package com.seibel.distanthorizons.core.jar.updater; +import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.jar.JarUtils; @@ -83,15 +84,8 @@ public class SelfUpdater boolean returnValue = false; try { - switch (Config.Client.Advanced.AutoUpdater.updateBranch.get()) - { - case STABLE: - returnValue = onStableStart(); - break; - case NIGHTLY: - returnValue = onNightlyStart(); - break; - }; + EDhApiUpdateBranch updateBranch = EDhApiUpdateBranch.convertAutoToStableOrNightly(Config.Client.Advanced.AutoUpdater.updateBranch.get()); + returnValue = (updateBranch == EDhApiUpdateBranch.STABLE) ? onStableStart() : onNightlyStart(); } catch (Exception e) // Shouldn't be needed, but just in case { diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index d1ee62c9d..771e660dd 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -920,6 +920,8 @@ "Stable", "distanthorizons.config.enum.EDhApiUpdateBranch.NIGHTLY": "Nightly", + "distanthorizons.config.enum.EDhApiUpdateBranch.AUTO": + "Auto", "distanthorizons.config.enum.EDhApiGrassSideRendering.AS_GRASS": "As Grass",