Refactor Jars to ThirdPartyManager

This commit is contained in:
N0tMyFaultOG 2020-11-01 20:56:45 +01:00
parent 781c1e943b
commit b728989355
2 changed files with 12 additions and 13 deletions

View File

@ -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);
}

View File

@ -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) {