Fix LocalPlayer & WorldGuardHook
This commit is contained in:
parent
89218727a2
commit
156c56d71d
@ -14,10 +14,6 @@ public class BridgeLoader extends ClassLoader {
|
|||||||
private static Method findClass;
|
private static Method findClass;
|
||||||
private static ClassLoader pluginClassLoader;
|
private static ClassLoader pluginClassLoader;
|
||||||
|
|
||||||
public static BridgeLoader getInstance() {
|
|
||||||
return new BridgeLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
private BridgeLoader() {
|
private BridgeLoader() {
|
||||||
super(BridgeLoader.class.getClassLoader());
|
super(BridgeLoader.class.getClassLoader());
|
||||||
try {
|
try {
|
||||||
@ -41,6 +37,6 @@ public class BridgeLoader extends ClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> createNewClass(String name, byte[] arr) {
|
public static Class<?> createNewClass(String name, byte[] arr) {
|
||||||
return getInstance().defineClass(name, arr, 0, arr.length, BridgeLoader.class.getProtectionDomain());
|
return new BridgeLoader().defineClass(name, arr, 0, arr.length, BridgeLoader.class.getProtectionDomain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import io.izzel.taboolib.Version;
|
|||||||
import io.izzel.taboolib.common.plugin.InternalPlugin;
|
import io.izzel.taboolib.common.plugin.InternalPlugin;
|
||||||
import io.izzel.taboolib.common.plugin.bridge.BridgeLoader;
|
import io.izzel.taboolib.common.plugin.bridge.BridgeLoader;
|
||||||
import io.izzel.taboolib.util.Files;
|
import io.izzel.taboolib.util.Files;
|
||||||
|
import io.izzel.taboolib.util.IO;
|
||||||
import io.izzel.taboolib.util.Ref;
|
import io.izzel.taboolib.util.Ref;
|
||||||
import io.izzel.taboolib.util.asm.AsmClassLoader;
|
import io.izzel.taboolib.util.asm.AsmClassLoader;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -13,7 +14,9 @@ import org.objectweb.asm.ClassReader;
|
|||||||
import org.objectweb.asm.ClassVisitor;
|
import org.objectweb.asm.ClassVisitor;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,7 +28,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class SimpleVersionControl {
|
public class SimpleVersionControl {
|
||||||
|
|
||||||
private static Map<String, Class<?>> cacheClasses = new HashMap<>();
|
private static Map<String, byte[]> cacheClasses = new HashMap<>();
|
||||||
private String target;
|
private String target;
|
||||||
private String to;
|
private String to;
|
||||||
private List<String> from = Lists.newArrayList();
|
private List<String> from = Lists.newArrayList();
|
||||||
@ -113,20 +116,23 @@ public class SimpleVersionControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> translate(Plugin plugin) throws IOException {
|
public Class<?> translate(Plugin plugin) throws IOException {
|
||||||
|
InputStream inputStream;
|
||||||
if (useCache && cacheClasses.containsKey(target)) {
|
if (useCache && cacheClasses.containsKey(target)) {
|
||||||
return cacheClasses.get(target);
|
inputStream = new ByteArrayInputStream(cacheClasses.get(target));
|
||||||
|
} else {
|
||||||
|
inputStream = Files.getResource(plugin, target.replace(".", "/") + ".class");
|
||||||
|
if (useCache) {
|
||||||
|
cacheClasses.put(target, IO.readFully(inputStream));
|
||||||
}
|
}
|
||||||
ClassReader classReader = new ClassReader(Files.getResource(plugin, target.replace(".", "/") + ".class"));
|
}
|
||||||
|
ClassReader classReader = new ClassReader(inputStream);
|
||||||
ClassWriter classWriter = new ClassWriter(0);
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
|
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
|
||||||
classReader.accept(classVisitor, ClassReader.EXPAND_FRAMES);
|
classReader.accept(classVisitor, ClassReader.EXPAND_FRAMES);
|
||||||
classWriter.visitEnd();
|
classWriter.visitEnd();
|
||||||
classVisitor.visitEnd();
|
classVisitor.visitEnd();
|
||||||
Class<?> newClass = plugin instanceof InternalPlugin ? AsmClassLoader.createNewClass(target, classWriter.toByteArray()) : BridgeLoader.createNewClass(target, classWriter.toByteArray());
|
// 因第三方插件调用该方法时会出现找不到类,所以第三方插件使用 BridgeLoader 加载类
|
||||||
if (useCache) {
|
return plugin instanceof InternalPlugin ? AsmClassLoader.createNewClass(target, classWriter.toByteArray()) : BridgeLoader.createNewClass(target, classWriter.toByteArray());
|
||||||
cacheClasses.put(target, newClass);
|
|
||||||
}
|
|
||||||
return newClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> translateBridge() throws IOException {
|
public Class<?> translateBridge() throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user