From b7289893552a958609e1827be2ce0549f330b260 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Sun, 1 Nov 2020 20:56:45 +0100 Subject: [PATCH] Refactor Jars to ThirdPartyManager --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 6 +++--- .../{Jars.java => ThirdPartyManager.java} | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) rename worldedit-core/src/main/java/com/boydti/fawe/util/{Jars.java => ThirdPartyManager.java} (81%) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index d8006bbc6..7079aea51 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -21,7 +21,7 @@ import com.boydti.fawe.bukkit.util.ItemUtil; import com.boydti.fawe.bukkit.util.image.BukkitImageViewer; import com.boydti.fawe.config.Settings; import com.boydti.fawe.regions.FaweMaskManager; -import com.boydti.fawe.util.Jars; +import com.boydti.fawe.util.ThirdPartyManager; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.image.ImageViewer; @@ -123,7 +123,7 @@ public class FaweBukkit implements IFawe, Listener { if (manager.getPlugin("PacketListenerApi") == null) { File output = new File(plugin.getDataFolder().getParentFile(), "PacketListenerAPI_v3.7.6-SNAPSHOT.jar"); - byte[] jarData = Jars.PL_v3_7_6.download(); + byte[] jarData = ThirdPartyManager.PacketListenerAPI.download(); try (FileOutputStream fos = new FileOutputStream(output)) { fos.write(jarData); } @@ -131,7 +131,7 @@ public class FaweBukkit implements IFawe, Listener { if (manager.getPlugin("MapManager") == null) { File output = new File(plugin.getDataFolder().getParentFile(), "MapManager_v1.7.8-SNAPSHOT.jar"); - byte[] jarData = Jars.MM_v1_7_8.download(); + byte[] jarData = ThirdPartyManager.MapManager.download(); try (FileOutputStream fos = new FileOutputStream(output)) { fos.write(jarData); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/Jars.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ThirdPartyManager.java similarity index 81% rename from worldedit-core/src/main/java/com/boydti/fawe/util/Jars.java rename to worldedit-core/src/main/java/com/boydti/fawe/util/ThirdPartyManager.java index 2fffb90ad..19e8ecddc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/Jars.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ThirdPartyManager.java @@ -9,15 +9,14 @@ import java.util.Base64; import static org.slf4j.LoggerFactory.getLogger; -//TODO: Look into renaming this class or moving to a new package. /** An internal FAWE class not meant for public use. **/ -public enum Jars { +public enum ThirdPartyManager { - MM_v1_7_8( + MapManager( "https://github.com/InventivetalentDev/MapManager/releases/download/1.7.8-SNAPSHOT/MapManager_v1.7.8-SNAPSHOT.jar", "m3YLUqZz66k2DmvdcYLeu38u3zKRKhrAXqGGpVKfO6g=", 544000), - PL_v3_7_6( + PacketListenerAPI( "https://github.com/InventivetalentDev/PacketListenerAPI/releases/download/3.7.6-SNAPSHOT/PacketListenerAPI_v3.7.6-SNAPSHOT.jar", "etdBRzLn5pRVDfr/mSQdPm6Jjer3wQOKhcn8fUxo5zM=", 143000), @@ -32,7 +31,7 @@ public enum Jars { * @param digest The Base64-encoded SHA-256 digest * @param fileSize Size of this jar in bytes */ - Jars(String url, String digest, int fileSize) { + ThirdPartyManager(String url, String digest, int fileSize) { this.url = url; this.digest = digest; this.fileSize = fileSize; @@ -47,7 +46,7 @@ public enum Jars { try (DataInputStream dis = new DataInputStream(url.openConnection().getInputStream())) { dis.readFully(jarBytes); if (dis.read() != -1) { // assert that we've read everything - throw new IllegalStateException("downloaded jar is longer than expected"); + throw new IllegalStateException("Downloaded jar is longer than expected"); } MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] jarDigestBytes = md.digest(jarBytes); @@ -55,12 +54,12 @@ public enum Jars { String jarDigest = Base64.getEncoder().encodeToString(jarDigestBytes); if (this.digest.equals(jarDigest)) { - getLogger(Jars.class).debug("++++ HASH CHECK ++++"); - getLogger(Jars.class).debug(this.url); - getLogger(Jars.class).debug(this.digest); + getLogger(ThirdPartyManager.class).debug("++++ HASH CHECK ++++"); + getLogger(ThirdPartyManager.class).debug(this.url); + getLogger(ThirdPartyManager.class).debug(this.digest); return jarBytes; } else { - getLogger(Jars.class).debug(jarDigest + " | " + url); + getLogger(ThirdPartyManager.class).debug(jarDigest + " | " + url); throw new IllegalStateException("The downloaded jar does not match the hash"); } } catch (NoSuchAlgorithmException e) {