Many people are confused on how to use NMS classes when they’re new to writing Bukkit/Spigot plugins because their IDE doesn’t find those classes. Don’t worry.
What is NMS?
NMS refers to net.minecraft.server. This package contains all the classes that Mojang wrote for the vanilla Minecraft Server. You can use them to change the server’s behaviour for all the stuff that the Spigot-API does not provide.
Important: When you can achieve the same results using the Spigot-API, always use the API instead. Whenever you use NMS classes, you can expect your plugin to break when a new Minecraft version gets released. NMS is highly version dependent, and field/method names WILL change whenever a new Minecraft version is released. On versions 1.16.5 and earlier, even the package names are different between most updates. Also, most fields and methods have obfuscated names, so instead of “kickPlayer()” you will often have methods called like “a7()”.
How to use NMS classes with Maven
To access NMS classes from your plugin, you have to add the Spigot server .jar to your dependencies, NOT the Spigot-API! Since Spigot is not available in any public repositories (due to copyright reasons), you have to build it yourself using BuildTools. After running BuildTools for the version you’d like to use, add the Spigot dependency to your pom.xml, for example like this:
<dependency> <groupId>org.spigotmc</groupId> <artifactId>spigot</artifactId> <version>1.17.1-R0.1-SNAPSHOT</version> <scope>provided</scope> </dependency>
You’re already done. You can now use and access all NMS classes, fields and methods.