-
-
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.
- Loading branch information
1 parent
5fafb20
commit cdc98d3
Showing
3 changed files
with
94 additions
and
5 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
50 changes: 50 additions & 0 deletions
50
SyncCommands-common/src/main/java/io/github/efekurbann/synccommands/util/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,50 @@ | ||
package io.github.efekurbann.synccommands.util; | ||
|
||
import io.github.efekurbann.synccommands.scheduler.Scheduler; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.util.logging.Logger; | ||
|
||
public class UpdateChecker { | ||
|
||
private static final String RESOURCE_ID = "99596"; | ||
private static final String URL = "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID; | ||
|
||
private final Logger logger; | ||
private final Scheduler scheduler; | ||
private final String version; | ||
private boolean upToDate; | ||
|
||
public UpdateChecker(String version, Logger logger, Scheduler scheduler) { | ||
this.logger = logger; | ||
this.scheduler = scheduler; | ||
this.version = version; | ||
} | ||
|
||
public void checkUpdates() { | ||
this.scheduler.runAsync(()-> { | ||
try { | ||
HttpsURLConnection con = (HttpsURLConnection) new URL(URL).openConnection(); | ||
InputStreamReader reader = new InputStreamReader(con.getInputStream()); | ||
String latestVersion = (new BufferedReader(reader)).readLine(); | ||
this.upToDate = latestVersion.equals(version); | ||
|
||
if (!this.upToDate) { | ||
logger.info("An update was found for SyncCommands!"); | ||
logger.info("Download from: https://www.spigotmc.org/resources/" + RESOURCE_ID); | ||
} else | ||
logger.info("Plugin is up to date, no update found."); | ||
} catch (IOException exception) { | ||
this.logger.info("Could not check for updates: " + exception.getMessage()); | ||
} | ||
}); | ||
} | ||
|
||
public boolean isUpToDate() { | ||
return upToDate; | ||
} | ||
} |
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