unregister the update checker after finishing

since this is a tick handler keeping it registered is probably a bad
idea.
This commit is contained in:
Shadows_of_Fire 2018-07-10 19:10:26 -04:00
parent 2584bb9cf4
commit a10999736a
2 changed files with 13 additions and 20 deletions

View file

@ -82,5 +82,7 @@ public class ThreadUpdateChecker extends Thread{
ActuallyAdditions.LOGGER.info(ActuallyAdditions.NAME+" is up to date!"); ActuallyAdditions.LOGGER.info(ActuallyAdditions.NAME+" is up to date!");
} }
} }
UpdateChecker.threadFinished = true;
} }
} }

View file

@ -31,14 +31,11 @@ public class UpdateChecker{
public static boolean needsUpdateNotify; public static boolean needsUpdateNotify;
public static int updateVersionInt; public static int updateVersionInt;
public static String updateVersionString; public static String updateVersionString;
public static boolean threadFinished = false;
private static boolean notified = false;
private static int ticksElapsedBeforeInfo;
public UpdateChecker(){ public UpdateChecker(){
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){ if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){
ActuallyAdditions.LOGGER.info("Initializing Update Checker..."); ActuallyAdditions.LOGGER.info("Initializing Update Checker...");
new ThreadUpdateChecker(); new ThreadUpdateChecker();
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -47,23 +44,17 @@ public class UpdateChecker{
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled = true) @SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){ public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining if(Minecraft.getMinecraft().player != null){
if(!notified && Minecraft.getMinecraft().player != null){
ticksElapsedBeforeInfo++;
if(ticksElapsedBeforeInfo >= 800){
EntityPlayer player = Minecraft.getMinecraft().player; EntityPlayer player = Minecraft.getMinecraft().player;
if(UpdateChecker.checkFailed){ if(UpdateChecker.checkFailed){
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ActuallyAdditions.MODID+".update.failed"))); player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ActuallyAdditions.MODID+".update.failed")));
notified = true;
} }
else if(UpdateChecker.needsUpdateNotify){ else if(UpdateChecker.needsUpdateNotify){
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ActuallyAdditions.MODID+".update.generic"))); player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ActuallyAdditions.MODID+".update.generic")));
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ActuallyAdditions.MODID+".update.versionCompare", ActuallyAdditions.VERSION, UpdateChecker.updateVersionString))); player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ActuallyAdditions.MODID+".update.versionCompare", ActuallyAdditions.VERSION, UpdateChecker.updateVersionString)));
player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ActuallyAdditions.MODID+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK))); player.sendMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ActuallyAdditions.MODID+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK)));
notified = true;
}
ticksElapsedBeforeInfo = 0;
} }
if(threadFinished) MinecraftForge.EVENT_BUS.unregister(this);
} }
} }
} }