From bf64f465a8763fb2bfb5cb679a6f82e831fb62d6 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 1 Jul 2018 15:31:28 +0100 Subject: [PATCH] Re-implement Bukkit 1.7.10 support --- .../common/dependencies/Dependency.java | 7 ++++--- .../common/dependencies/DependencyManager.java | 11 +++++++---- .../dependencies/DependencyRegistry.java | 18 ++++++++++++++++++ .../relocation/RelocationHandler.java | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java index 50be6d8e..db332e96 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.dependencies; +import com.google.common.collect.ImmutableList; import com.google.common.io.ByteStreams; import me.lucko.luckperms.common.dependencies.relocation.Relocation; @@ -238,11 +239,11 @@ public enum Dependency { private static final String MAVEN_CENTRAL_FORMAT = "https://repo1.maven.org/maven2/%s/%s/%s/%s-%s.jar"; Dependency(String groupId, String artifactId, String version, String checksum) { - this(groupId, artifactId, version, checksum, Collections.emptyList()); + this(groupId, artifactId, version, checksum, ImmutableList.of()); } Dependency(String groupId, String artifactId, String version, String checksum, Relocation relocation) { - this(groupId, artifactId, version, checksum, Collections.singletonList(relocation)); + this(groupId, artifactId, version, checksum, ImmutableList.of(relocation)); } Dependency(String groupId, String artifactId, String version, String checksum, List relocations) { @@ -270,7 +271,7 @@ public enum Dependency { this.url = url; this.version = version; this.checksum = Base64.getDecoder().decode(checksum); - this.relocations = relocations; + this.relocations = ImmutableList.copyOf(relocations); } private static String rewriteEscaping(String s) { diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java index aa73242f..89ae1c0b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java @@ -152,7 +152,8 @@ public class DependencyManager { for (Source source : sources) { try { // apply remap rules - List relocations = source.dependency.getRelocations(); + List relocations = new ArrayList<>(source.dependency.getRelocations()); + relocations.addAll(this.registry.getLegacyRelocations(source.dependency)); if (relocations.isEmpty()) { remappedJars.add(source); @@ -221,13 +222,15 @@ public class DependencyManager { // compute a hash for the downloaded file byte[] hash = this.digest.digest(bytes); - this.plugin.getLogger().info("Successfully downloaded '" + fileName + "' with checksum: " + Base64.getEncoder().encodeToString(hash)); - // ensure the hash matches the expected checksum if (!Arrays.equals(hash, dependency.getChecksum())) { - throw new RuntimeException("Downloaded file had an invalid hash. Expected: " + Base64.getEncoder().encodeToString(dependency.getChecksum())); + throw new RuntimeException("Downloaded file had an invalid hash. " + + "Expected: " + Base64.getEncoder().encodeToString(dependency.getChecksum()) + " " + + "Actual: " + Base64.getEncoder().encodeToString(hash)); } + this.plugin.getLogger().info("Successfully downloaded '" + fileName + "' with matching checksum: " + Base64.getEncoder().encodeToString(hash)); + // if the checksum matches, save the content to disk Files.write(file, bytes); } diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyRegistry.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyRegistry.java index 312764de..a75caae9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyRegistry.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyRegistry.java @@ -27,8 +27,11 @@ package me.lucko.luckperms.common.dependencies; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.gson.JsonElement; import me.lucko.luckperms.common.config.ConfigKeys; +import me.lucko.luckperms.common.dependencies.relocation.Relocation; +import me.lucko.luckperms.common.dependencies.relocation.RelocationHandler; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.StorageType; @@ -83,6 +86,21 @@ public class DependencyRegistry { return dependencies; } + // support for LuckPerms legacy (bukkit 1.7.10) + public List getLegacyRelocations(Dependency dependency) { + if (RelocationHandler.DEPENDENCIES.contains(dependency)) { + return ImmutableList.of(); + } + + if (JsonElement.class.getName().startsWith("me.lucko")) { + return ImmutableList.of( + Relocation.of("guava", "com{}google{}common"), + Relocation.of("gson", "com{}google{}gson") + ); + } + return ImmutableList.of(); + } + private static boolean classExists(String className) { try { Class.forName(className); diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/relocation/RelocationHandler.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/relocation/RelocationHandler.java index f4fd1e55..7ac1fb58 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/relocation/RelocationHandler.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/relocation/RelocationHandler.java @@ -43,7 +43,7 @@ import java.util.Set; * Handles class runtime relocation of packages in downloaded dependencies */ public class RelocationHandler { - private static final Set DEPENDENCIES = EnumSet.of(Dependency.ASM, Dependency.ASM_COMMONS, Dependency.JAR_RELOCATOR); + public static final Set DEPENDENCIES = EnumSet.of(Dependency.ASM, Dependency.ASM_COMMONS, Dependency.JAR_RELOCATOR); private static final String JAR_RELOCATOR_CLASS = "me.lucko.jarrelocator.JarRelocator"; private static final String JAR_RELOCATOR_RUN_METHOD = "run";