2022-02-07 12:45:18 +01:00
|
|
|
package fr.pandacube.lib.paper.reflect;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2022-07-20 13:18:57 +02:00
|
|
|
import fr.pandacube.lib.reflect.Reflect;
|
2022-07-28 01:11:28 +02:00
|
|
|
import fr.pandacube.lib.reflect.ReflectClass;
|
2022-02-07 12:45:18 +01:00
|
|
|
|
2022-09-08 23:42:12 +02:00
|
|
|
/**
|
|
|
|
* Provides reflection tools related to {@code org.bukkit.craftbukkit}.
|
|
|
|
*/
|
2022-02-07 12:45:18 +01:00
|
|
|
public class OBCReflect {
|
|
|
|
|
|
|
|
private static final String OBC_PACKAGE_PREFIX = "org.bukkit.craftbukkit.";
|
|
|
|
|
|
|
|
private static final String OBC_PACKAGE_VERSION;
|
|
|
|
|
|
|
|
static {
|
|
|
|
String name = Bukkit.getServer().getClass().getName()
|
|
|
|
.substring(OBC_PACKAGE_PREFIX.length());
|
|
|
|
name = name.substring(0, name.indexOf("."));
|
|
|
|
|
|
|
|
OBC_PACKAGE_VERSION = name;
|
|
|
|
}
|
2022-09-08 23:42:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the OBC class that has the provided name, wrapped into a {@link ReflectClass}.
|
|
|
|
* @param obcClass the name of the class, including the subpackage in whitch the requested class is. This parameter
|
|
|
|
* will be prefixed with the {@code OBC} package and the current package version.
|
|
|
|
* @return the OBC class that has the provided name, wrapped into a {@link ReflectClass}.
|
|
|
|
* @throws ClassNotFoundException if the provided class was not found in {@code OBC} package.
|
|
|
|
*/
|
2022-02-07 12:45:18 +01:00
|
|
|
public static ReflectClass<?> ofClass(String obcClass) throws ClassNotFoundException {
|
|
|
|
return Reflect.ofClass(OBC_PACKAGE_PREFIX + OBC_PACKAGE_VERSION + "." + obcClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|