mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 12:19:46 +00:00
Version checker just piggybacks off forge one now
This commit is contained in:
2 files changed
+16
-54
No files matched your search
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [May 31, 2014, 10:31:46 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.core.version;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class ThreadVersionChecker extends Thread {
|
||||
|
||||
private static final String LINK = "https://raw.githubusercontent.com/williewillus/Botania/MC19/version/" + MinecraftForge.MC_VERSION + ".txt";
|
||||
|
||||
public ThreadVersionChecker() {
|
||||
setName("Botania Version Checker Thread");
|
||||
setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try(BufferedReader r = new BufferedReader(new InputStreamReader(new URL(LINK).openStream()))) {
|
||||
VersionChecker.onlineVersion = r.readLine();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
VersionChecker.doneChecking = true;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,10 @@ import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
@@ -30,34 +33,32 @@ public final class VersionChecker {
|
||||
private static final int FLAVOUR_MESSAGES = 65;
|
||||
|
||||
public static boolean doneChecking = false;
|
||||
public static String onlineVersion = "";
|
||||
public static boolean triedToWarnPlayer = false;
|
||||
private static boolean triedToWarnPlayer = false;
|
||||
|
||||
public static boolean startedDownload = false;
|
||||
public static boolean downloadedFile = false;
|
||||
|
||||
public static void init() {
|
||||
new ThreadVersionChecker();
|
||||
MinecraftForge.EVENT_BUS.register(VersionChecker.class);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTick(ClientTickEvent event) {
|
||||
if(doneChecking && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null && !triedToWarnPlayer) {
|
||||
if(!onlineVersion.isEmpty()) {
|
||||
if(!triedToWarnPlayer && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null) {
|
||||
ModContainer botaniaContainer = Loader.instance().getIndexedModList().get(LibMisc.MOD_ID);
|
||||
ForgeVersion.CheckResult result = ForgeVersion.getResult(botaniaContainer);
|
||||
|
||||
if(result.status != ForgeVersion.Status.PENDING)
|
||||
triedToWarnPlayer = true;
|
||||
|
||||
if(result.status == ForgeVersion.Status.OUTDATED) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
int onlineBuild = Integer.parseInt(onlineVersion.split("-")[1]);
|
||||
int clientBuild = LibMisc.BUILD.contains("GRADLE") ? Integer.MIN_VALUE : Integer.parseInt(LibMisc.BUILD);
|
||||
if(onlineBuild > clientBuild) {
|
||||
player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.flavour" + player.worldObj.rand.nextInt(FLAVOUR_MESSAGES)).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE)));
|
||||
player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.outdated", clientBuild, onlineBuild));
|
||||
player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.flavour" + player.worldObj.rand.nextInt(FLAVOUR_MESSAGES)).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE)));
|
||||
player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.outdated", botaniaContainer.getVersion(), result.target));
|
||||
|
||||
ITextComponent component = ITextComponent.Serializer.jsonToComponent(I18n.format("botania.versioning.updateMessage", onlineVersion));
|
||||
player.addChatComponentMessage(component);
|
||||
}
|
||||
ITextComponent component = ITextComponent.Serializer.jsonToComponent(I18n.format("botania.versioning.updateMessage", result.target));
|
||||
player.addChatComponentMessage(component);
|
||||
}
|
||||
|
||||
triedToWarnPlayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user