From 4ba559af13418ce65b443a47ecd5899443fb7970 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman Date: Tue, 29 Oct 2024 23:37:07 +0000 Subject: [PATCH] Use updated utility library --- build.gradle.kts | 2 +- .../plugins/template/file/FileUtil.java | 34 ------------------- .../http/server/HttpServerManager.java | 3 +- .../resourcepack/ResourcePackManager.java | 7 ++-- 4 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/foundation/esoteric/minecraft/plugins/template/file/FileUtil.java diff --git a/build.gradle.kts b/build.gradle.kts index a8c88cb5..94738ab7 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.3.0") + implementation("com.github.EsotericFoundation:utility.kt:0.4.0") implementation("com.github.EsotericFoundation:plugin-library:0.3.0") } diff --git a/src/main/java/foundation/esoteric/minecraft/plugins/template/file/FileUtil.java b/src/main/java/foundation/esoteric/minecraft/plugins/template/file/FileUtil.java deleted file mode 100644 index 03556e29..00000000 --- a/src/main/java/foundation/esoteric/minecraft/plugins/template/file/FileUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package foundation.esoteric.minecraft.plugins.template.file; - -import net.lingala.zip4j.ZipFile; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; - -public class FileUtil { - - private static final String FILE_EXTENSION_SEPARATOR = "."; - - private static final String FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR = "/"; - - public static String getFileExtensionSeparator() { - return FILE_EXTENSION_SEPARATOR; - } - - public static String getFileMimeTypeTypeSubtypeSeparator() { - return FILE_MIME_TYPE_TYPE_SUBTYPE_SEPARATOR; - } - - public static void zipFolder(@NotNull File sourceFolder, File zipFile) throws IOException { - try (ZipFile zipFileInstance = new ZipFile(zipFile)) { - for (File file : sourceFolder.listFiles()) { - if (file.isDirectory()) { - zipFileInstance.addFolder(file); - } else { - zipFileInstance.addFile(file); - } - } - } - } -} diff --git a/src/main/java/foundation/esoteric/minecraft/plugins/template/http/server/HttpServerManager.java b/src/main/java/foundation/esoteric/minecraft/plugins/template/http/server/HttpServerManager.java index c052afae..6a2a78b4 100644 --- a/src/main/java/foundation/esoteric/minecraft/plugins/template/http/server/HttpServerManager.java +++ b/src/main/java/foundation/esoteric/minecraft/plugins/template/http/server/HttpServerManager.java @@ -5,7 +5,6 @@ import com.sun.net.httpserver.HttpServer; import org.bukkit.Bukkit; import foundation.esoteric.minecraft.plugins.template.PaperTemplatePlugin; -import foundation.esoteric.minecraft.plugins.template.file.FileUtil; import foundation.esoteric.minecraft.plugins.template.http.server.event.listeners.PlayerJoinListener; import foundation.esoteric.minecraft.plugins.template.resourcepack.ResourcePackManager; import org.jetbrains.annotations.NotNull; @@ -74,7 +73,7 @@ public void handle(HttpExchange exchange) throws IOException { if (file.exists()) { exchange.getResponseHeaders().set("Content-Type", resourcePackManager.getResourcePackFileMimeType()); - exchange.getResponseHeaders().set("Content-Disposition", "attachment; filename=\"" + resourcePackManager.getResourcePackResourceFolderName() + FileUtil.getFileExtensionSeparator() + resourcePackManager.getResourcePackFileExtension() + "\""); + exchange.getResponseHeaders().set("Content-Disposition", "attachment; filename=\"" + resourcePackManager.getResourcePackResourceFolderName() + "." + resourcePackManager.getResourcePackFileExtension() + "\""); exchange.sendResponseHeaders(successResponseCode, file.length()); diff --git a/src/main/java/foundation/esoteric/minecraft/plugins/template/resourcepack/ResourcePackManager.java b/src/main/java/foundation/esoteric/minecraft/plugins/template/resourcepack/ResourcePackManager.java index d4edba94..ea450b6a 100644 --- a/src/main/java/foundation/esoteric/minecraft/plugins/template/resourcepack/ResourcePackManager.java +++ b/src/main/java/foundation/esoteric/minecraft/plugins/template/resourcepack/ResourcePackManager.java @@ -3,7 +3,6 @@ import foundation.esoteric.utility.file.FileUtility; import org.apache.commons.io.FileUtils; import foundation.esoteric.minecraft.plugins.template.PaperTemplatePlugin; -import foundation.esoteric.minecraft.plugins.template.file.FileUtil; import java.io.File; import java.util.List; @@ -16,7 +15,7 @@ public class ResourcePackManager { private final String resourcePackFileType = "application"; private final String resourcePackFileExtension = "zip"; - private final String resourcePackFileMimeType = resourcePackFileType + FileUtil.getFileMimeTypeTypeSubtypeSeparator() + resourcePackFileExtension; + private final String resourcePackFileMimeType = resourcePackFileType + "/" + resourcePackFileExtension; private final String resourcePackAssetsFolderName = "assets"; @@ -70,11 +69,11 @@ private void saveResourcepackZipFile() { return; } - resourcePackZipFilePath = plugin.getDataPath() + File.separator + resourcePackResourceFolderName + FileUtil.getFileExtensionSeparator() + resourcePackFileExtension; + resourcePackZipFilePath = plugin.getDataPath() + File.separator + resourcePackResourceFolderName + "." + resourcePackFileExtension; try { resourcePackZipFile = new File(resourcePackZipFilePath); - FileUtil.zipFolder(resourcePackFolder, resourcePackZipFile); + FileUtility.Companion.zipFolder(resourcePackFolder, resourcePackZipFile); FileUtils.deleteDirectory(resourcePackFolder); } catch (Exception exception) {