This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ModUpdater/src/main/java/com/thebrokenrail/modupdater/ModUpdater.java

51 lines
1.5 KiB
Java
Raw Normal View History

2020-06-24 02:04:22 +00:00
package com.thebrokenrail.modupdater;
2020-06-25 20:56:09 +00:00
import com.thebrokenrail.modupdater.strategy.util.UpdateStrategyRunner;
import com.thebrokenrail.modupdater.data.ModUpdate;
2020-06-24 02:04:22 +00:00
import net.fabricmc.api.ModInitializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2020-06-24 18:03:02 +00:00
import java.util.Objects;
2020-06-24 02:04:22 +00:00
public class ModUpdater implements ModInitializer {
public static final String NAMESPACE = "modupdater";
private static final String LOGGER_NAME = "ModUpdater";
2020-06-25 20:56:09 +00:00
private static Logger getLogger() {
2020-06-24 02:04:22 +00:00
return LogManager.getLogger(LOGGER_NAME);
}
2020-06-25 20:56:09 +00:00
public static void log(String name, String msg) {
getLogger().warn(String.format("%s: %s", name, msg));
2020-06-24 02:04:22 +00:00
}
2020-06-24 18:21:26 +00:00
private static volatile ModUpdate[] updates;
2020-06-24 02:04:22 +00:00
2020-06-24 18:03:02 +00:00
private static Thread updateThread;
2020-06-24 02:04:22 +00:00
public static ModUpdate[] getUpdates() {
if (updates == null) {
2020-06-24 18:03:02 +00:00
if (Thread.currentThread() == updateThread) {
2020-06-25 20:56:09 +00:00
updates = UpdateStrategyRunner.checkAllModsForUpdates();
2020-06-24 18:03:02 +00:00
} else {
return null;
}
2020-06-24 02:04:22 +00:00
}
return updates;
}
@Override
public void onInitialize() {
2020-06-24 18:03:02 +00:00
updateThread = new Thread(() -> {
getLogger().info("Checking For Mod Updates...");
for (ModUpdate update : Objects.requireNonNull(getUpdates())) {
getLogger().info(update.text + " (" + update.downloadURL + ')');
}
getLogger().info(updates.length + " Mod Update(s) Found");
});
2020-06-24 18:21:26 +00:00
updateThread.start();
2020-06-24 02:04:22 +00:00
}
}