public final class Reflections extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessedFrom(Class<?> clazz)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static boolean |
accessedFrom(String regex)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static boolean |
accessedFromBukkit()
Façade method for determining if Bukkit is the invoker of the method
|
static <T> T |
defaultPrimitiveValue(Class<T> c)
Returns a "default value" of -1 or
false for a default type's
class or autoboxing class. |
static File |
findPluginJarfile(String name)
Checks whether or not there is a plugin on the server with the name of
the passed
name paramater. |
static StackTraceElement |
getCaller()
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static StackTraceElement |
getCaller(int offset)
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static JavaPlugin |
getCallingPlugin()
Returns the
JavaPlugin that immediately called the method in the
current context. |
static JavaPlugin |
getCallingPlugin(int offset)
Returns the
JavaPlugin that immediately called the method in the
current context. |
static World |
getDefaultWorld()
Gets the default
World loaded by Bukkit |
static JavaPlugin |
getPlugin(Class<?> clazz)
Returns the relevant
JavaPlugin that is specified by a
class-level PluginClass annotation if it is loaded, otherwise
null |
static boolean |
hasAnnotation(AnnotatedElement target,
Class<? extends Annotation> check)
Returns
true if the specified target has the passed
Annotation |
static Set<String> |
matchClosestKeys(Map<String,?> map,
String search)
Returns a
Set of keys that closest match the passed in string
value |
static <T> List<T> |
matchClosestValues(Map<String,T> map,
String search)
Returns a
List of values mapped from keys that closest match the
passed in string value |
static <T> List<T> |
nonFixedList(T... items)
Returns a new
ArrayList of the passed parameters that is not
fixed-size, akin to what Arrays.asList(Object...) returns |
static <I,R> R |
nullSafeMutation(I in,
Function<I,R> act)
Provides a way of mutating an object (into a new result) without worrying
about null safety.
|
public static JavaPlugin getPlugin(Class<?> clazz)
JavaPlugin that is specified by a
class-level PluginClass annotation if it is loaded, otherwise
nullclazz - The Class that holds the AnnotationJavaPlugin, or null if not foundpublic static boolean hasAnnotation(AnnotatedElement target, Class<? extends Annotation> check)
true if the specified target has the passed
Annotationtarget - The relevant element to check for an Annotationcheck - The Annotation class type to check fortrue if the Annotation is presentpublic static boolean accessedFrom(String regex)
regex - The regex to check against the calling classtrue if accessed from a class that matches the regexpublic static boolean accessedFrom(Class<?> clazz)
clazz - The class to checktrue if accessed from this classpublic static boolean accessedFromBukkit()
true if Bukkit is the direct invoker of the methodpublic static JavaPlugin getCallingPlugin(int offset)
JavaPlugin that immediately called the method in the
current context. Useful for finding out which plugins accessed static API
methodsoffset - The number of additional methods to look backJavaPluginUnsupportedOperationException - If not called from a
JavaPlugin class (either through an alternative ClassLoader,
executing code directly, or some voodoo magic)public static JavaPlugin getCallingPlugin()
JavaPlugin that immediately called the method in the
current context. Useful for finding out which plugins accessed static API
methods. This method is equivalent to calling
Reflections.getCallingPlugin(0)JavaPluginUnsupportedOperationException - If not called from a
JavaPlugin class (either through an alternative ClassLoader,
executing code directly, or some voodoo magic)getCallingPlugin(int)public static StackTraceElement getCaller(int offset)
StackTraceElement of the direct caller of the current
method's context.offset - The number of additional methods to look backStackTraceElement representing where the current
context was called frompublic static StackTraceElement getCaller()
StackTraceElement of the direct caller of the current
method's context. This method is equivalent to calling
Reflections.getCaller(0)StackTraceElement representing where the current
context was called frompublic static File findPluginJarfile(String name)
name paramater. This method achieves this by scanning
the plugins folder and reading the plugin.yml files of any
respective jarfiles in the directory.name - The name of the plugin as specified in the plugin.ymlFile for the plugin jarfile, or null if not
foundpublic static <T> T defaultPrimitiveValue(Class<T> c)
false for a default type's
class or autoboxing class. Will return null if not relevant to
primitivesT - The type of the primitivec - The primitive classnull if not a primitivepublic static Set<String> matchClosestKeys(Map<String,?> map, String search)
Set of keys that closest match the passed in string
valuemap - The Map with a string key to look throughsearch - The string to use as a base to search forpublic static <T> List<T> matchClosestValues(Map<String,T> map, String search)
List of values mapped from keys that closest match the
passed in string valueT - The type of the valuesmap - The Map to look throughsearch - The string to use as a base to search forpublic static <T> List<T> nonFixedList(T... items)
ArrayList of the passed parameters that is not
fixed-size, akin to what Arrays.asList(Object...) returnsT - The type of the objects being passed initems - The parameters to add to a listList of the items, or an empty list if no paramspublic static World getDefaultWorld()
World loaded by BukkitWorld objectpublic static <I,R> R nullSafeMutation(I in,
Function<I,R> act)
I - The potentially null variable to be mutatedR - The expected result typein - The variable to evaluate for a mutationact - The action to take on the variableIllegalArgumentException - if the passed parameter is nullCopyright © 2015. All rights reserved.