-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from AdamCalculator/checker
Checker for 1.20.1
- Loading branch information
Showing
19 changed files
with
254 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
common/src/main/java/com/adamcalculator/dynamicpack/status/StatusChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.adamcalculator.dynamicpack.status; | ||
|
||
import com.adamcalculator.dynamicpack.Mod; | ||
import com.adamcalculator.dynamicpack.util.Out; | ||
import com.adamcalculator.dynamicpack.util.Urls; | ||
import org.json.JSONObject; | ||
|
||
public class StatusChecker { | ||
private static final String URL = "https://adamcalculator.github.io/DynamicPack/dynamicpack.status.v1.json"; | ||
|
||
|
||
private static boolean isUpdateAvailable = false; | ||
private static boolean isFormatActual = true; | ||
private static boolean isSafe = true; | ||
private static boolean isChecked = false; | ||
|
||
public static void check() throws Exception { | ||
Out.println("Checking status..."); | ||
String s = Urls.parseContent(URL, 1024 * 1024 * 128); | ||
JSONObject j = new JSONObject(s); | ||
JSONObject lat = j.getJSONObject("latest_version"); | ||
isUpdateAvailable = lat.getLong("build") > Mod.VERSION_BUILD; | ||
isSafe = lat.getLong("safe") <= Mod.VERSION_BUILD; | ||
isFormatActual = lat.getLong("format") <= Mod.VERSION_BUILD; | ||
|
||
isChecked = true; | ||
Out.println(String.format("Status checked! isSafe=%s, isFormatActual=%s, isUpdateAvailable=%s", isSafe, isFormatActual, isUpdateAvailable)); | ||
} | ||
|
||
public static boolean isBlockUpdating(String remoteType) { | ||
if (remoteType.equals("modrinth")) { | ||
return false; | ||
} | ||
return !isSafe(); | ||
} | ||
|
||
|
||
public static boolean isModUpdateAvailable() { | ||
return isUpdateAvailable; | ||
} | ||
|
||
public static boolean isSafe() { | ||
return isSafe; | ||
} | ||
|
||
public static boolean isFormatActual() { | ||
return isFormatActual; | ||
} | ||
|
||
public static boolean isChecked() { | ||
return isChecked; | ||
} | ||
} |
Oops, something went wrong.