mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-13 07:09:51 +01:00
Style and stream cleanup
This commit is contained in:
parent
79a8f4bd93
commit
3b5d066f44
@ -22,20 +22,25 @@ public abstract class HierarchyClassLoader extends URLClassLoader {
|
||||
children.add(loader);
|
||||
}
|
||||
|
||||
public InputStream getResourceAsStreamWithChildren(String name) {
|
||||
public InputStream getResourceAsStreamWithChildren(@NotNull String name) {
|
||||
InputStream in = getResourceAsStream(name);
|
||||
if(in != null) return in;
|
||||
if (in != null) return in;
|
||||
|
||||
for(MinestomExtensionClassLoader child : children) {
|
||||
for (MinestomExtensionClassLoader child : children) {
|
||||
InputStream childInput = child.getResourceAsStreamWithChildren(name);
|
||||
if(childInput != null)
|
||||
if (childInput != null)
|
||||
return childInput;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeChildInHierarchy(MinestomExtensionClassLoader child) {
|
||||
children.remove(child);
|
||||
children.forEach(c -> c.removeChildInHierarchy(child));
|
||||
|
||||
// Also remove all children from these extension's children.
|
||||
for (MinestomExtensionClassLoader subChild : children) {
|
||||
subChild.removeChildInHierarchy(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,14 @@ public class MinestomExtensionClassLoader extends HierarchyClassLoader {
|
||||
* @see MinestomRootClassLoader#loadBytes(String, boolean) for more information
|
||||
*/
|
||||
protected boolean isMainExtensionClass(String name) {
|
||||
if(mainClassName.equals(name))
|
||||
|
||||
if (mainClassName.equals(name))
|
||||
return true;
|
||||
return children.stream().anyMatch(c -> c.isMainExtensionClass(name));
|
||||
|
||||
for (MinestomExtensionClassLoader child : children) {
|
||||
if (child.isMainExtensionClass(name)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.objectweb.asm.tree.ClassNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -220,9 +219,8 @@ public class MinestomRootClassLoader extends HierarchyClassLoader {
|
||||
return originalBytes;
|
||||
}
|
||||
|
||||
public byte[] loadBytesWithChildren(String name, boolean transform) throws IOException, ClassNotFoundException {
|
||||
if (name == null)
|
||||
throw new ClassNotFoundException();
|
||||
public byte[] loadBytesWithChildren(@NotNull String name, boolean transform) throws IOException, ClassNotFoundException {
|
||||
|
||||
String path = name.replace(".", "/") + ".class";
|
||||
InputStream input = getResourceAsStreamWithChildren(path);
|
||||
if (input == null) {
|
||||
@ -298,11 +296,7 @@ public class MinestomRootClassLoader extends HierarchyClassLoader {
|
||||
}
|
||||
return true;
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
if(MinecraftServer.getExceptionManager() != null) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -336,7 +330,7 @@ public class MinestomRootClassLoader extends HierarchyClassLoader {
|
||||
@Nullable
|
||||
public static String findExtensionObjectOwner(@NotNull Object obj) {
|
||||
ClassLoader cl = obj.getClass().getClassLoader();
|
||||
if(cl instanceof MinestomExtensionClassLoader) {
|
||||
if (cl instanceof MinestomExtensionClassLoader) {
|
||||
return ((MinestomExtensionClassLoader) cl).getExtensionName();
|
||||
}
|
||||
return null;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.extras.selfmodification.mixins;
|
||||
|
||||
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual;
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
@ -64,7 +65,7 @@ public class MixinServiceMinestom extends MixinServiceAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
public InputStream getResourceAsStream(@NotNull String name) {
|
||||
return classLoader.getResourceAsStreamWithChildren(name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user