Skip to content

Utility library to make reflection easier in Bukkit projects.

License

Notifications You must be signed in to change notification settings

TobiasDeBruijn/BukkitReflectionUtil

Repository files navigation

BukkitReflectionUtil

Utility to make working with NMS code easier on Spigot. Compatible with (most) 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.

Maven Central

Installation

BukkitReflectionUtil is available on MavenCentral:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'dev.array21:bukkit-reflection-util:VERSION'
}

Notes about 1.17

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");
        }
    }
}

About

Utility library to make reflection easier in Bukkit projects.

Topics

Resources

License

Stars

Watchers

Forks

Languages