11package org .embeddedt .modernfix .forge .classloading ;
22
3- import com .google .common .base .Joiner ;
4- import com .google .common .collect .*;
3+ import com .google .common .collect .ImmutableMultimap ;
4+ import com .google .common .collect .Iterators ;
5+ import com .google .common .collect .Multimap ;
56import net .minecraftforge .fml .loading .FMLLoader ;
67import net .minecraftforge .fml .loading .LoadingModList ;
7- import net .minecraftforge .fml .loading .moddiscovery .*;
8+ import net .minecraftforge .fml .loading .moddiscovery .AbstractJarFileLocator ;
9+ import net .minecraftforge .fml .loading .moddiscovery .ExplodedDirectoryLocator ;
10+ import net .minecraftforge .fml .loading .moddiscovery .ModFile ;
11+ import net .minecraftforge .fml .loading .moddiscovery .ModFileInfo ;
812import net .minecraftforge .forgespi .locating .IModFile ;
913import net .minecraftforge .forgespi .locating .IModLocator ;
1014import org .apache .commons .lang3 .tuple .Pair ;
1115import org .apache .logging .log4j .LogManager ;
1216import org .apache .logging .log4j .Logger ;
17+ import org .embeddedt .modernfix .resources .CachedResourcePath ;
18+ import org .embeddedt .modernfix .util .FileUtil ;
1319
1420import java .io .IOException ;
1521import java .lang .reflect .Field ;
1925import java .nio .file .Files ;
2026import java .nio .file .Path ;
2127import java .util .*;
22- import java .util .regex .Pattern ;
2328import java .util .stream .Stream ;
2429
2530public class ModernFixResourceFinder {
26- private static Multimap <String , String > urlsForClass = null ;
31+ private static Multimap <CachedResourcePath , String > urlsForClass = null ;
2732 private static final Class <? extends IModLocator > MINECRAFT_LOCATOR ;
2833 private static Field explodedDirModsField = null ;
2934 private static final Logger LOGGER = LogManager .getLogger ("ModernFixResourceFinder" );
@@ -36,11 +41,10 @@ public class ModernFixResourceFinder {
3641 }
3742 }
3843
39- private static final Joiner SLASH_JOINER = Joiner .on ('/' );
40-
4144 public static synchronized void init () throws ReflectiveOperationException {
42- ImmutableMultimap .Builder <String , String > urlBuilder = ImmutableMultimap .builder ();
43- Interner <String > pathInterner = Interners .newStrongInterner ();
45+ // Make sure FileUtil is classloaded now to avoid issues
46+ FileUtil .normalize ("" );
47+ ImmutableMultimap .Builder <CachedResourcePath , String > urlBuilder = ImmutableMultimap .builder ();
4448 //LOGGER.info("Start building list of class locations...");
4549 for (ModFileInfo fileInfo : LoadingModList .get ().getModFiles ()) {
4650 ModFile file = fileInfo .getFile ();
@@ -53,8 +57,8 @@ public static synchronized void init() throws ReflectiveOperationException {
5357 stream
5458 .map (root ::relativize )
5559 .forEach (path -> {
56- String strPath = pathInterner . intern ( SLASH_JOINER . join ( path ) );
57- urlBuilder .put (strPath , fileInfo .getMods ().get (0 ).getModId ());
60+ CachedResourcePath p = new CachedResourcePath ( CachedResourcePath . NO_PREFIX , path );
61+ urlBuilder .put (p , fileInfo .getMods ().get (0 ).getModId ());
5862 });
5963 } catch (IOException e ) {
6064 throw new RuntimeException (e );
@@ -87,12 +91,11 @@ private static Iterable<Path> getRootPathForLocator(IModLocator locator, ModFile
8791 throw new UnsupportedOperationException ("Unknown ModLocator type: " + locator .getClass ().getName ());
8892 }
8993
90- private static final Pattern SLASH_REPLACER = Pattern .compile ("/+" );
91-
9294 public static Enumeration <URL > findAllURLsForResource (String input ) {
93- String pathInput = SLASH_REPLACER . matcher ( input ). replaceAll ( "/" );
94- Collection <String > urlList = urlsForClass .get (pathInput );
95+ // CachedResourcePath normalizes already
96+ Collection <String > urlList = urlsForClass .get (new CachedResourcePath ( input ) );
9597 if (!urlList .isEmpty ()) {
98+ String pathInput = FileUtil .normalize (input );
9699 return Iterators .asEnumeration (urlList .stream ().map (modId -> {
97100 try {
98101 return new URL ("modjar://" + modId + "/" + pathInput );
0 commit comments