File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed
src/main/java/com/xxmicloxx/NoteBlockAPI Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11package com .xxmicloxx .NoteBlockAPI ;
22
3+ import java .io .IOException ;
34import java .util .ArrayList ;
45import java .util .Collections ;
56import java .util .HashMap ;
1516import org .bukkit .scheduler .BukkitRunnable ;
1617
1718import com .xxmicloxx .NoteBlockAPI .songplayer .SongPlayer ;
19+ import com .xxmicloxx .NoteBlockAPI .utils .Updater ;
1820
1921/**
2022 * Main class; contains methods for playing and adjusting songs for players
@@ -110,7 +112,7 @@ public void onEnable() {
110112
111113 new NoteBlockPlayerMain ().onEnable ();
112114
113- getServer ().getScheduler ().runTaskLater (this , new BukkitRunnable () {
115+ getServer ().getScheduler ().runTaskLater (this , new Runnable () {
114116
115117 @ Override
116118 public void run () {
@@ -128,6 +130,21 @@ public void run() {
128130 }
129131 }
130132 }, 20 *60 );
133+
134+ getServer ().getScheduler ().runTaskLater (this , new Runnable () {
135+
136+ @ Override
137+ public void run () {
138+ try {
139+ if (Updater .checkUpdate ("19287" , getDescription ().getVersion ())){
140+ Bukkit .getLogger ().info (String .format ("[%s] New update available!" , plugin .getDescription ().getName ()));
141+ }
142+ } catch (IOException e ) {
143+ Bukkit .getLogger ().info (String .format ("[%s] Cannot receive update from Spigot resource page!" , plugin .getDescription ().getName ()));
144+ }
145+ }
146+ }, 20 *10 );
147+
131148 }
132149
133150 @ Override
Original file line number Diff line number Diff line change 1+ package com .xxmicloxx .NoteBlockAPI .utils ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ import java .net .MalformedURLException ;
7+ import java .net .URL ;
8+ import java .net .URLConnection ;
9+
10+ public class Updater {
11+
12+ public static boolean checkUpdate (String resource , String actualVersion ) throws MalformedURLException , IOException {
13+ Float version = getVersionNumber (actualVersion );
14+
15+ URLConnection con = new URL ("https://api.spigotmc.org/legacy/update.php?resource=" + resource ).openConnection ();
16+ String newVersionString = new BufferedReader (new InputStreamReader (con .getInputStream ())).readLine ();
17+ int first = newVersionString .indexOf ("(" );
18+ String newVersion = newVersionString .substring (0 , first );
19+
20+ Float newVer = getVersionNumber (newVersion );
21+
22+ return newVer > version ;
23+ }
24+
25+ private static Float getVersionNumber (String version ){
26+ String [] versionParts = version .split ("\\ ." );
27+ String versionString = "0." ;
28+
29+ for (String vpart : versionParts ){
30+ if (vpart .length () < 2 ){
31+ versionString += "0" ;
32+ }
33+ versionString += vpart ;
34+ }
35+
36+ return Float .parseFloat (versionString );
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments