mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-08 00:21:50 +01:00
Fixed java plugin class loader so it works with plugins that contain classes also present in other plugins.
This also removes the changes from commit 1c4bde50bc12d130f6c8 which was added in order to fix this issue but wasn't ideal as it required plugins to be updated which isnt required with this fix By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
parent
11804b78a5
commit
4af56e3d16
@ -27,7 +27,6 @@ import org.bukkit.event.vehicle.*;
|
||||
import org.bukkit.event.world.*;
|
||||
import org.bukkit.event.weather.*;
|
||||
import org.bukkit.plugin.*;
|
||||
import org.bukkit.plugin.java.annotations.DontExport;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
/**
|
||||
@ -218,7 +217,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
}
|
||||
|
||||
public void setClass(final String name, final Class<?> clazz) {
|
||||
if ((!classes.containsKey(name)) && (clazz.getAnnotation(DontExport.class) != null)) {
|
||||
if (!classes.containsKey(name)) {
|
||||
classes.put(name, clazz);
|
||||
}
|
||||
}
|
||||
|
@ -25,27 +25,35 @@ public class PluginClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
protected Class<?> findClass(String name, boolean checkGlobal) throws ClassNotFoundException {
|
||||
// We use the following load order:
|
||||
// 1. Local first, this avoids IllegalAccessError exceptions for duplicate classes
|
||||
// 2. Global cache second which prevents ClassCastException's apparently
|
||||
Class<?> result = classes.get(name);
|
||||
|
||||
if (result == null) {
|
||||
if (checkGlobal) {
|
||||
result = loader.getClassByName(name);
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if ( null == result ) {
|
||||
try {
|
||||
result = super.findClass(name);
|
||||
|
||||
if (result != null) {
|
||||
loader.setClass(name, result);
|
||||
classes.put(name, result);
|
||||
loader.setClass(name, result);
|
||||
} catch ( ClassNotFoundException e ) {
|
||||
if ( checkGlobal ) {
|
||||
result = loader.getClassByName(name);
|
||||
if ( null == result ) {
|
||||
// We really couldnt find it
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
} else {
|
||||
throw e; // no more options just rethrow
|
||||
}
|
||||
}
|
||||
|
||||
classes.put(name, result);
|
||||
}
|
||||
|
||||
// NOTE: setClass already does a not exists check
|
||||
loader.setClass(name, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getClasses() {
|
||||
return classes.keySet();
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
|
||||
package org.bukkit.plugin.java.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Flags a class as private and not to be exported with other plugins
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DontExport {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user