This repository was archived by the owner on Jan 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/main/java/com/cosmiiko/bsodod Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .cosmiiko .bsodod ;
2
+
3
+ import org .apache .commons .io .IOUtils ;
4
+ import java .io .IOException ;
5
+ import java .net .URL ;
6
+ import java .nio .charset .Charset ;
7
+ import java .util .regex .Matcher ;
8
+ import java .util .regex .Pattern ;
9
+
10
+ public class UpdateChecker {
11
+ static String GetLatestVersion () {
12
+ String gradleFile = null ;
13
+ try {
14
+ gradleFile = IOUtils .toString (
15
+ new URL ("https://raw.githubusercontent.com/Cosmiiko/MC-BSODOnDeath/main/build.gradle" ),
16
+ Charset .defaultCharset ()
17
+ );
18
+ } catch (IOException e ) {
19
+ return null ;
20
+ }
21
+
22
+ if (gradleFile == null ) return null ;
23
+
24
+ Pattern pattern = Pattern .compile ("version = '(.*)'" );
25
+ Matcher matcher = pattern .matcher (gradleFile );
26
+
27
+ if (matcher .find ())
28
+ {
29
+ return matcher .group (1 );
30
+ }
31
+ else
32
+ {
33
+ return null ;
34
+ }
35
+ }
36
+
37
+ static String GetCurrentVersion ()
38
+ {
39
+ return UpdateChecker .class .getPackage ().getImplementationVersion ();
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,25 @@ public void init()
31
31
textLines .add ("By clicking 'I understand', you acknowledge the risks involved in" );
32
32
textLines .add ("playing with such a mod." );
33
33
34
+ String latestVersion = UpdateChecker .GetLatestVersion ();
35
+ String currentVersion = UpdateChecker .GetCurrentVersion ();
36
+
37
+ if (latestVersion != null && currentVersion != null )
38
+ {
39
+ if (!latestVersion .equals (currentVersion ))
40
+ {
41
+ textLines .add (TextFormatting .RED + "Your mod version is outdated (v" + currentVersion + ", latest is v" + latestVersion + ")." );
42
+ textLines .add (TextFormatting .RED + "This version may contain bugs or accidental blue screens." );
43
+ }
44
+ else
45
+ {
46
+ textLines .add (TextFormatting .GREEN + "Your mod version is up-to-date." );
47
+ }
48
+ }
49
+ else
50
+ {
51
+ textLines .add (TextFormatting .GOLD + "Could not check for updates. Proceed with caution." );
52
+ }
34
53
35
54
textVOffset = this .height /2 - (textLines .size ()*LINESIZE + WARNINGSIZE )/2 ;
36
55
You can’t perform that action at this time.
0 commit comments