mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 07:57:45 +00:00
added update checks and separate internet library
This commit is contained in:
7 files changed
+207
-101
No files matched your search
@@ -2,6 +2,8 @@ package com.falsepattern.lib.internal;
|
||||
|
||||
import com.falsepattern.lib.config.ConfigException;
|
||||
import com.falsepattern.lib.config.ConfigurationManager;
|
||||
import com.falsepattern.lib.updates.ModUpdateInfo;
|
||||
import com.falsepattern.lib.updates.UpdateChecker;
|
||||
import com.falsepattern.lib.util.ResourceUtil;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
@@ -15,10 +17,15 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Utility class used by FalsePatternLib's internal code. This can change between versions without notice, so do not use
|
||||
* this in your code!
|
||||
@@ -30,6 +37,8 @@ public class FalsePatternLib extends DummyModContainer {
|
||||
@Getter private static final boolean developerEnvironment =
|
||||
(boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
|
||||
|
||||
private Future<List<ModUpdateInfo>> updateCheckFuture;
|
||||
|
||||
public FalsePatternLib() {
|
||||
super(MetadataCollection.from(ResourceUtil.getResourceFromJar("/mcmod.info", FalsePatternLib.class), Tags.MODID)
|
||||
.getMetadataForId(Tags.MODID, null));
|
||||
@@ -48,8 +57,26 @@ public class FalsePatternLib extends DummyModContainer {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
if (LibraryConfig.ENABLE_UPDATE_CHECKER) {
|
||||
getLog().info("Launching asynchronous update check. I'll check back on it during postInit.");
|
||||
updateCheckFuture = UpdateChecker.fetchUpdatesAsync("https://falsepattern.com/mc/versions.json");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
if (updateCheckFuture != null && !updateCheckFuture.isCancelled()) {
|
||||
try {
|
||||
val updates = updateCheckFuture.get();
|
||||
if (updates != null)
|
||||
for (val update: updates)
|
||||
update.log(getLog());
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
getLog().warn("Error while checking updates", ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
|
||||
Reference in new issue
Block a user