JEFF Media Developer Blog

Java & Spigot development

Menu
  • Blog
  • Main Website
  • Privacy Policy
Menu

NMS: Use Mojang maps for your Spigot plugins with Maven or Gradle

Posted on December 2, 2021April 24, 2024 by mfnalex

If you need to access NMS classes from inside your Spigot plugin, it is a very good idea to use the so called Mojang mappings.

Disclaimer: This post is written for 1.20.4. If you use another version, you of course have to replace every occurance of “1.20.4” with the version you actually use.

What are Mojang mappings?

Mojang is obfuscating certain method and field names before shipping Minecraft. That means you will have a very bad experience when you want to access NMS in the classic way, because most fields are simply called “a”, “b”, “c”, etc. Fortunately, Mojang decided to release their obfuscation map, which means that you can actually use the same names that the Mojang developers are using.

How to use Mojang mappings

First of all, you have to run BuildTools and tell it to get yourself a nice, fresh compiled spigot version with the Mojang mappings:

java -jar BuildTools.jar --rev 1.20.4 --remapped

It does not matter in which folder you run BuildTools as long as it’s on the same computer that you use to code your plugin. BuildTools will install all dependencies to your local maven repository. You can now adjust your build file (pom.xml when using Maven, or build.gradle/build.gradle.kts when using Gradle) to use the Mojang mapped .jar, and to reobfuscate all needed method/class calls at compile time.

When using Maven

When using Maven, you can use the official specialsource-maven-plugin which is available on Maven Central. We’ll also change our dependency to use spigot instead of spigot-api with classifier remapped-mojang:

    <build>
        <plugins>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>2.0.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    [...]

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>1.20.4-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
            <classifier>remapped-mojang</classifier> <!-- Important! -->
        </dependency>
    </dependencies>

Obviously, you might want to adjust “1.20.4” when you want to use a different spigot version (e.g. change it from “1.20.4” to “1.19.4” in both, your <dependency> section, and in all 4 places it appears in the <plugin> section). You are now fine to go to use Mojang mappings. Maven will automatically “reobfuscate” your code so it’ll be compatible with the actual server software.

When using Gradle

For Gradle, there is no official remapping plugin available from SpigotMC, but we can just use one of the community ones. I suggest to use patrick-choe’s mojang-spigot-remapper. We’ll also need to add mavenCentral() (for transitive dependencies) and mavenLocal() to our repositories so that Gradle can find our spigot dependency (again, we’ll use the artifact spigot with classifier remapped-mojang instead of the regular spigot-api), and then we’ll make the build task depend on the remap task so that we don’t have to run it manually everytime:

// Using Kotlin DSL:

plugins {
    java
    id("io.github.patrick.remapper") version "1.4.0"
}

// ...

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compileOnly("org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:remapped-mojang")
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17)) // Spigot 1.18+ requires Java 17+
    }
}

tasks.remap {
    version.set("1.20.4")
}

tasks.build {
    dependsOn(tasks.remap)
}

If you’re using Groovy, then you’ll obviously have to adjust that code a bit.

That’s it!

You’re done! You can now use Mojang Mappings in your code and don’t have to rely on those stupid obfuscated method names anymore.

You’ll notice that some classes or methods can’t be found anymore if you’re switching from the old Spigot Mappings. Check out this blog post to see how you can find out the new class, method and field names.

If you’re writing your plugin to be compatible with more than one NMS version, you want to create a multi-module project instead. For Maven, you can check out this blog post.

Join my Discord Server for feedback or support. Just check out the channel #programming-help 🙂

12 thoughts on “NMS: Use Mojang maps for your Spigot plugins with Maven or Gradle”

  1. Ntdi says:
    June 9, 2022 at 5:22 pm

    Super Cool!

    Reply
  2. fisher says:
    March 27, 2023 at 12:10 am

    ya know, google doesn’t turn up particularly helpful results from spigot, thanks for the post 🙂

    Reply
    1. mfnalex says:
      March 31, 2023 at 10:19 am

      You’re welcome!

      Reply
  3. siea says:
    November 18, 2023 at 8:31 pm

    Saving my life every single time

    Reply
  4. Luis says:
    January 18, 2024 at 5:57 pm

    Hi, I don’t know if you give support here but this for some reason doesn’t work for me… I keep getting this error no matter how many clean installs I do or reloads:

    Could not find artifact org.spigotmc:spigot:jar:remapped-mojang:1.20.4-R0.1-SNAPSHOT in spigot repo (https://hub.spigotmc.org/nexus/content/repositories/snapshots/)

    Which basically means it’s not finding the files anywhere… I think I did every step

    Reply
    1. mfnalex says:
      January 28, 2024 at 5:03 pm

      You haven’t ran BuildTools as described in the post: java -jar BuildTools.jar --rev 1.20.4 --remapped

      Reply
  5. Cade says:
    May 16, 2024 at 11:07 pm

    Hey so after it compiles, which target jar should you use?
    -VanaByte-1.0-shaded.jar
    -VanaByte-1.0-remapped-obf.jar
    -VanaByte-1.0-remapped.jar
    -VanaByte-1.0.jar
    -original-VanaByte-1.0.jar

    Reply
    1. mfnalex says:
      June 1, 2024 at 11:52 am

      VanaByte-1.0.jar

      Reply
  6. Goldentoenail says:
    May 22, 2024 at 2:49 am

    It seems that you have forgotten to say that this implementation is for when using the InteliJ IDE.
    The section would be different when using Eclipse (for example).

    Reply
    1. mfnalex says:
      June 1, 2024 at 11:54 am

      What do you mean? It’s independant of any IDE. It only requires changes in your maven pom.xml or gradle build file

      Reply
  7. Goldentoenail says:
    May 22, 2024 at 2:53 am

    * Configuration Section which points to a local directory

    Reply
  8. Azzy says:
    September 8, 2024 at 9:16 pm

    Thanks for the help! Lifesaver. Definitely bookmarking this for future reference.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Solution: Creating a Datastore on Proxmox Backup Server fails at “Chunkstore create” (“File exists” or “Too many links”)
  • Don’t disable dependency-reduced-pom.xml
  • Maven Multi-Module setup for supporting different NMS versions
  • How to read or block Spigot’s console output
  • Why IntelliJ complains about your pom.xml file

Recent Comments

  1. mfnalex on Creating custom heads in Spigot 1.18.1+
  2. Timon Coucke on Maven Multi-Module setup for supporting different NMS versions
  3. 3ricL on Creating custom heads in Spigot 1.18.1+
  4. Ryan Leach on Why the GPL does NOT directly apply to all Spigot plugins
  5. Azzy on NMS: Use Mojang maps for your Spigot plugins with Maven or Gradle

Archives

  • December 2024
  • August 2023
  • July 2023
  • June 2023
  • February 2023
  • January 2023
  • October 2022
  • August 2022
  • March 2022
  • December 2021
  • October 2021
  • August 2021
©2025 JEFF Media Developer Blog
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT