diff options
author | syeyoung <cyoung06@naver.com> | 2023-02-27 01:53:35 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-02-27 01:53:35 +0900 |
commit | 38e7c947fdc412d34babbdd54c5b66af3e844ae9 (patch) | |
tree | b16386e6363c9d6e99d1cf828b4c354be83fd45b /mod/src/main/java/kr/syeyoung | |
parent | 9102eba6e32babb8d20cc92d4a6c9d1e0979c882 (diff) | |
download | Skyblock-Dungeons-Guide-38e7c947fdc412d34babbdd54c5b66af3e844ae9.tar.gz Skyblock-Dungeons-Guide-38e7c947fdc412d34babbdd54c5b66af3e844ae9.tar.bz2 Skyblock-Dungeons-Guide-38e7c947fdc412d34babbdd54c5b66af3e844ae9.zip |
- Disable autoupdate button if remote branch is not available
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rw-r--r-- | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java | 15 | ||||
-rw-r--r-- | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java index f0c30c7b..37b6c212 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java @@ -36,6 +36,7 @@ import org.apache.logging.log4j.Logger; import javax.swing.*; import java.io.IOException; +import java.util.List; import java.util.Optional; import java.util.Properties; @@ -82,13 +83,14 @@ public class VersionInfo { Scaler scaler = new Scaler(); scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); scaler.child.setValue(new WidgetUpdateLog( - latestUpdate.getName(), latestUpdate.getUpdateLog() + latestUpdate.getName(), latestUpdate.getUpdateLog(), true )); GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); logger.info("Update Required!!"); } else if (VersionInfo.getCurrentLoader() instanceof JarLoader || VersionInfo.getCurrentLoader() instanceof LocalLoader) { - UpdateBranch requiredUpdateBranch = UpdateRetrieverUtil.getUpdateBranches().stream().filter(a -> + List<UpdateBranch> availableBranches = UpdateRetrieverUtil.getUpdateBranches(); + UpdateBranch requiredUpdateBranch = availableBranches.stream().filter(a -> Optional.ofNullable(a.getMetadata()) .filter(b -> b.has("additionalMeta")) .map(b -> b.getJSONObject("additionalMeta")) @@ -96,6 +98,13 @@ public class VersionInfo { .map(b -> b.getString("type")) .filter(b -> b.equals("update-alarm-github")) .isPresent()).findFirst().orElse(null); + boolean autoupdate = availableBranches.stream().anyMatch(a -> + Optional.ofNullable(a.getMetadata()) + .filter(b -> b.has("additionalMeta")) + .map(b -> b.getJSONObject("additionalMeta")) + .filter(b -> b.has("type")) + .map(b -> b.getString("type")) + .filter(b -> b.equals("mod")).isPresent()); if (requiredUpdateBranch == null) { logger.error("No update branch found: ???"); return; @@ -117,7 +126,7 @@ public class VersionInfo { Scaler scaler = new Scaler(); scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); scaler.child.setValue(new WidgetUpdateLog( - latestUpdate.getName(), latestUpdate.getUpdateLog() + latestUpdate.getName(), latestUpdate.getUpdateLog(), autoupdate )); GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); } else { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java index cb7903e3..1345a140 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java @@ -32,10 +32,14 @@ public class WidgetUpdateLog extends AnnotatedImportOnlyWidget { @Bind(variableName = "version") public final BindableAttribute<String> version = new BindableAttribute<>(String.class); - public WidgetUpdateLog(String version, String updateLog) { + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> disabled = new BindableAttribute<>(Boolean.class, false); + + public WidgetUpdateLog(String version, String updateLog, boolean autoupdate) { super(new ResourceLocation("dungeonsguide:gui/update.gui")); this.version.setValue(version); this.updateLog.setValue(updateLog); + this.disabled.setValue(!autoupdate); } @On(functionName = "continue") |