Skip to content

Commit

Permalink
Merge pull request #165 from Fix3dll/master
Browse files Browse the repository at this point in the history
fix repository update
  • Loading branch information
AzureAaron authored Jun 1, 2023
2 parents d816786 + 9190389 commit 9d114a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;

import java.io.File;
import java.nio.file.Files;
import java.util.concurrent.CompletableFuture;

public class RepositoryUpdate {
public static final MinecraftClient client = MinecraftClient.getInstance();

/**
* Adds command to update repository manually from ingame.
Expand All @@ -21,22 +23,7 @@ public static void init(){
ClientCommandManager.literal("skyblocker")
.then(ClientCommandManager.literal("updaterepository")
.executes(context -> {
CompletableFuture.runAsync(() -> {
try {
ItemRegistry.filesImported = false;
File dir = ItemRegistry.LOCAL_ITEM_REPO_DIR.toFile();
recursiveDelete(dir);
} catch (Exception ex) {
ItemRegistry.client.player.sendMessage(
Text.translatable("skyblocker.updaterepository.failed")
, false
);
return;
}

ItemRegistry.init();
});

updateRepository();
return 1;
})
)
Expand All @@ -45,6 +32,25 @@ public static void init(){

}

public static void updateRepository() {
CompletableFuture.runAsync(() -> {
try {
ItemRegistry.filesImported = false;
File dir = ItemRegistry.LOCAL_ITEM_REPO_DIR.toFile();
recursiveDelete(dir);
} catch (Exception ex) {
if (client.player != null)
client.player.sendMessage(
Text.translatable("skyblocker.updaterepository.failed")
, false
);
return;
}

ItemRegistry.init();
});
}

private static void recursiveDelete(File dir) {
if (dir.isDirectory() && !Files.isSymbolicLink(dir.toPath())) {
for (File child : dir.listFiles()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import me.xmrvizzy.skyblocker.skyblock.api.RepositoryUpdate;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -47,27 +49,35 @@ public static void init() {
}

private static void updateItemRepo() {
Git git;
if (!Files.isDirectory(LOCAL_ITEM_REPO_DIR)) {
try {
Git.cloneRepository()
git = Git.cloneRepository()
.setURI(REMOTE_ITEM_REPO)
.setDirectory(LOCAL_ITEM_REPO_DIR.toFile())
.setBranchesToClone(List.of("refs/heads/master"))
.setBranch("refs/heads/master")
.call();
git.close();
LOGGER.info("[Skyblocker Repository Update] Repository updated.");
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
PullResult pull = Git.open(LOCAL_ITEM_REPO_DIR.toFile()).pull().setRebase(true).call();
git = Git.open(LOCAL_ITEM_REPO_DIR.toFile());
PullResult pull = git.pull().setRebase(true).call();
git.close();

if (pull.getRebaseResult() == null) {
LOGGER.info("[Skyblocker Repository Update] No update result");
} else if (pull.getRebaseResult().getStatus().isSuccessful()) {
LOGGER.info("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name());
} else if (!pull.getRebaseResult().getStatus().isSuccessful()) {
LOGGER.warn("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name());
}
} catch (RepositoryNotFoundException e) {
RepositoryUpdate.updateRepository();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 9d114a7

Please sign in to comment.