diff --git a/src/main/java/xyz/spruceloader/trunk/MainClient.java b/src/main/java/xyz/spruceloader/trunk/MainClient.java index ace89ae..49a1a53 100644 --- a/src/main/java/xyz/spruceloader/trunk/MainClient.java +++ b/src/main/java/xyz/spruceloader/trunk/MainClient.java @@ -11,6 +11,9 @@ public static void main(String[] args) { argMap.putIfAbsent("accessToken", "None"); argMap.putIfAbsent("version", "Unknown"); argMap.putIfAbsent("gameDir", Paths.get(".").normalize().toString()); - new Trunk().initialize(argMap, EnvSide.CLIENT); + + Trunk trunk = new Trunk(); + trunk.initialize(argMap, EnvSide.CLIENT); + trunk.getClassLoader().addDefaultLoadingFilters(); } } diff --git a/src/main/java/xyz/spruceloader/trunk/MainServer.java b/src/main/java/xyz/spruceloader/trunk/MainServer.java index d2003b6..6ab3ff5 100644 --- a/src/main/java/xyz/spruceloader/trunk/MainServer.java +++ b/src/main/java/xyz/spruceloader/trunk/MainServer.java @@ -9,6 +9,9 @@ public static void main(String[] args) { argMap.remove("version"); argMap.remove("gameDir"); argMap.remove("assetsDir"); - new Trunk().initialize(argMap, EnvSide.SERVER); + + Trunk trunk = new Trunk(); + trunk.initialize(argMap, EnvSide.SERVER); + trunk.getClassLoader().addDefaultLoadingFilters(); } } diff --git a/src/main/java/xyz/spruceloader/trunk/Trunk.java b/src/main/java/xyz/spruceloader/trunk/Trunk.java index 70b5bca..dbf41f3 100644 --- a/src/main/java/xyz/spruceloader/trunk/Trunk.java +++ b/src/main/java/xyz/spruceloader/trunk/Trunk.java @@ -11,6 +11,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -35,11 +36,12 @@ public Trunk() { } catch (Throwable t) { return null; } - }).filter(Objects::nonNull).collect(Collectors.toList()).toArray(URL[]::new), getClass().getClassLoader()); + }).filter(Objects::nonNull).collect(Collectors.toList()).toArray(new URL[0]), getClass().getClassLoader()); transformerManager = new TransformerManager(); Thread.currentThread().setContextClassLoader(classLoader); GLOBAL_PROPERTIES.put("trunk.development", DEVELOPMENT); } + public void initialize(ArgumentMap argMap, EnvSide env) { LOGGER.info("Launching Minecraft with Spruce Trunk"); diff --git a/src/main/java/xyz/spruceloader/trunk/TrunkClassLoader.java b/src/main/java/xyz/spruceloader/trunk/TrunkClassLoader.java index 55bd620..f3c6652 100644 --- a/src/main/java/xyz/spruceloader/trunk/TrunkClassLoader.java +++ b/src/main/java/xyz/spruceloader/trunk/TrunkClassLoader.java @@ -30,6 +30,19 @@ public void addPath(Path path) { } } + /** + * Adds the default loading filters. This is subject to change! + */ + public void addDefaultLoadingFilters() { + addPackageLoadingFilter("java"); + addPackageLoadingFilter("jdk"); + addPackageLoadingFilter("javax"); + addPackageLoadingFilter("sun"); + addPackageLoadingFilter("com.sun"); + addPackageLoadingFilter("org.apache.logging.log4j"); + addPackageLoadingFilter("org.slf4j"); + } + /** * Adds a loading filter - returns true to filter the class. * @@ -130,7 +143,7 @@ private byte[] transformClassBytes(String name, byte[] bytes) { } private byte[] getClassBytes(String name) throws IOException { - try (InputStream in = getResourceAsStream(name)) { + try (InputStream in = getResourceAsStream(name.replace(".", "/").concat(".class"))) { if (in == null) return null; diff --git a/src/main/java/xyz/spruceloader/trunk/api/TransformerManager.java b/src/main/java/xyz/spruceloader/trunk/api/TransformerManager.java index 304aae7..046d7f8 100644 --- a/src/main/java/xyz/spruceloader/trunk/api/TransformerManager.java +++ b/src/main/java/xyz/spruceloader/trunk/api/TransformerManager.java @@ -9,6 +9,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class TransformerManager implements Iterable { @@ -44,8 +45,9 @@ private void handleFromNamespaces(ArgumentMap argMap, String argName, String pro argValues.forEach(name -> transformers.add(fromName(name))); String prop = System.getProperty(propName); + if (prop != null) { - List propValues = Arrays.stream(prop.split("/")).toList(); + List propValues = Arrays.stream(prop.split("/")).collect(Collectors.toList()); if (!propValues.isEmpty()) propValues.forEach(name -> transformers.add(fromName(name))); }