Use different classifier for dependency files with Bukkit-Legacy remappings

This commit is contained in:
Luck 2021-07-08 22:53:43 +01:00
parent 563b5be9b2
commit cfb298f69b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 15 additions and 5 deletions

View File

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

View File

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

View File

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