Search in sources :

Example 1 with BoxPatchVisitor

use of net.glowstone.linkstone.runtime.boxing.BoxPatchVisitor 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();
        }
    };
}
Also used : BoxPatchVisitor(net.glowstone.linkstone.runtime.boxing.BoxPatchVisitor) DirectFieldAccessReplaceVisitor(net.glowstone.linkstone.runtime.direct.DirectFieldAccessReplaceVisitor) ClassInitInvokeVisitor(net.glowstone.linkstone.runtime.inithook.ClassInitInvokeVisitor) ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) ReflectionReplaceVisitor(net.glowstone.linkstone.runtime.reflectionreplace.ReflectionReplaceVisitor) ClassWriter(org.objectweb.asm.ClassWriter) PluginClassLoader(org.bukkit.plugin.java.PluginClassLoader)

Aggregations

BoxPatchVisitor (net.glowstone.linkstone.runtime.boxing.BoxPatchVisitor)1 DirectFieldAccessReplaceVisitor (net.glowstone.linkstone.runtime.direct.DirectFieldAccessReplaceVisitor)1 ClassInitInvokeVisitor (net.glowstone.linkstone.runtime.inithook.ClassInitInvokeVisitor)1 ReflectionReplaceVisitor (net.glowstone.linkstone.runtime.reflectionreplace.ReflectionReplaceVisitor)1 PluginClassLoader (org.bukkit.plugin.java.PluginClassLoader)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1