Utility to make working with NMS code easier on Spigot. Compatible with Minecraft versions 1.16+.
This library also provides some abstractions over NMS. Feel free to PR more, I add the abstractions when I need them in projects using this library.
BukkitReflectionUtil is available on MavenCentral:
repositories {
mavenCentral()
}
dependencies {
implementation 'dev.array21:bukkit-reflection-util:VERSION'
}
BukkitReflectionUtil works with both pre-1.17 and post-1.17. However there are some things you should pay attention to.
As of 1.17, Spigot does not flatten net.minecraft
anymore. You could solve it like this:
import dev.array21.bukkitreflectionutil.ReflectionUtil;
class MyNmsClass {
public Class<?> getEntityHumanClass() {
if(ReflectionUtil.isUseNewSpigotPackaging()) {
// >= Minecraft 1.17
return ReflectionUtil.getMinecraftClass("world.entity.player.EntityHuman");
} else {
// =< Minecraft 1.16
// This method is also marked as @Deprecated !
return ReflectionUtil.getNmsClass("EntityHuman");
}
}
}