From 8776ae65b4f7f935e3abbd842c0c8e6f9cc4038d Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 31 May 2025 19:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81remap=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/plugin/dependency/Dependencies.java | 21 ++++++++++++++++++- .../core/plugin/dependency/Dependency.java | 16 ++++++++++++++ .../dependency/DependencyManagerImpl.java | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java index a7e7a1b58..61b0db93f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java @@ -1,9 +1,19 @@ package net.momirealms.craftengine.core.plugin.dependency; +import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.Collections; import java.util.List; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; public class Dependencies { @@ -176,7 +186,16 @@ public class Dependencies { "commons-imaging", "org{}apache{}commons", "commons-imaging", - List.of(Relocation.of("commons", "org{}apache{}commons")) + List.of(Relocation.of("commons", "org{}apache{}commons")), + (p) -> { + try (JarFile jarFile = new JarFile(p.toFile())) { + ZipEntry entry = jarFile.getEntry("net/momirealms/craftengine/libraries/commons/imaging/Imaging.class"); + return entry != null; + } catch (IOException e) { + CraftEngine.instance().logger().warn("Error reading jar file", e); + return false; + } + } ); public static final Dependency BYTE_BUDDY = new Dependency( diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependency.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependency.java index 6dd449cb9..893716bac 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependency.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependency.java @@ -3,21 +3,37 @@ package net.momirealms.craftengine.core.plugin.dependency; import net.momirealms.craftengine.core.plugin.PluginProperties; import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation; +import java.nio.file.Path; import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.function.Predicate; public class Dependency { private final String id; private final String groupId; private final String rawArtifactId; private final List relocations; + private final Predicate verifier; public Dependency(String id, String groupId, String artifactId, List relocations) { this.id = id; this.groupId = groupId; this.rawArtifactId = artifactId; this.relocations = relocations; + this.verifier = (p) -> true; + } + + public Dependency(String id, String groupId, String artifactId, List relocations, Predicate verifier) { + this.id = id; + this.groupId = groupId; + this.rawArtifactId = artifactId; + this.relocations = relocations; + this.verifier = verifier; + } + + public boolean verify(Path remapped) { + return this.verifier.test(remapped); } public String id() { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/DependencyManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/DependencyManagerImpl.java index a6ecf30a3..886f830d2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/DependencyManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/DependencyManagerImpl.java @@ -168,7 +168,7 @@ public class DependencyManagerImpl implements DependencyManager { Path remappedFile = this.cacheDirectory.resolve(dependency.toLocalPath()).resolve(dependency.fileName(DependencyRegistry.isGsonRelocated() ? "remapped-legacy" : "remapped")); // if the remapped source exists already, just use that. - if (Files.exists(remappedFile)) { + if (Files.exists(remappedFile) && dependency.verify(remappedFile)) { return remappedFile; }