2015-04-26 21:09:25 +02:00
|
|
|
package ellpeck.actuallyadditions.update;
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-08-01 00:40:29 +02:00
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
2015-04-26 21:09:25 +02:00
|
|
|
import ellpeck.actuallyadditions.util.Util;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-05-27 21:57:53 +02:00
|
|
|
import net.minecraft.util.ChatComponentText;
|
2015-04-26 21:09:25 +02:00
|
|
|
import net.minecraft.util.IChatComponent;
|
|
|
|
|
|
|
|
public class UpdateChecker{
|
|
|
|
|
2015-07-10 20:04:07 +02:00
|
|
|
public static boolean doneChecking = false;
|
|
|
|
public static boolean checkFailed = false;
|
|
|
|
private static boolean notified = false;
|
|
|
|
public static String updateVersionS;
|
|
|
|
public static int updateVersion;
|
|
|
|
public static int clientVersion;
|
|
|
|
public static String changelog;
|
|
|
|
|
|
|
|
public static final String DOWNLOAD_LINK = "http://minecraft.curseforge.com/mc-mods/228404-actually-additions/files";
|
2015-04-26 21:09:25 +02:00
|
|
|
|
|
|
|
public void init(){
|
2015-07-01 21:32:48 +02:00
|
|
|
ModUtil.LOGGER.info("Initializing Update Checker...");
|
2015-04-26 21:09:25 +02:00
|
|
|
Util.registerEvent(this);
|
2015-07-10 20:04:07 +02:00
|
|
|
new ThreadUpdateChecker();
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|
|
|
|
|
2015-07-03 00:21:20 +02:00
|
|
|
@SubscribeEvent(receiveCanceled = true)
|
2015-04-26 21:09:25 +02:00
|
|
|
public void onTick(TickEvent.ClientTickEvent event){
|
2015-07-17 18:32:30 +02:00
|
|
|
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
|
2015-07-23 11:41:09 +02:00
|
|
|
if(Minecraft.getSystemTime() % 200 == 0 && !notified && doneChecking && Minecraft.getMinecraft().thePlayer != null){
|
2015-05-04 17:26:50 +02:00
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
if(checkFailed){
|
2015-08-01 00:40:29 +02:00
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed.desc")));
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
2015-07-10 20:04:07 +02:00
|
|
|
else{
|
|
|
|
if(updateVersion > clientVersion){
|
|
|
|
String notice1 = "info."+ModUtil.MOD_ID_LOWER+".update.generic.desc";
|
|
|
|
String notice2 = "info."+ModUtil.MOD_ID_LOWER+".update.versionComp.desc";
|
|
|
|
String notice3 = "info."+ModUtil.MOD_ID_LOWER+".update.changelog.desc";
|
|
|
|
String notice4 = "info."+ModUtil.MOD_ID_LOWER+".update.download.desc";
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(""));
|
2015-08-01 00:40:29 +02:00
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize(notice1)));
|
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice2, ModUtil.VERSION, updateVersionS)));
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StringUtil.localizeFormatted(notice3, changelog)));
|
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice4, DOWNLOAD_LINK)));
|
2015-07-10 20:04:07 +02:00
|
|
|
player.addChatComponentMessage(new ChatComponentText(""));
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
notified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|