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;
|
|
|
|
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;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
public class UpdateChecker{
|
|
|
|
|
|
|
|
public boolean doneChecking = false;
|
2015-05-04 17:26:50 +02:00
|
|
|
public boolean checkFailed = false;
|
2015-04-26 21:09:25 +02:00
|
|
|
public boolean notified = false;
|
|
|
|
public String onlineVersion;
|
2015-05-27 21:57:53 +02:00
|
|
|
public String changelog;
|
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);
|
|
|
|
new UpdateCheckThread();
|
|
|
|
}
|
|
|
|
|
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){
|
|
|
|
if(doneChecking && event.phase == TickEvent.Phase.END && Minecraft.getMinecraft().thePlayer != null && !notified){
|
2015-05-04 17:26:50 +02:00
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
if(checkFailed){
|
2015-07-02 10:45:15 +02:00
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StatCollector.translateToLocal("info." + ModUtil.MOD_ID_LOWER + ".update.failed.desc")));
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
else if(onlineVersion.length() > 0){
|
2015-07-03 00:21:20 +02:00
|
|
|
try{
|
|
|
|
int update = Integer.parseInt(onlineVersion.replace("-", "").replace(".", ""));
|
|
|
|
int client = Integer.parseInt(ModUtil.VERSION.replace("-", "").replace(".", ""));
|
2015-04-26 21:09:25 +02:00
|
|
|
|
2015-07-03 00:21:20 +02:00
|
|
|
if(update > client){
|
|
|
|
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";
|
2015-07-06 17:48:38 +02:00
|
|
|
player.addChatComponentMessage(new ChatComponentText(""));
|
2015-07-03 00:21:20 +02:00
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StatCollector.translateToLocal(notice1)));
|
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StatCollector.translateToLocalFormatted(notice2, ModUtil.VERSION, onlineVersion)));
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(notice3, changelog)));
|
|
|
|
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StatCollector.translateToLocalFormatted(notice4, "http://minecraft.curseforge.com/mc-mods/228404-actually-additions/files")));
|
2015-07-06 17:48:38 +02:00
|
|
|
player.addChatComponentMessage(new ChatComponentText(""));
|
2015-07-03 00:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception e){
|
|
|
|
ModUtil.LOGGER.error("Sending the Update Check Information to the Chat failed!", e);
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
notified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class UpdateCheckThread extends Thread{
|
|
|
|
|
|
|
|
public UpdateCheckThread(){
|
|
|
|
this.setName(ModUtil.MOD_ID + " Update Checker");
|
|
|
|
this.setDaemon(true);
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(){
|
2015-07-01 21:32:48 +02:00
|
|
|
ModUtil.LOGGER.info("Starting Update Check...");
|
2015-04-26 21:09:25 +02:00
|
|
|
try{
|
2015-07-02 10:45:15 +02:00
|
|
|
URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/newestVersion.txt");
|
2015-05-27 21:57:53 +02:00
|
|
|
BufferedReader newestReader = new BufferedReader(new InputStreamReader(newestURL.openStream()));
|
|
|
|
onlineVersion = newestReader.readLine();
|
|
|
|
newestReader.close();
|
|
|
|
|
2015-07-02 10:45:15 +02:00
|
|
|
URL changeURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/changelog.txt");
|
2015-05-27 21:57:53 +02:00
|
|
|
BufferedReader changeReader = new BufferedReader(new InputStreamReader(changeURL.openStream()));
|
|
|
|
changelog = changeReader.readLine();
|
|
|
|
changeReader.close();
|
|
|
|
|
2015-07-01 21:32:48 +02:00
|
|
|
ModUtil.LOGGER.info("Update Check done!");
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|
|
|
|
catch(Exception e){
|
2015-05-04 17:26:50 +02:00
|
|
|
checkFailed = true;
|
2015-07-03 00:21:20 +02:00
|
|
|
ModUtil.LOGGER.error("Update Check failed!", e);
|
2015-04-26 21:09:25 +02:00
|
|
|
}
|
|
|
|
doneChecking = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|