mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-16 15:24:51 +00:00
added update checks for my mods, turned fplib into a regular mod, added async lib
This commit is contained in:
8 files changed
+204
-54
No files matched your search
@@ -0,0 +1,67 @@
|
||||
package com.falsepattern.lib.internal.proxy;
|
||||
|
||||
import com.falsepattern.lib.config.ConfigException;
|
||||
import com.falsepattern.lib.config.ConfigurationManager;
|
||||
import com.falsepattern.lib.internal.FalsePatternLib;
|
||||
import com.falsepattern.lib.internal.LibraryConfig;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.updates.ModUpdateInfo;
|
||||
import com.falsepattern.lib.updates.UpdateChecker;
|
||||
import cpw.mods.fml.common.event.FMLConstructionEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class CommonProxy {
|
||||
|
||||
protected Future<List<ModUpdateInfo>> updatesFuture;
|
||||
|
||||
public void construct(FMLConstructionEvent e) {
|
||||
ConfigurationManager.init();
|
||||
}
|
||||
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
try {
|
||||
ConfigurationManager.registerConfig(LibraryConfig.class);
|
||||
} catch (ConfigException ex) {
|
||||
FalsePatternLib.getLog().error("Failed to register " + Tags.MODNAME + " config!", ex);
|
||||
}
|
||||
if (LibraryConfig.ENABLE_UPDATE_CHECKER) {
|
||||
FalsePatternLib.getLog().info("Launching asynchronous update check.");
|
||||
val updateCheckFuture = UpdateChecker.fetchUpdatesAsync("https://falsepattern.com/mc/versions.json");
|
||||
updatesFuture = FalsePatternLib.getAsyncWorker().submit(() -> {
|
||||
if (!updateCheckFuture.isCancelled()) {
|
||||
try {
|
||||
var updates = updateCheckFuture.get();
|
||||
if (updates != null && updates.size() > 0) {
|
||||
for (val update:updates) {
|
||||
update.log(FalsePatternLib.getLog());
|
||||
}
|
||||
} else if (updates == null) {
|
||||
FalsePatternLib.getLog().warn("Unknown error while checking updates");
|
||||
} else {
|
||||
FalsePatternLib.getLog().info("All FalsePattern mods up to date!");
|
||||
updates = null;
|
||||
}
|
||||
return updates;
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
FalsePatternLib.getLog().warn("Error while checking updates", ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user