From cfb298f69baf84f627b5881f8e65183fda1e0f17 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 8 Jul 2021 22:53:43 +0100 Subject: [PATCH] Use different classifier for dependency files with Bukkit-Legacy remappings --- .../lucko/luckperms/common/dependencies/Dependency.java | 9 +++++++-- .../luckperms/common/dependencies/DependencyManager.java | 4 ++-- .../common/dependencies/DependencyRegistry.java | 7 ++++++- 3 files changed, 15 insertions(+), 5 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 b9eb0dad9..18d645154 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 @@ -313,8 +313,13 @@ public enum Dependency { return s.replace("{}", "."); } - public String getFileName() { - return name().toLowerCase().replace('_', '-') + "-" + this.version; + public String getFileName(String classifier) { + String name = name().toLowerCase().replace('_', '-'); + String extra = classifier == null || classifier.isEmpty() + ? "" + : "-" + classifier; + + return name + "-" + this.version + extra + ".jar"; } String getMavenRepoPath() { 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 7cbee16a8..696ec8094 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 @@ -155,7 +155,7 @@ public class DependencyManager { } private Path downloadDependency(Dependency dependency) throws DependencyDownloadException { - Path file = this.cacheDirectory.resolve(dependency.getFileName() + ".jar"); + Path file = this.cacheDirectory.resolve(dependency.getFileName(null)); // if the file already exists, don't attempt to re-download it. if (Files.exists(file)) { @@ -185,7 +185,7 @@ public class DependencyManager { return normalFile; } - Path remappedFile = this.cacheDirectory.resolve(dependency.getFileName() + "-remapped.jar"); + Path remappedFile = this.cacheDirectory.resolve(dependency.getFileName(DependencyRegistry.isGsonRelocated() ? "remapped-legacy" : "remapped")); // if the remapped source exists already, just use that. if (Files.exists(remappedFile)) { 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 3f6698b30..0be355473 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 @@ -99,7 +99,7 @@ public class DependencyRegistry { Platform.Type type = this.plugin.getBootstrap().getType(); // support for LuckPerms legacy (bukkit 1.7.10) - if (!RelocationHandler.DEPENDENCIES.contains(dependency) && JsonElement.class.getName().startsWith("me.lucko")) { + if (!RelocationHandler.DEPENDENCIES.contains(dependency) && isGsonRelocated()) { relocations.add(Relocation.of("guava", "com{}google{}common")); relocations.add(Relocation.of("gson", "com{}google{}gson")); } @@ -125,6 +125,11 @@ public class DependencyRegistry { } } + @SuppressWarnings("ConstantConditions") + public static boolean isGsonRelocated() { + return JsonElement.class.getName().startsWith("me.lucko"); + } + private static boolean classExists(String className) { try { Class.forName(className);