Skip to content

Commit df928c6

Browse files
committed
Added clickable notification
Added clickable download link, and stopped update message from showing when there are no new updates
1 parent b2a49d6 commit df928c6

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

src/main/java/xyz/yourboykyle/secretroutes/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void onServerConnect(FMLNetworkEvent.ClientConnectedToServerEvent event)
280280
if(SRMConfig.autoCheckUpdates) {
281281
new Thread(() -> {
282282
try {
283-
Main.updateManager.checkUpdate();
283+
Main.updateManager.checkUpdate(false);
284284
} catch (Exception e) {
285285
LogUtils.error(e);
286286
}

src/main/java/xyz/yourboykyle/secretroutes/config/SRMConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public class SRMConfig extends Config {
234234
Runnable runnable14 = () -> {
235235
new Thread(() -> {
236236
sendChatMessage("Checking for updates, please wait a few seconds...");
237-
Main.updateManager.checkUpdate();
237+
Main.updateManager.checkUpdate(true);
238238
}).start();
239239
};
240240

src/main/java/xyz/yourboykyle/secretroutes/utils/ChatUtils.java

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
package xyz.yourboykyle.secretroutes.utils;
2222

2323
import net.minecraft.client.Minecraft;
24+
import net.minecraft.event.ClickEvent;
25+
import net.minecraft.event.HoverEvent;
2426
import net.minecraft.util.ChatComponentText;
2527
import net.minecraft.util.ChatStyle;
2628
import net.minecraft.util.EnumChatFormatting;
@@ -91,4 +93,13 @@ public static boolean sendVerboseMessage(String message, String TAG){
9193
}
9294

9395
}
96+
public static void sendClickableMessage(String text, String link){
97+
if(Minecraft.getMinecraft().thePlayer == null){
98+
return;
99+
}
100+
ChatComponentText component = new ChatComponentText(text);
101+
component.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link));
102+
component.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText("Click to open link")));
103+
Minecraft.getMinecraft().thePlayer.addChatMessage(component);
104+
}
94105
}

src/main/java/xyz/yourboykyle/secretroutes/utils/Room.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ public void getData(String filePath){
213213
for (int i = 0; i < 10; i++) {
214214
String path = name;
215215
if (i == 0) {
216-
if (data.get(name) == null || data.get(name).isJsonNull()) {
216+
if (data == null || data.isJsonNull() || data.get(name) == null || data.get(name).isJsonNull()) {
217217
currentSecretRoute = null;
218218
}
219219
} else {
220220
path = name + ":" + i;
221221
}
222-
if (data.get(path) == null || data.get(path).isJsonNull()) {
222+
if (data == null || data.isJsonNull() || data.get(path) == null || data.get(path).isJsonNull()) {
223223
break;
224224
}
225225
JsonArray route = data.get(path).getAsJsonArray();

src/main/java/xyz/yourboykyle/secretroutes/utils/autoupdate/UpdateManager.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void reset() {
4444
LogUtils.info("Reset update state");
4545
}
4646

47-
public void checkUpdate() {
47+
public void checkUpdate(Boolean button) {
4848
if (updateState == UpdateState.DOWNLOADED) {
4949
LogUtils.info("The latest version has already been downloaded in this session. Please restart to apply the changes.");
5050
return;
@@ -75,10 +75,12 @@ public void checkUpdate() {
7575
ChatUtils.sendChatMessage(EnumChatFormatting.GREEN + "Automatically downloading new Secret Routes Mod update, since AutoDownload is true...");
7676
queueUpdate();
7777
} else {
78-
ChatUtils.sendChatMessage(EnumChatFormatting.GREEN + "Download at https://github.com/yourboykyle/SecretRoutes/releases/latest");
78+
ChatUtils.sendClickableMessage(EnumChatFormatting.GREEN + "Download at https://github.com/yourboykyle/SecretRoutes/releases/latest", "https://github.com/yourboykyle/SecretRoutes/releases/latest");
7979
}
8080
} else {
81-
ChatUtils.sendChatMessage(EnumChatFormatting.GREEN + "Secret Routes Mod didn't find a new update.");
81+
if(button){
82+
ChatUtils.sendChatMessage(EnumChatFormatting.GREEN + "Secret Routes Mod is up to date!");
83+
}
8284
LogUtils.info("No update available.");
8385
}
8486
}, MinecraftExecutor.INSTANCE)

0 commit comments

Comments
 (0)