Skip to content

Commit

Permalink
Update utility dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Oct 28, 2024
1 parent 92b0842 commit 90d3b9a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -31,43 +25,6 @@ public static String getFileMimeTypeTypeSubtypeSeparator() {
return FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR;
}

public static List<String> 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<String> 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<String> getResourceFileFolderResourceFilePathsRecursively(String resourceFileFolderPath) throws IOException {
List<String> paths = new ArrayList<>();

for (String resourceFilePath : getResourceFileFolderResourceFilePaths(resourceFileFolderPath)) {
List<String> 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()) {
Expand Down

0 comments on commit 90d3b9a

Please sign in to comment.