mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-11 20:47:31 +00:00
* Fix ClassCastException * Support Fabric for 1.14.1 * Support Fabric for 1.14.1 * Use mapping file instead of hard code
35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
package customskinloader.utils;
|
|
|
|
import java.io.File;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URLClassLoader;
|
|
import java.util.LinkedList;
|
|
|
|
public class JavaUtil {
|
|
public static URL[] getClasspath() {
|
|
if (JavaUtil.class.getClassLoader() instanceof URLClassLoader) {
|
|
//Java 8-
|
|
//Use URLClassLoader Directly
|
|
URLClassLoader ucl = (URLClassLoader) JavaUtil.class.getClassLoader();
|
|
return ucl.getURLs();
|
|
} else {
|
|
//Java 9+
|
|
//It uses APPClassLoader instead of URLClassLoader
|
|
//Get Classpath from properties and parse it to URL array
|
|
String classpath = System.getProperty("java.class.path");
|
|
String[] elements = classpath.split(File.pathSeparator);
|
|
if (elements.length == 0)
|
|
return new URL[0];
|
|
LinkedList<URL> urls = new LinkedList<URL>();
|
|
for (String ele : elements) {
|
|
try {
|
|
urls.add(new URL(ele));
|
|
} catch (Exception ignored) {
|
|
}
|
|
}
|
|
return urls.toArray(new URL[0]);
|
|
}
|
|
}
|
|
}
|