From 0a1fc12e22e789349b95fe7c5444c704b63e1d30 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Tue, 30 May 2023 22:46:59 +0200 Subject: [PATCH] Updated libraries --- build.gradle | 4 +-- .../util/ClassLoaderPriorityUtil.java | 35 ++----------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index b8d4828..1a312d2 100644 --- a/build.gradle +++ b/build.gradle @@ -93,7 +93,7 @@ dependencies { include "com.google.code.gson:gson:2.10.1" include "com.formdev:flatlaf:3.1.1" - include "com.google.guava:guava:31.1-jre" + include "com.google.guava:guava:32.0.0-jre" include "org.apache.commons:commons-lang3:3.12.0" include "commons-io:commons-io:2.12.0" include "net.sf.jopt-simple:jopt-simple:5.0.4" @@ -103,7 +103,7 @@ dependencies { include "net.lenni0451.classtransform:mixinstranslator:1.9.1" include "net.lenni0451.classtransform:mixinsdummy:1.9.1" include "net.lenni0451.classtransform:additionalclassprovider:1.9.1" - include "net.lenni0451:Reflect:1.1.0" + include "net.lenni0451:Reflect:1.2.0" include "net.lenni0451:LambdaEvents:2.0.3" include "net.raphimc.netminecraft:all:2.3.3" include("net.raphimc:MinecraftAuth:2.1.3") { diff --git a/src/main/java/net/raphimc/viaproxy/util/ClassLoaderPriorityUtil.java b/src/main/java/net/raphimc/viaproxy/util/ClassLoaderPriorityUtil.java index a283198..808ce5e 100644 --- a/src/main/java/net/raphimc/viaproxy/util/ClassLoaderPriorityUtil.java +++ b/src/main/java/net/raphimc/viaproxy/util/ClassLoaderPriorityUtil.java @@ -17,13 +17,10 @@ */ package net.raphimc.viaproxy.util; -import net.lenni0451.reflect.Classes; -import net.lenni0451.reflect.stream.RStream; +import net.lenni0451.reflect.ClassLoaders; import net.raphimc.viaproxy.util.logging.Logger; import java.io.File; -import java.net.URL; -import java.util.List; public class ClassLoaderPriorityUtil { @@ -33,7 +30,7 @@ public class ClassLoaderPriorityUtil { for (File file : jarsFolder.listFiles()) { try { if (file.getName().endsWith(".jar")) { - loadWithHighestPriority(file.toURI().toURL()); + ClassLoaders.loadToFront(file.toURI().toURL()); Logger.LOGGER.info("Loaded overriding jar " + file.getName()); } } catch (Throwable e) { @@ -43,32 +40,4 @@ public class ClassLoaderPriorityUtil { } } - private static void loadWithHighestPriority(final URL url) { - // First add the URl into the classpath - final Object ucp = RStream.of(Thread.currentThread().getContextClassLoader()).withSuper().fields().by("ucp").get(); - RStream.of(ucp).methods().by("addURL", URL.class).invokeArgs(url); - - // Then move the URL to the front of the classpath, so it gets loaded first - final List ucpPath = RStream.of(ucp).fields().by("path").get(); - ucpPath.add(0, ucpPath.remove(ucpPath.size() - 1)); - - // Force the ClassLoader to populate the whole list of Loaders (Its lazy loaded by default) - if (ClassLoaderPriorityUtil.class.getClassLoader().getResourceAsStream("I_HOPE_THIS_FILE_NEVER_EXISTS_" + System.nanoTime()) != null) { - throw new IllegalStateException("The file that should never exist exists! Please report this to the ViaProxy developers!"); - } - - // Move the loader for that URL to the front of the list - final Class jarLoaderClazz = Classes.forName(ucp.getClass().getName() + "$JarLoader"); - final List loaders = RStream.of(ucp).fields().by("loaders").get(); - for (Object loader : loaders) { - if (jarLoaderClazz.equals(loader.getClass())) { - final URL loaderUrl = RStream.of(loader).fields().filter(URL.class).by(0).get(); - if (url.equals(loaderUrl)) { - loaders.add(0, loaders.remove(loaders.size() - 1)); - break; - } - } - } - } - }