22
33import me .nik .combatplus .CombatPlus ;
44import me .nik .combatplus .utils .ChatUtils ;
5+ import org .bukkit .Bukkit ;
56import org .bukkit .event .EventHandler ;
67import org .bukkit .event .Listener ;
78import org .bukkit .event .player .PlayerJoinEvent ;
@@ -25,37 +26,39 @@ public UpdateChecker(CombatPlus plugin) {
2526
2627 @ Override
2728 public void run () {
29+
2830 try {
29- newVersion = readLines ();
31+
32+ URLConnection connection = new URL ("https://raw.githubusercontent.com/NikV2/CombatPlus/master/version.txt" ).openConnection ();
33+
34+ connection .addRequestProperty ("User-Agent" , "Mozilla/4.0" );
35+
36+ BufferedReader reader = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
37+
38+ final String line = reader .readLine ();
39+
40+ reader .close ();
41+
42+ this .newVersion = line ;
43+
3044 } catch (IOException e ) {
3145 plugin .getLogger ().warning ("Couldn't check for updates, Is the server connected to the internet?" );
3246 return ;
3347 }
3448
3549 if (!plugin .getDescription ().getVersion ().equals (newVersion )) {
36- ChatUtils .consoleMessage (MsgType .UPDATE_REMINDER .getMessage ().replaceAll ("%current%" , plugin .getDescription ().getVersion ()).replaceAll ("%new%" , newVersion ));
37- plugin .getServer ().getPluginManager ().registerEvents (this , plugin );
38- } else {
39- ChatUtils .consoleMessage (MsgType .CONSOLE_UPDATE_NOT_FOUND .getMessage ());
40- }
41- }
42-
43- private String readLines () throws IOException {
44- URLConnection connection = new URL ("https://raw.githubusercontent.com/NikV2/CombatPlus/master/version.txt" ).openConnection ();
45- connection .addRequestProperty ("User-Agent" , "Mozilla/4.0" );
46-
47- BufferedReader reader = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
50+ ChatUtils .consoleMessage (MsgType .UPDATE_REMINDER .getMessage ()
51+ .replace ("%current%" , plugin .getDescription ().getVersion ())
52+ .replace ("%new%" , newVersion ));
4853
49- final String line = reader .readLine ();
50-
51- reader .close ();
52-
53- return line ;
54+ Bukkit .getPluginManager ().registerEvents (this , plugin );
55+ } else ChatUtils .consoleMessage (MsgType .CONSOLE_UPDATE_NOT_FOUND .getMessage ());
5456 }
5557
5658 @ EventHandler
5759 public void onJoin (final PlayerJoinEvent e ) {
5860 if (!e .getPlayer ().hasPermission (Permissions .ADMIN .getPermission ())) return ;
61+
5962 e .getPlayer ().sendMessage (MsgType .UPDATE_REMINDER .getMessage ()
6063 .replace ("%current%" , plugin .getDescription ().getVersion ())
6164 .replace ("%new%" , newVersion ));
0 commit comments