Merge pull request #47 from TheBiblMan/master

Compiled Java Plugin Loading
This commit is contained in:
Kalen (Konloch) Kinloch 2015-06-02 17:21:32 -06:00
commit 2bc68fb108

View file

@ -63,7 +63,7 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
while ((entry = jis.getNextEntry()) != null) { while ((entry = jis.getNextEntry()) != null) {
try { try {
String name = entry.getName(); String name = entry.getName();
if(!name.endsWith(".class")){ if(name.endsWith(".class")){
byte[] bytes = JarUtils.getBytes(jis); byte[] bytes = JarUtils.getBytes(jis);
String magic = String.format("%02X", bytes[0]) + String.format("%02X", bytes[1]) + String.format("%02X", bytes[2]) + String.format("%02X", bytes[3]); String magic = String.format("%02X", bytes[0]) + String.format("%02X", bytes[1]) + String.format("%02X", bytes[2]) + String.format("%02X", bytes[3]);
if(magic.toLowerCase().equals("cafebabe")) { if(magic.toLowerCase().equals("cafebabe")) {
@ -136,10 +136,8 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
ccache = new HashMap<String, Class<?>>(); ccache = new HashMap<String, Class<?>>();
for(LoadedNodeData d: set) { for(LoadedNodeData d: set) {
if(d != data) {
cache.put(d.node.name, d); cache.put(d.node.name, d);
} }
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends Plugin> pluginKlass = (Class<? extends Plugin>) loadClass(data.node.name.replace("/", ".")); Class<? extends Plugin> pluginKlass = (Class<? extends Plugin>) loadClass(data.node.name.replace("/", "."));
@ -152,7 +150,9 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
@Override @Override
public Class<?> findClass(String name) throws ClassNotFoundException { public Class<?> findClass(String name) throws ClassNotFoundException {
name = name.replace("/", "."); name = name.replace(".", "/");
System.out.println("finding " + name);
if(ccache.containsKey(name)) if(ccache.containsKey(name))
return ccache.get(name); return ccache.get(name);
@ -160,7 +160,7 @@ public class CompiledJavaPluginLaunchStrategy implements PluginLaunchStrategy {
LoadedNodeData data = cache.get(name); LoadedNodeData data = cache.get(name);
if(data != null) { if(data != null) {
byte[] bytes = data.bytes; byte[] bytes = data.bytes;
Class<?> klass = defineClass(data.node.name, bytes, 0, bytes.length); Class<?> klass = defineClass(data.node.name.replace("/", "."), bytes, 0, bytes.length);
ccache.put(name, klass); ccache.put(name, klass);
return klass; return klass;
} }