diff --git a/build.gradle.kts b/build.gradle.kts index 7e38b7ad..b934bee8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -102,7 +102,7 @@ dependencies { implementation("dev.jorel", "commandapi-bukkit-shade-mojang-mapped", "9.5.3") implementation("net.lingala.zip4j", "zip4j", "2.11.5") - implementation("com.github.EsotericFoundation:utility.kt:0.0.4") + implementation("com.github.EsotericFoundation:utility.kt:0.1.0") } tasks { diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/file/FileManager.java b/src/main/java/org/esoteric/minecraft/plugins/template/file/FileManager.java index ef06b52a..fa64c4ca 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/file/FileManager.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/file/FileManager.java @@ -1,9 +1,9 @@ package org.esoteric.minecraft.plugins.template.file; +import foundation.esoteric.utility.resource.ResourceUtility; import org.esoteric.minecraft.plugins.template.PaperTemplatePlugin; import java.io.File; -import java.io.IOException; public class FileManager { @@ -14,15 +14,8 @@ public FileManager(PaperTemplatePlugin plugin) { } public File saveResourceFileFolder(String resourceFileFolderPath, boolean shouldReplaceExistingFiles) { - try { - FileUtil.getResourceFileFolderResourceFilePathsRecursively(resourceFileFolderPath).forEach((resourceFilePath) -> { - plugin.saveResource(resourceFilePath, shouldReplaceExistingFiles); - }); - return new File(plugin.getDataPath() + File.separator + resourceFileFolderPath); - } catch (IOException exception) { - exception.printStackTrace(); - return null; - } + ResourceUtility.Companion.getResourceFilePaths(resourceFileFolderPath).forEach((resourceFilePath) -> plugin.saveResource(resourceFilePath.toString(), shouldReplaceExistingFiles)); + return new File(plugin.getDataPath() + File.separator + resourceFileFolderPath); } public File saveResourceFileFolder(String resourceFileFolderPath) { diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/file/FileUtil.java b/src/main/java/org/esoteric/minecraft/plugins/template/file/FileUtil.java index 86d49fbc..91dd279c 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/file/FileUtil.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/file/FileUtil.java @@ -8,14 +8,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; public class FileUtil { @@ -31,43 +25,6 @@ public static String getFileMimeTypeTypeSubtypeSeparator() { return FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR; } - public static List getResourceFileFolderResourceFilePaths(String resourceFileFolderPath) throws IOException { - ClassLoader classLoader = FileUtil.class.getClassLoader(); - - URL jarURL = classLoader.getResource(resourceFileFolderPath); - if (jarURL == null) { - return Collections.emptyList(); - } - - String jarPath = jarURL.getPath(); - int exclamationMarkIndex = jarPath.indexOf("!"); - - String jarPathPrefix = "file:"; - String jarFilePath = jarPath.substring(jarPathPrefix.length(), exclamationMarkIndex); - - try (JarFile jarFile = new JarFile(jarFilePath)) { - List paths = jarFile.stream().map(JarEntry::getName).filter(name -> name.startsWith(resourceFileFolderPath) && !name.equals(resourceFileFolderPath)) - .map(name -> name.substring(resourceFileFolderPath.length())).filter(name -> !"/".equals(name)).map(name -> resourceFileFolderPath + name).toList(); - - return paths; - } - } - - public static @NotNull List getResourceFileFolderResourceFilePathsRecursively(String resourceFileFolderPath) throws IOException { - List paths = new ArrayList<>(); - - for (String resourceFilePath : getResourceFileFolderResourceFilePaths(resourceFileFolderPath)) { - List subFiles = getResourceFileFolderResourceFilePathsRecursively(resourceFilePath); - if (subFiles.isEmpty()) { - paths.add(resourceFilePath); - } else { - paths.addAll(subFiles); - } - } - - return paths; - } - public static void zipFolder(@NotNull File sourceFolder, File zipFile) throws IOException { try (ZipFile zipFileInstance = new ZipFile(zipFile)) { for (File file : sourceFolder.listFiles()) {