diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
4 files changed, 59 insertions, 23 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/FileUtils.java b/src/main/java/de/hysky/skyblocker/utils/FileUtils.java new file mode 100644 index 00000000..22611441 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/FileUtils.java @@ -0,0 +1,36 @@ +package de.hysky.skyblocker.utils; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.slf4j.Logger; + +import com.mojang.logging.LogUtils; + +public class FileUtils { + private static final Logger LOGGER = LogUtils.getLogger(); + + public static void recursiveDelete(Path dir) throws IOException { + if (Files.isDirectory(dir) && !Files.isSymbolicLink(dir)) { + Files.list(dir).forEach(child -> { + try { + recursiveDelete(child); + } catch (Exception e) { + LOGGER.error("[Skyblocker] Encountered an exception while deleting a file! Path: {}", child.toAbsolutePath(), e); + } + }); + } + + Files.delete(dir); + } + + /** + * Replaces any characters that do not match the regex: [^a-z0-9_.-] + * + * @implNote Designed to convert a file path to an {@link net.minecraft.util.Identifier} + */ + public static String normalizePath(Path path) { + return path.toString().toLowerCase().replaceAll("[^a-z0-9_.-]", ""); + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/Http.java b/src/main/java/de/hysky/skyblocker/utils/Http.java index 58deced2..871eac78 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Http.java +++ b/src/main/java/de/hysky/skyblocker/utils/Http.java @@ -33,10 +33,6 @@ public class Http { .followRedirects(Redirect.NORMAL) .build(); - public static String sendGetRequest(String url) throws IOException, InterruptedException { - return sendCacheableGetRequest(url).content(); - } - private static ApiResponse sendCacheableGetRequest(String url) throws IOException, InterruptedException { HttpRequest request = HttpRequest.newBuilder() .GET() @@ -55,6 +51,26 @@ public class Http { return new ApiResponse(body, response.statusCode(), getCacheStatuses(headers), getAge(headers)); } + + public static InputStream downloadContent(String url) throws IOException, InterruptedException { + HttpRequest request = HttpRequest.newBuilder() + .GET() + .header("Accept", "*/*") + .header("Accept-Encoding", "gzip, deflate") + .header("User-Agent", USER_AGENT) + .version(Version.HTTP_2) + .uri(URI.create(url)) + .build(); + + HttpResponse<InputStream> response = HTTP_CLIENT.send(request, BodyHandlers.ofInputStream()); + InputStream decodedInputStream = getDecodedInputStream(response); + + return decodedInputStream; + } + + public static String sendGetRequest(String url) throws IOException, InterruptedException { + return sendCacheableGetRequest(url).content(); + } public static HttpHeaders sendHeadRequest(String url) throws IOException, InterruptedException { HttpRequest request = HttpRequest.newBuilder() diff --git a/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java index 870e94da..c779d666 100644 --- a/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java +++ b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java @@ -13,13 +13,10 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; /** * 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. @@ -76,7 +73,7 @@ public class NEURepoManager { CompletableFuture.runAsync(() -> { try { ItemRepository.setFilesImported(false); - recursiveDelete(NEURepoManager.LOCAL_REPO_DIR); + FileUtils.recursiveDelete(NEURepoManager.LOCAL_REPO_DIR); } catch (Exception ex) { if (MinecraftClient.getInstance().player != null) MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.updaterepository.failed")), false); @@ -86,21 +83,6 @@ public class NEURepoManager { }); } - @SuppressWarnings("ResultOfMethodCallIgnored") - private static void recursiveDelete(Path dir) throws IOException { - if (Files.isDirectory(dir) && !Files.isSymbolicLink(dir)) { - Files.list(dir).forEach(child -> { - try { - recursiveDelete(child); - } catch (Exception e) { - LOGGER.error("[Skyblocker] Encountered an exception while deleting a file! Path: {}", child.toAbsolutePath(), e); - } - }); - } - - Files.delete(dir); - } - /** * Runs the given runnable after the NEU repo is initialized. * @param runnable the runnable to run diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java index f78e5184..460f34dd 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java @@ -3,6 +3,7 @@ package de.hysky.skyblocker.utils.render.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.hysky.skyblocker.mixin.accessor.HandledScreenAccessor; import de.hysky.skyblocker.skyblock.dungeon.CroesusHelper; +import de.hysky.skyblocker.skyblock.dungeon.CroesusProfit; import de.hysky.skyblocker.skyblock.dungeon.terminal.ColorTerminal; import de.hysky.skyblocker.skyblock.dungeon.terminal.OrderTerminal; import de.hysky.skyblocker.skyblock.dungeon.terminal.StartsWithTerminal; @@ -40,6 +41,7 @@ public class ContainerSolverManager { new OrderTerminal(), new StartsWithTerminal(), new CroesusHelper(), + new CroesusProfit(), new ChronomatronSolver(), new SuperpairsSolver(), UltrasequencerSolver.INSTANCE |