3131import org .apache .commons .lang3 .StringUtils ;
3232import org .apache .http .HttpEntity ;
3333import org .apache .http .HttpResponse ;
34- import org .apache .http .client .HttpClient ;
3534import org .apache .http .client .methods .HttpGet ;
3635import org .apache .http .impl .client .CloseableHttpClient ;
3736import org .apache .http .impl .client .HttpClients ;
@@ -154,7 +153,7 @@ public void startAndConnect() {
154153 ICommandSender sender = Minecraft .getMinecraft ().thePlayer ;
155154
156155 if (!isRunning ()) {
157- if (!Metafile .areVersionsCompatible ("v" + Tags .VERSION , this .metafile .currentCompanionAppVersion )) {
156+ if (!Metafile .areVersionsCompatible (Tags .VERSION , this .metafile .currentCompanionAppVersion )) {
158157 this .metafile .loadNewestCompanionAppVersion ();
159158 } else {
160159 // If the current versions are compatible, it's fine if we download the new version after the next
@@ -305,9 +304,8 @@ private void downloadCompanionApp(String version) {
305304 .setChatStyle (new ChatStyle ().setColor (EnumChatFormatting .GRAY ))
306305 );
307306
308- HttpClient client = HttpClients .createDefault ();
309307 HttpResponse response ;
310- try {
308+ try ( CloseableHttpClient client = HttpClients . createDefault ()) {
311309 response = client .execute (new HttpGet ("https://github.com/Minecraft-TA/TotalDebugCompanion/releases/download/" + version + "/TotalDebugCompanion.zip" ));
312310 } catch (IOException e ) {
313311 TotalDebug .LOGGER .error ("Unable to reach github. Does this release exist? " + version , e );
@@ -508,15 +506,14 @@ private void loadNewestCompanionAppVersion() {
508506 byte [] responseData = outputStream .toByteArray ();
509507
510508 JsonArray jsonArray = GSON .fromJson (new String (responseData , StandardCharsets .UTF_8 ), JsonArray .class );
511- String totalDebugVersion = "v" + Tags .VERSION ;
512509
513- //find newest matching version
510+ // Find newest matching version
514511 for (int i = 0 ; i < jsonArray .size (); i ++) {
515512 JsonObject jsonObject = jsonArray .get (i ).getAsJsonObject ();
516513 String version = jsonObject .get ("tag_name" ).getAsString ();
517514
518- //don 't compare build number
519- if (areVersionsCompatible (totalDebugVersion , version )) {
515+ // Don 't compare build number
516+ if (areVersionsCompatible (Tags . VERSION , version )) {
520517 TotalDebug .LOGGER .info ("Found matching companion app version {}" , version );
521518 this .newestCompatibleCompanionAppVersion = version ;
522519 this .newestCompanionAppVersionSize = jsonObject .getAsJsonArray ("assets" ).get (0 )
@@ -525,7 +522,7 @@ private void loadNewestCompanionAppVersion() {
525522 }
526523 }
527524
528- //return newest version if no matching version was found
525+ // Return newest version if no matching version was found
529526 String newestVersion = jsonArray .get (0 ).getAsJsonObject ().get ("tag_name" ).getAsString ();
530527 TotalDebug .LOGGER .info ("No matching companion app version found. Falling back to newest available {}" , newestVersion );
531528 this .newestCompatibleCompanionAppVersion = newestVersion ;
@@ -538,11 +535,6 @@ private void loadNewestCompanionAppVersion() {
538535 }
539536
540537 private static boolean areVersionsCompatible (String totalDebugVersion , String companionAppVersion ) {
541- if (totalDebugVersion .startsWith ("v" ))
542- totalDebugVersion = totalDebugVersion .substring (1 );
543- if (companionAppVersion .startsWith ("v" ))
544- companionAppVersion = companionAppVersion .substring (1 );
545-
546538 String [] totalDebugVersionSplit = StringUtils .split (totalDebugVersion , '.' );
547539 String [] companionAppVersionSplit = StringUtils .split (companionAppVersion , '.' );
548540
0 commit comments