-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compat with BMFloodgate + bStats & UpdateChecker
- Loading branch information
1 parent
e7d2c1d
commit ef3f21c
Showing
4 changed files
with
79 additions
and
3 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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/technicjelle/bluemapcustomskinprovider/UpdateChecker.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,54 @@ | ||
//TechnicJelle's GitHub Update Checker v1 | ||
package com.technicjelle.bluemapcustomskinprovider; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.logging.Logger; | ||
|
||
@SuppressWarnings("SameParameterValue") | ||
public class UpdateChecker { | ||
private static boolean updateAvailable = false; | ||
private static URL url = null; | ||
private static String latestVersion = null; | ||
private static String curVer = null; | ||
|
||
|
||
static void check(String author, String name, String currentVersion) { | ||
curVer = currentVersion; | ||
new Thread(() -> { | ||
try { | ||
url = new URL("https://github.com/"+author+"/"+name+"/releases/latest"); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
HttpURLConnection con; | ||
try { | ||
con = (HttpURLConnection) url.openConnection(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
con.setInstanceFollowRedirects(false); | ||
|
||
String newUrl = con.getHeaderField("Location"); | ||
|
||
if(newUrl == null) { | ||
throw new RuntimeException("Did not get a redirect"); | ||
} | ||
|
||
String[] split = newUrl.split("/"); | ||
latestVersion = split[split.length - 1].replace("v", ""); | ||
|
||
if (!latestVersion.equals(curVer)) updateAvailable = true; | ||
}, name + "-Update-Checker").start(); | ||
} | ||
|
||
static void logUpdateMessage(Logger logger) { | ||
if (updateAvailable) { | ||
logger.warning("New version available: v" + latestVersion + " (current: v" + curVer + ")"); | ||
logger.warning("Download it at " + url); | ||
} | ||
} | ||
} |
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