aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/UpdateChecker.java
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2021-02-27 18:25:51 -0500
committerbowser0000 <bowser0000@gmail.com>2021-02-27 18:25:51 -0500
commitad53066846fb168255499a332a1ad4bca39f5935 (patch)
tree9482f461f3f12c64bcb8e6572f43bc480d817d85 /src/main/java/me/Danker/features/UpdateChecker.java
parenta2f85ba6b9d80be3026aa906783a21c0b05cb681 (diff)
downloadSkyblockMod-ad53066846fb168255499a332a1ad4bca39f5935.tar.gz
SkyblockMod-ad53066846fb168255499a332a1ad4bca39f5935.tar.bz2
SkyblockMod-ad53066846fb168255499a332a1ad4bca39f5935.zip
Move features into their own files
Diffstat (limited to 'src/main/java/me/Danker/features/UpdateChecker.java')
-rw-r--r--src/main/java/me/Danker/features/UpdateChecker.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/features/UpdateChecker.java b/src/main/java/me/Danker/features/UpdateChecker.java
new file mode 100644
index 0000000..747fe91
--- /dev/null
+++ b/src/main/java/me/Danker/features/UpdateChecker.java
@@ -0,0 +1,52 @@
+package me.Danker.features;
+
+import com.google.gson.JsonObject;
+import me.Danker.DankersSkyblockMod;
+import me.Danker.handlers.APIHandler;
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.event.ClickEvent;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.event.entity.EntityJoinWorldEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
+
+public class UpdateChecker {
+
+ static boolean updateChecked = false;
+
+ @SubscribeEvent
+ public void onJoin(EntityJoinWorldEvent event) {
+ if (!updateChecked) {
+ updateChecked = true;
+
+ // MULTI THREAD DRIFTING
+ new Thread(() -> {
+ EntityPlayer player = Minecraft.getMinecraft().thePlayer;
+
+ System.out.println("Checking for updates...");
+ JsonObject latestRelease = APIHandler.getResponse("https://api.github.com/repos/bowser0000/SkyblockMod/releases/latest");
+
+ String latestTag = latestRelease.get("tag_name").getAsString();
+ DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(DankersSkyblockMod.VERSION);
+ DefaultArtifactVersion latestVersion = new DefaultArtifactVersion(latestTag.substring(1));
+
+ if (currentVersion.compareTo(latestVersion) < 0) {
+ String releaseURL = latestRelease.get("html_url").getAsString();
+
+ ChatComponentText update = new ChatComponentText(EnumChatFormatting.GREEN + "" + EnumChatFormatting.BOLD + " [UPDATE] ");
+ update.setChatStyle(update.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, releaseURL)));
+
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + DankersSkyblockMod.MODID + " is outdated. Please update to " + latestTag + ".\n").appendSibling(update));
+ }
+ }).start();
+ }
+ }
+
+}