ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java

69 lines
3.2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("UpdateChecker.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.update;
2015-04-26 21:09:25 +02:00
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.Util;
2016-07-03 20:57:00 +02:00
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-04-26 21:09:25 +02:00
2016-07-03 20:57:00 +02:00
public class UpdateChecker{
2015-04-26 21:09:25 +02:00
public static final String DOWNLOAD_LINK = "http://ellpeck.de/actadddownload";
2016-05-16 22:52:27 +02:00
public static final String CHANGELOG_LINK = "http://ellpeck.de/actaddchangelog";
public static boolean checkFailed;
public static boolean needsUpdateNotify;
public static int updateVersionInt;
public static String updateVersionString;
2016-07-03 20:57:00 +02:00
private static boolean notified = false;
private static int ticksElapsedBeforeInfo;
public UpdateChecker(){
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){
2015-09-29 17:08:47 +02:00
ModUtil.LOGGER.info("Initializing Update Checker...");
2016-07-03 20:57:00 +02:00
2015-09-29 17:08:47 +02:00
new ThreadUpdateChecker();
2016-07-03 20:57:00 +02:00
MinecraftForge.EVENT_BUS.register(this);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
2016-11-26 21:32:27 +01:00
if(!notified && Minecraft.getMinecraft().player != null){
2016-07-03 20:57:00 +02:00
ticksElapsedBeforeInfo++;
if(ticksElapsedBeforeInfo >= 800){
2016-11-26 21:32:27 +01:00
EntityPlayer player = Minecraft.getMinecraft().player;
2016-07-03 20:57:00 +02:00
if(UpdateChecker.checkFailed){
2016-11-26 21:32:27 +01:00
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.failed")));
2016-07-03 20:57:00 +02:00
notified = true;
}
else if(UpdateChecker.needsUpdateNotify){
2016-11-26 21:32:27 +01:00
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.generic")));
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersionString)));
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK)));
2016-07-03 20:57:00 +02:00
notified = true;
}
ticksElapsedBeforeInfo = 0;
}
2015-09-29 17:08:47 +02:00
}
2015-04-26 21:09:25 +02:00
}
}