-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from BT-Pluginz/1.5
1.5
- Loading branch information
Showing
9 changed files
with
178 additions
and
24 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
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 |
---|---|---|
|
@@ -17,21 +17,20 @@ | |
* Class responsible for checking if a new version of the plugin is available. | ||
*/ | ||
public class VersionChecker { | ||
private static final String project = "km0yAITg"; | ||
public VersionChecker(){} | ||
|
||
/** | ||
* Checks if a new version of the plugin is available. | ||
* @param version The current version of the plugin. | ||
* @return A boolean indicating whether a new version is available. | ||
*/ | ||
public static boolean isNewVersionAvailable(String version) { | ||
public static VersionInfo isNewVersionAvailable(String version, String project) { | ||
try { | ||
URL url = new URL("https://api.modrinth.com/v2/project/" + project + "/version"); | ||
|
||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
|
||
connection.setRequestProperty("User-Agent", "TubYoub/StatusPlugin/"+ version +" ([email protected])"); | ||
connection.setRequestProperty("User-Agent", "BTPluginz/TubsStatusPlugin/"+ version + " ([email protected])"); | ||
|
||
int responseCode = connection.getResponseCode(); | ||
if (responseCode == HttpURLConnection.HTTP_OK) { | ||
|
@@ -40,21 +39,62 @@ public static boolean isNewVersionAvailable(String version) { | |
|
||
List<Map<String, Object>> versions = parseJsonArray(jsonResponse); | ||
if (!versions.isEmpty()) { | ||
String latestVersion = (String) versions.get(0).get("version_number"); | ||
Map<String, Object> latestVersion = versions.get(0); | ||
String latestVersionNumber = (String) latestVersion.get("version_number"); | ||
String changelog = (String) latestVersion.get("changelog"); | ||
String versionType = (String) latestVersion.get("version_type"); | ||
|
||
String currentVersion = version; | ||
return !latestVersion.equals(currentVersion); | ||
} else { | ||
return false; | ||
if (!latestVersionNumber.equals(version)) { | ||
UpdateUrgency urgency = determineUrgency(changelog, versionType); | ||
return new VersionInfo(true, latestVersionNumber, changelog, urgency); | ||
} else { | ||
return new VersionInfo(false, version, null, UpdateUrgency.NONE); | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
return new VersionInfo(false, version, null, UpdateUrgency.NONE); | ||
} | ||
|
||
private static UpdateUrgency determineUrgency(String changelog, String versionType) { | ||
if (versionType.equals("release")) { | ||
if (changelog.toLowerCase().contains("security") || changelog.toLowerCase().contains("critical")) { | ||
return UpdateUrgency.CRITICAL; | ||
} else if (changelog.toLowerCase().contains("important") || changelog.toLowerCase().contains("major")) { | ||
return UpdateUrgency.HIGH; | ||
} else { | ||
return UpdateUrgency.NORMAL; | ||
} | ||
} else if (versionType.equals("beta")) { | ||
return UpdateUrgency.LOW; | ||
} else { | ||
return UpdateUrgency.NONE; | ||
} | ||
} | ||
|
||
public static class VersionInfo { | ||
public final boolean isNewVersionAvailable; | ||
public final String latestVersion; | ||
public final String changelog; | ||
public final UpdateUrgency urgency; | ||
|
||
public VersionInfo(boolean isNewVersionAvailable, String latestVersion, String changelog, UpdateUrgency urgency) { | ||
this.isNewVersionAvailable = isNewVersionAvailable; | ||
this.latestVersion = latestVersion; | ||
this.changelog = changelog; | ||
this.urgency = urgency; | ||
} | ||
} | ||
|
||
public enum UpdateUrgency { | ||
CRITICAL, | ||
HIGH, | ||
NORMAL, | ||
LOW, | ||
NONE | ||
} | ||
|
||
/** | ||
|
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