aboutsummaryrefslogtreecommitdiff
path: root/spark-fabric/src/main/java/me/lucko/spark/fabric
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-02-12 00:32:56 +0000
committerLuck <git@lucko.me>2022-02-12 00:32:56 +0000
commit8bfad57b70746f444c9fe74e6be3d078ae4da247 (patch)
tree6e0e39a70a258221ff48bc1795185f1fc0b561de /spark-fabric/src/main/java/me/lucko/spark/fabric
parentf54a31e9d4756c12836d5e42c31d3d100546533d (diff)
downloadspark-8bfad57b70746f444c9fe74e6be3d078ae4da247.tar.gz
spark-8bfad57b70746f444c9fe74e6be3d078ae4da247.tar.bz2
spark-8bfad57b70746f444c9fe74e6be3d078ae4da247.zip
Improve Sponge and Fabric class source lookups
Diffstat (limited to 'spark-fabric/src/main/java/me/lucko/spark/fabric')
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
index fa59079..7030680 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
@@ -20,25 +20,47 @@
package me.lucko.spark.fabric;
+import com.google.common.collect.ImmutableMap;
+
import me.lucko.spark.common.util.ClassSourceLookup;
import net.fabricmc.loader.api.FabricLoader;
+import net.fabricmc.loader.api.ModContainer;
import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Map;
public class FabricClassSourceLookup extends ClassSourceLookup.ByCodeSource {
private final Path modsDirectory;
+ private final Map<Path, String> pathToModMap;
public FabricClassSourceLookup() {
- this.modsDirectory = FabricLoader.getInstance().getGameDir().resolve("mods").toAbsolutePath().normalize();
+ FabricLoader loader = FabricLoader.getInstance();
+ this.modsDirectory = loader.getGameDir().resolve("mods").toAbsolutePath().normalize();
+ this.pathToModMap = constructPathToModIdMap(loader.getAllMods());
}
@Override
public String identifyFile(Path path) {
+ String id = this.pathToModMap.get(path);
+ if (id != null) {
+ return id;
+ }
+
if (!path.startsWith(this.modsDirectory)) {
return null;
}
return super.identifyFileName(this.modsDirectory.relativize(path).toString());
}
+
+ private static Map<Path, String> constructPathToModIdMap(Collection<ModContainer> mods) {
+ ImmutableMap.Builder<Path, String> builder = ImmutableMap.builder();
+ for (ModContainer mod : mods) {
+ Path path = mod.getRootPath().toAbsolutePath().normalize();
+ builder.put(path, mod.getMetadata().getId());
+ }
+ return builder.build();
+ }
}