From 11804b78a585733e46e5a45dbf2dd4c1fcfffedf Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 12 May 2011 23:09:24 +0100 Subject: [PATCH] Added @DontExport annotation for telling Bukkit not to share a class with another plugin By: Dinnerbone --- .../org/bukkit/plugin/java/JavaPluginLoader.java | 3 ++- .../bukkit/plugin/java/PluginClassLoader.java | 2 +- .../plugin/java/annotations/DontExport.java | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/plugin/java/annotations/DontExport.java diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 448b297035..93eb0f2c04 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -27,6 +27,7 @@ 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; /** @@ -217,7 +218,7 @@ public final class JavaPluginLoader implements PluginLoader { } public void setClass(final String name, final Class clazz) { - if(!classes.containsKey(name)) { + if ((!classes.containsKey(name)) && (clazz.getAnnotation(DontExport.class) != null)) { classes.put(name, clazz); } } diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java index 91d4d6d3d6..f998e3098e 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java @@ -28,7 +28,7 @@ public class PluginClassLoader extends URLClassLoader { Class result = classes.get(name); if (result == null) { - if(checkGlobal) { + if (checkGlobal) { result = loader.getClassByName(name); } diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/annotations/DontExport.java b/paper-api/src/main/java/org/bukkit/plugin/java/annotations/DontExport.java new file mode 100644 index 0000000000..dd6efb9bea --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/plugin/java/annotations/DontExport.java @@ -0,0 +1,16 @@ + +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 { + +}