Skip to content

Commit 1719b62

Browse files
committed
Added CevAPI Release Version Check
1 parent 5274d5b commit 1719b62

7 files changed

Lines changed: 177 additions & 16 deletions

File tree

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,18 @@ tasks.register("generateBuildConfig") {
180180
def template =
181181
file("src/main/templates/net/wurstclient/config/BuildConfig.java.in")
182182
def modVersionValue = project.mod_version
183+
def forkReleaseVersion =
184+
(project.findProperty("fork_release_version") ?: "0.0").toString()
185+
def ghRepoId = project.gh_repo_id.toString()
186+
def ghRepoUrl = "https://github.com/${ghRepoId}"
187+
def buildDate = java.time.Instant.now().toString()
183188

184189
inputs.file(template)
185190
inputs.property("niceWurstEnabled", niceWurstEnabled)
191+
inputs.property("forkReleaseVersion", forkReleaseVersion)
192+
inputs.property("ghRepoId", ghRepoId)
193+
inputs.property("ghRepoUrl", ghRepoUrl)
194+
inputs.property("buildDate", buildDate)
186195
outputs.dir(buildConfigOutput)
187196

188197
doLast {
@@ -194,6 +203,10 @@ tasks.register("generateBuildConfig") {
194203
def content = template.getText("UTF-8")
195204
.replace('${NICE_WURST}', String.valueOf(niceWurstEnabled))
196205
.replace('${MOD_VERSION}', modVersionValue)
206+
.replace('${FORK_RELEASE_VERSION}', forkReleaseVersion)
207+
.replace('${BUILD_DATE}', buildDate)
208+
.replace('${GH_REPO_ID}', ghRepoId)
209+
.replace('${GH_REPO_URL}', ghRepoUrl)
197210

198211
def targetFile = new File(targetDir, "BuildConfig.java")
199212
targetFile.setText(content, "UTF-8")

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fabric_api_version=0.140.2+1.21.11
1616

1717
# Mod Properties
1818
mod_version=v7.51.4-CevAPI-MC1.21.11
19+
fork_release_version=0.41
1920
maven_group=net.wurstclient
2021
archives_base_name=Wurst-Client
2122
mod_loader=Fabric

src/main/java/net/wurstclient/WurstClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import net.wurstclient.presets.PresetManager;
4141
import net.wurstclient.settings.SettingsFile;
4242
import net.wurstclient.update.ProblematicResourcePackDetector;
43+
import net.wurstclient.update.ForkUpdateChecker;
4344
import net.wurstclient.update.WurstUpdater;
4445
import net.wurstclient.util.PlayerRangeAlertManager;
4546
import net.wurstclient.util.SetbackDetector;
@@ -85,6 +86,7 @@ public enum WurstClient
8586
private boolean enabled = true;
8687
private static boolean guiInitialized;
8788
private WurstUpdater updater;
89+
private ForkUpdateChecker forkUpdateChecker;
8890
private ProblematicResourcePackDetector problematicPackDetector;
8991
private Path wurstFolder;
9092

@@ -167,6 +169,9 @@ public void initialize()
167169
updater = new WurstUpdater();
168170
eventManager.add(UpdateListener.class, updater);
169171

172+
forkUpdateChecker = new ForkUpdateChecker();
173+
eventManager.add(UpdateListener.class, forkUpdateChecker);
174+
170175
problematicPackDetector = new ProblematicResourcePackDetector();
171176
problematicPackDetector.start();
172177

@@ -392,6 +397,11 @@ public WurstUpdater getUpdater()
392397
return updater;
393398
}
394399

400+
public ForkUpdateChecker getForkUpdateChecker()
401+
{
402+
return forkUpdateChecker;
403+
}
404+
395405
public ProblematicResourcePackDetector getProblematicPackDetector()
396406
{
397407
return problematicPackDetector;

src/main/java/net/wurstclient/hacks/SpearAssistHack.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ public void update()
220220
private int spearKillFlushCooldown;
221221
private AssistMode lastAssistMode;
222222

223-
public SpearAssistHack()
224-
{
225-
super("SpearAssist");
226-
setCategory(Category.COMBAT);
223+
public SpearAssistHack()
224+
{
225+
super("SpearAssist");
226+
setCategory(Category.COMBAT);
227227
addSetting(assistMode);
228228
addSetting(boostMode);
229229
addSetting(boostSpeed);
@@ -257,17 +257,16 @@ public SpearAssistHack()
257257
addSetting(spearKillLungeDelayModifier);
258258
addSetting(spearKillChatFeedback);
259259

260-
spearKillTargetEntities.clear();
261-
updateModeVisibility();
262-
}
263-
264-
@Override
265-
public String getRenderName()
266-
{
267-
return assistMode.getSelected() == AssistMode.SPEARKILL
268-
? getName() + " [Kill]"
269-
: getName();
270-
}
260+
spearKillTargetEntities.clear();
261+
updateModeVisibility();
262+
}
263+
264+
@Override
265+
public String getRenderName()
266+
{
267+
return assistMode.getSelected() == AssistMode.SPEARKILL
268+
? getName() + " [Kill]" : getName();
269+
}
271270

272271
@Override
273272
protected void onEnable()

src/main/java/net/wurstclient/mixin/TitleScreenMixin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ private void onAddNormalWidgets(int y, int spacingY,
8080
@Inject(at = @At("RETURN"), method = "tick()V")
8181
private void onTick(CallbackInfo ci)
8282
{
83+
if(WurstClient.INSTANCE.getForkUpdateChecker() != null)
84+
WurstClient.INSTANCE.getForkUpdateChecker().startIfNeeded();
85+
8386
if(realmsButton == null || wurstOptionsButton == null)
8487
return;
8588

@@ -95,7 +98,11 @@ private void onRender(GuiGraphics graphics, int mouseX, int mouseY,
9598
{
9699
Font font = minecraft.font;
97100
String brand = NiceWurstModule.isActive() ? "NiceWurst" : "Wurst";
98-
String text = brand + " " + BuildConfig.MOD_VERSION;
101+
String baseText = brand + " " + BuildConfig.MOD_VERSION + " v"
102+
+ BuildConfig.FORK_RELEASE_VERSION;
103+
String suffix = WurstClient.INSTANCE.getForkUpdateChecker() == null ? ""
104+
: WurstClient.INSTANCE.getForkUpdateChecker().getStatusSuffix();
105+
String text = baseText + suffix;
99106
graphics.drawString(font, Component.literal(text).getVisualOrderText(),
100107
4, 4, 0xFFFFFFFF, true);
101108
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
3+
*
4+
* This source code is subject to the terms of the GNU General Public
5+
* License, version 3. If a copy of the GPL was not distributed with this
6+
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
7+
*/
8+
package net.wurstclient.update;
9+
10+
import java.net.URI;
11+
import java.net.URLConnection;
12+
import net.wurstclient.WurstClient;
13+
import net.wurstclient.config.BuildConfig;
14+
import net.wurstclient.events.UpdateListener;
15+
import net.wurstclient.util.json.JsonUtils;
16+
import net.wurstclient.util.json.WsonArray;
17+
import net.wurstclient.util.json.WsonObject;
18+
19+
public final class ForkUpdateChecker implements UpdateListener
20+
{
21+
private Thread thread;
22+
private volatile String statusSuffix = "";
23+
24+
@Override
25+
public void onUpdate()
26+
{
27+
if(thread == null)
28+
{
29+
thread = new Thread(this::checkForUpdates, "ForkUpdateChecker");
30+
thread.start();
31+
return;
32+
}
33+
34+
if(thread.isAlive())
35+
return;
36+
37+
WurstClient.INSTANCE.getEventManager().remove(UpdateListener.class,
38+
this);
39+
}
40+
41+
public void startIfNeeded()
42+
{
43+
if(thread != null)
44+
return;
45+
46+
thread = new Thread(this::checkForUpdates, "ForkUpdateChecker");
47+
thread.start();
48+
}
49+
50+
public String getStatusSuffix()
51+
{
52+
return statusSuffix;
53+
}
54+
55+
private void checkForUpdates()
56+
{
57+
if(System.getProperty("fabric.client.gametest") != null)
58+
return;
59+
60+
if(BuildConfig.GH_REPO_ID == null || BuildConfig.GH_REPO_ID.isBlank())
61+
return;
62+
63+
Version currentRelease =
64+
new Version(stripTagPrefix(BuildConfig.FORK_RELEASE_VERSION));
65+
Version latestRelease = null;
66+
67+
try
68+
{
69+
latestRelease = fetchLatestRelease();
70+
71+
}catch(Exception e)
72+
{
73+
System.err.println("[ForkUpdateChecker] An error occurred!");
74+
e.printStackTrace();
75+
return;
76+
}
77+
78+
if(latestRelease == null || latestRelease.isInvalid()
79+
|| currentRelease.isInvalid())
80+
return;
81+
82+
if(currentRelease.isLowerThan(latestRelease))
83+
{
84+
statusSuffix =
85+
" (Out of Date: Latest Version is " + latestRelease + ")";
86+
return;
87+
}
88+
}
89+
90+
private Version fetchLatestRelease() throws Exception
91+
{
92+
String releasesUrl = "https://api.github.com/repos/"
93+
+ BuildConfig.GH_REPO_ID + "/releases";
94+
WsonArray releases =
95+
JsonUtils.parseConnectionToArray(openGitHubConnection(releasesUrl));
96+
97+
for(WsonObject release : releases.getAllObjects())
98+
{
99+
if(release.getBoolean("draft", false))
100+
continue;
101+
102+
if(release.getBoolean("prerelease", false))
103+
continue;
104+
105+
String tagName = release.getString("tag_name", "");
106+
return new Version(stripTagPrefix(tagName));
107+
}
108+
109+
return null;
110+
}
111+
112+
private URLConnection openGitHubConnection(String url) throws Exception
113+
{
114+
URLConnection connection = URI.create(url).toURL().openConnection();
115+
connection.setRequestProperty("Accept", "application/vnd.github+json");
116+
connection.setRequestProperty("User-Agent", "Wurst7-CevAPI");
117+
return connection;
118+
}
119+
120+
private String stripTagPrefix(String version)
121+
{
122+
if(version == null)
123+
return "";
124+
125+
return version.startsWith("v") ? version.substring(1) : version;
126+
}
127+
}

src/main/templates/net/wurstclient/config/BuildConfig.java.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ public final class BuildConfig
66

77
public static final boolean NICE_WURST = ${NICE_WURST};
88
public static final String MOD_VERSION = "${MOD_VERSION}";
9+
public static final String FORK_RELEASE_VERSION = "${FORK_RELEASE_VERSION}";
10+
public static final String BUILD_DATE = "${BUILD_DATE}";
11+
public static final String GH_REPO_ID = "${GH_REPO_ID}";
12+
public static final String GH_REPO_URL = "${GH_REPO_URL}";
913
}

0 commit comments

Comments
 (0)