mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-11-17 11:19:40 +01:00
Format to Daddy code style
This commit is contained in:
@@ -20,9 +20,6 @@
|
||||
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@@ -31,54 +28,48 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FileUtil
|
||||
{
|
||||
public class FileUtil {
|
||||
|
||||
@Nullable
|
||||
public static <T> Class<? extends T> findClass(@NotNull final File file, @NotNull final Class<T> clazz) throws IOException, ClassNotFoundException
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Nullable
|
||||
public static <T> Class<? extends T> findClass(@NotNull final File file,
|
||||
@NotNull final Class<T> clazz) throws IOException, ClassNotFoundException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final URL jar = file.toURI().toURL();
|
||||
final URL jar = file.toURI().toURL();
|
||||
|
||||
final List<String> matches = new ArrayList<>();
|
||||
final List<Class<? extends T>> classes = new ArrayList<>();
|
||||
final List<String> matches = new ArrayList<>();
|
||||
final List<Class<? extends T>> classes = new ArrayList<>();
|
||||
|
||||
try (final JarInputStream stream = new JarInputStream(
|
||||
jar.openStream()); final URLClassLoader loader = new URLClassLoader(new URL[]{jar},
|
||||
clazz.getClassLoader())) {
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null) {
|
||||
final String name = entry.getName();
|
||||
if (name == null || name.isEmpty() || !name.endsWith(".class")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (final JarInputStream stream = new JarInputStream(jar.openStream()); final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()))
|
||||
{
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null)
|
||||
{
|
||||
final String name = entry.getName();
|
||||
if (name == null || name.isEmpty() || !name.endsWith(".class"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
}
|
||||
|
||||
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
}
|
||||
for (final String match : matches) {
|
||||
try {
|
||||
final Class<?> loaded = loader.loadClass(match);
|
||||
if (clazz.isAssignableFrom(loaded)) {
|
||||
classes.add(loaded.asSubclass(clazz));
|
||||
}
|
||||
} catch (final NoClassDefFoundError ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final String match : matches)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Class<?> loaded = loader.loadClass(match);
|
||||
if (clazz.isAssignableFrom(loaded))
|
||||
{
|
||||
classes.add(loaded.asSubclass(clazz));
|
||||
}
|
||||
}
|
||||
catch (final NoClassDefFoundError ignored)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
return classes.isEmpty() ? null : classes.get(0);
|
||||
}
|
||||
return classes.isEmpty() ? null : classes.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user