mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-09 20:38:07 +02:00
Re-implement Bukkit 1.7.10 support
This commit is contained in:
parent
c1e0b874d8
commit
bf64f465a8
@ -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<Relocation> 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) {
|
||||
|
@ -152,7 +152,8 @@ public class DependencyManager {
|
||||
for (Source source : sources) {
|
||||
try {
|
||||
// apply remap rules
|
||||
List<Relocation> relocations = source.dependency.getRelocations();
|
||||
List<Relocation> 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);
|
||||
}
|
||||
|
@ -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<Relocation> 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);
|
||||
|
@ -43,7 +43,7 @@ import java.util.Set;
|
||||
* Handles class runtime relocation of packages in downloaded dependencies
|
||||
*/
|
||||
public class RelocationHandler {
|
||||
private static final Set<Dependency> DEPENDENCIES = EnumSet.of(Dependency.ASM, Dependency.ASM_COMMONS, Dependency.JAR_RELOCATOR);
|
||||
public static final Set<Dependency> 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";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user