aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java (renamed from src/main/java/de/hysky/skyblocker/utils/NEURepo.java)30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/NEURepo.java b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java
index 9bc6b245..e6ede542 100644
--- a/src/main/java/de/hysky/skyblocker/utils/NEURepo.java
+++ b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java
@@ -1,7 +1,8 @@
package de.hysky.skyblocker.utils;
import de.hysky.skyblocker.SkyblockerMod;
-import de.hysky.skyblocker.skyblock.itemlist.ItemRegistry;
+import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
+import io.github.moulberry.repo.NEURepository;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.client.MinecraftClient;
@@ -21,11 +22,15 @@ import java.util.concurrent.CompletableFuture;
/**
* Initializes the NEU repo, which contains item metadata and fairy souls location data. Clones the repo if it does not exist and checks for updates. Use {@link #runAsyncAfterLoad(Runnable)} to run code after the repo is initialized.
*/
-public class NEURepo {
- private static final Logger LOGGER = LoggerFactory.getLogger(NEURepo.class);
+public class NEURepoManager {
+ private static final Logger LOGGER = LoggerFactory.getLogger(NEURepoManager.class);
public static final String REMOTE_REPO_URL = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO.git";
- public static final Path LOCAL_REPO_DIR = SkyblockerMod.CONFIG_DIR.resolve("item-repo");
- private static final CompletableFuture<Void> REPO_INITIALIZED = initRepository();
+ /**
+ * Use {@link #NEU_REPO}.
+ */
+ private static final Path LOCAL_REPO_DIR = SkyblockerMod.CONFIG_DIR.resolve("item-repo"); // TODO rename to NotEnoughUpdates-REPO
+ private static final CompletableFuture<Void> REPO_INITIALIZED = loadRepository();
+ public static final NEURepository NEU_REPO = NEURepository.of(LOCAL_REPO_DIR);
/**
* Adds command to update repository manually from ingame.
@@ -41,18 +46,19 @@ public class NEURepo {
}))));
}
- private static CompletableFuture<Void> initRepository() {
+ private static CompletableFuture<Void> loadRepository() {
return CompletableFuture.runAsync(() -> {
try {
- if (Files.isDirectory(NEURepo.LOCAL_REPO_DIR)) {
- try (Git localRepo = Git.open(NEURepo.LOCAL_REPO_DIR.toFile())) {
+ if (Files.isDirectory(NEURepoManager.LOCAL_REPO_DIR)) {
+ try (Git localRepo = Git.open(NEURepoManager.LOCAL_REPO_DIR.toFile())) {
localRepo.pull().setRebase(true).call();
LOGGER.info("[Skyblocker] NEU Repository Updated");
}
} else {
- Git.cloneRepository().setURI(REMOTE_REPO_URL).setDirectory(NEURepo.LOCAL_REPO_DIR.toFile()).setBranchesToClone(List.of("refs/heads/master")).setBranch("refs/heads/master").call().close();
+ Git.cloneRepository().setURI(REMOTE_REPO_URL).setDirectory(NEURepoManager.LOCAL_REPO_DIR.toFile()).setBranchesToClone(List.of("refs/heads/master")).setBranch("refs/heads/master").call().close();
LOGGER.info("[Skyblocker] NEU Repository Downloaded");
}
+ NEU_REPO.reload();
} catch (TransportException e){
LOGGER.error("[Skyblocker] Transport operation failed. Most likely unable to connect to the remote NEU repo on github", e);
} catch (RepositoryNotFoundException e) {
@@ -67,15 +73,15 @@ public class NEURepo {
private static void deleteAndDownloadRepository() {
CompletableFuture.runAsync(() -> {
try {
- ItemRegistry.filesImported = false;
- File dir = NEURepo.LOCAL_REPO_DIR.toFile();
+ ItemRepository.setFilesImported(false);
+ File dir = NEURepoManager.LOCAL_REPO_DIR.toFile();
recursiveDelete(dir);
} catch (Exception ex) {
if (MinecraftClient.getInstance().player != null)
MinecraftClient.getInstance().player.sendMessage(Text.translatable("skyblocker.updaterepository.failed"), false);
return;
}
- initRepository();
+ loadRepository();
});
}