use of org.bukkit.plugin.java.PluginClassLoader in project Glowstone by GlowstoneMC.
the class LinkstonePluginLoader method newPluginLoader.
@Override
protected PluginClassLoader newPluginLoader(JavaPluginLoader loader, ClassLoader parent, PluginDescriptionFile description, File dataFolder, File file, ClassLoader libraryLoader) throws Exception {
return new PluginClassLoader(loader, parent, description, dataFolder, file, libraryLoader) {
@Override
protected byte[] transformBytecode(byte[] bytecode) {
if (LinkstoneRuntimeData.getFields().isEmpty() && LinkstoneRuntimeData.getBoxes().isEmpty()) {
// so there's no need for runtime support
return bytecode;
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = cw;
cv = new DirectFieldAccessReplaceVisitor(LinkstoneRuntimeData.getFields(), cv);
if (!FieldAccessorUtility.isSupported() || !MethodAccessorUtility.isSupported()) {
cv = new ReflectionReplaceVisitor(cv);
}
cv = new ClassInitInvokeVisitor(cv);
cv = new BoxPatchVisitor(LinkstoneRuntimeData.getBoxes(), cv);
new ClassReader(bytecode).accept(cv, 0);
return cw.toByteArray();
}
};
}
Aggregations