diff --git a/pom.xml b/pom.xml index 1e58f04..529ccd0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.55 + 4.56 UTF-8 diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java index 3be025e..b58055c 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java @@ -24,7 +24,7 @@ public class SimpleClassVisitor extends ClassVisitor { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - super.visit(version, access, name, signature, translate(superName), translate(interfaces)); + super.visit(version, access, name, translate(signature), translate(superName), translate(interfaces)); } @Override diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java index c9b6a8c..ab458db 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java @@ -21,9 +21,14 @@ public class SimpleMethodVisitor extends MethodVisitor { this.simpleVersionControl = simpleVersionControl; } + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor) { + super.visitMethodInsn(opcode, translate(owner), translate(name), translate(descriptor)); + } + @Override public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { - super.visitMethodInsn(opcode, translate(owner), name, translate(descriptor), isInterface); + super.visitMethodInsn(opcode, translate(owner), translate(name), translate(descriptor), isInterface); } @Override @@ -43,7 +48,7 @@ public class SimpleMethodVisitor extends MethodVisitor { @Override public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) { - super.visitLocalVariable(name, translate(descriptor), translate(signature), start, end, index); + super.visitLocalVariable(translate(name), translate(descriptor), translate(signature), start, end, index); } private String translate(String target) { diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java index 1f020cb..8f4444d 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java @@ -11,8 +11,9 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import java.io.IOException; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @Author sky @@ -20,12 +21,15 @@ import java.util.List; */ public class SimpleVersionControl { + private static Map> cacheClasses = new HashMap<>(); private String target; - private List from = Lists.newArrayList(); private String to; + private List from = Lists.newArrayList(); private Plugin plugin; + private boolean useCache; SimpleVersionControl() { + useCache = false; } public static SimpleVersionControl create() { @@ -61,18 +65,30 @@ public class SimpleVersionControl { return this; } + public SimpleVersionControl useCache() { + this.useCache = true; + return this; + } + public Class translate() throws IOException { return translate(plugin); } public Class translate(Plugin plugin) throws IOException { + if (useCache && cacheClasses.containsKey(target)) { + return cacheClasses.get(target); + } ClassReader classReader = new ClassReader(FileUtils.getResource(plugin, target.replace(".", "/") + ".class")); ClassWriter classWriter = new ClassWriter(0); ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter); classReader.accept(classVisitor, 0); classWriter.visitEnd(); classVisitor.visitEnd(); - return AsmClassLoader.createNewClass(target, classWriter.toByteArray()); + Class newClass = AsmClassLoader.createNewClass(target, classWriter.toByteArray()); + if (useCache) { + cacheClasses.put(target, newClass); + } + return newClass; } // ********************************* @@ -99,4 +115,5 @@ public class SimpleVersionControl { } return origin; } -} + +} \ No newline at end of file diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java index 5c3ad6a..f9c4043 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java @@ -134,14 +134,7 @@ public class FileUtils { * @return {@link InputStream} */ public static InputStream getResource(Plugin plugin, String filename) { - try { - URL url = plugin.getClass().getClassLoader().getResource(filename); - URLConnection connection = url.openConnection(); - connection.setUseCaches(false); - return connection.getInputStream(); - } catch (IOException ignored) { - return null; - } + return plugin.getClass().getClassLoader().getResourceAsStream(filename); } /** diff --git a/src/main/java/me/skymc/taboolib/string/ArrayUtils.java b/src/main/java/me/skymc/taboolib/string/ArrayUtils.java index 40fee02..b2da4df 100644 --- a/src/main/java/me/skymc/taboolib/string/ArrayUtils.java +++ b/src/main/java/me/skymc/taboolib/string/ArrayUtils.java @@ -2,10 +2,7 @@ package me.skymc.taboolib.string; import com.ilummc.tlib.util.Strings; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collections; @@ -64,7 +61,7 @@ public class ArrayUtils { return (T) newArray; } - public static T cloneAsByte(T obj) throws Exception { + public static T cloneAsByte(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(obj);