Solved 1.17 moved NBTTagCompound ?

Discussion in 'Spigot Plugin Development' started by Wythe, Jul 2, 2021.

  1. Hello,

    i tried to update my plugin to 1.17.
    I have a NMS Class for each version (1.8-1.16), on that class i have a setTag method which should set a NBT Tag.
    While trying to update the plugin to 1.17 i'm stuck on the following issue.
    The affected Code of the older versions looks like that:
    Code (Java):
    net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound compound = nmsStack.getTag();
    On a update i normaly just replace the version (also on the import).
    But on 1.17 my IDE (Intellj) sugessted me to use the following code

    Code (Java):
    net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound compound = nmsStack.getTag();
    But while compiling i get two errors:
    - cannot find symbol (symbol: class NBTTagCompound)
    - bad class file: /home/false/git/Builder-s-Wand/../all-spigot-nms/all-spigot-nms.jar(/net/minecraft/nbt/NBTTagCompound.class)
    [ERROR] class file has wrong version 60.0, should be 57.0

    I'm using maven and the projekt All Spigot NMS to get all versions.
    I also tried to ignore the suggestion of the IDE and just replace the version number as usual, but there is no "v1_17_R" folder which also means i cant find the class ItemStack for 1.17_R1..
    Maybe you could help me with that...
    THANKS!
     
  2. Minecraft has moved away (FINALLY!!!!!!!!!!!!!!) from NMS classes with versions in the names, so you'll have to update accordingly (I made a post about this and someone posted a good bit of code if you want to use it).
    The project you linked seems to have been updated about a year ago so they don't have those changes - I suggest you fork it and change the necessary stuff (if need be).
     
    • Like Like x 2
  3. Thank you for the information.
    Yea i now the project is not up2date, so i just added the newest versions myself (I'm not sure whats the best way to get all version :D).
    I will check the post you refere to.
     
  4. Maybe im wrong but i use
    Code (Text):
    CraftItemStack.asNMSCopy(itemStack)
    I can import the Class CraftItemStack without any issue, as it is a spigot class and also i got no errors while compiling.
    The method "asNMSCopy" already returns "net.minecraft.world.item.ItemStack" so i normaly don't need to use "Class.forName(...)" or im wrong ?
    I guess the real issue is the second error in my start post:
    Because of that error (I don't know how to fix it) i cant load the class which i need.
    If i'm wrong, please explain why and how i can use "Class.forName(...)" in that case.
    Thanks :)
     
  5. Minecraft never had revisions in package names. It was introduced by Bukkit/Spigot to have an explicit need to check functionality of your plugin using nms. Due the state that deobfuscated field names are dropped in favor of a future migration to Mojang mappings a explicit breaking change isn't needed anymore.
     
  6. I think this means you're using Java 13 while minecraft is using Java 16 as of MC 1.17.
     
  7. Nope, i'm using Java 16 but i also tried it with java 13 :/
     
  8. Could you explain that further ?
    How i can solve my problem, i try to understand the problem.
     
  9. Are you sure you correctly switched back to Java 16? Or maybe your compile target version is still set for Java 13? I'm not sure why else it would be expecting a class file version of 57.0.
     
  10. If i don't miss anything im quite sure.
    Code (Text):

    False ~/git/Builder-s-Wand   master ±  java --version                      
    openjdk 16.0.1 2021-04-20
    OpenJDK Runtime Environment (build 16.0.1+9-Ubuntu-120.04)
    OpenJDK 64-Bit Server VM (build 16.0.1+9-Ubuntu-120.04, mixed mode, sharing)
     
    (Ignore the missing Symboles :D)

    Also the Project and the Module SDK is set to 16 in Intellj.
     
  11. Nobody ? :/
     
  12. Please send your pom.xml so we can see if something is messed up somewhere.
     
  13. I tried it with Java 16 and Java 13 in the project SDK, but as the error appear while mvn install (which also can be executed without ide, i don't thinkt that is the error).

    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>de.False</groupId>
        <artifactId>Builders_Wand</artifactId>
        <version>3.0.0-SNAPSHOT</version>

        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>

            <repository>
                <id>bintray-tastybento-maven-repo</id>
                <name>bintray</name>
                <url>http://dl.bintray.com/tastybento/maven-repo</url>
            </repository>

            <repository>
                <id>sk89q-repo</id>
                <url>http://maven.sk89q.com/repo/</url>
            </repository>

            <repository>
                <id>factions</id>
                <url>https://repo.minebench.de/</url>
            </repository>

            <repository>
                <id>mcmmo</id>
                <url>https://repo.codemc.org/repository/maven-public/</url>
            </repository>

            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>

            <repository>
                <id>articdive-repo</id>
                <url>https://nexus.articdive.de/repository/maven-public/</url>
            </repository>

            <repository>
                <id>codemc-repo</id>
                <url>https://repo.codemc.org/repository/maven-public/</url>
            </repository>

            <repository>
                <id>IntellectualSites</id>
                <url>https://mvn.intellectualsites.com/content/groups/public/</url>
            </repository>

            <repository>
                <id>coreprotect-repo</id>
                <url>http://maven.playpro.com/</url>
            </repository>
        </repositories>

        <dependencies>

            <!--all nms versions-->
            <dependency>
                <groupId>local.spigot.nms</groupId>
                <artifactId>AllSpigotNMS</artifactId>
                <version>LATEST</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/../all-spigot-nms/all-spigot-nms.jar</systemPath>
            </dependency>

            <!--Spigot API-->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.14-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <!--Bukkit API-->
            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.14-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.wasteofplastic</groupId>
                <artifactId>askyblock</artifactId>
                <version>3.0.8.2</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.sk89q.worldedit</groupId>
                <artifactId>worldedit-bukkit</artifactId>
                <version>7.0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.sk89q.worldguard</groupId>
                <artifactId>worldguard-legacy</artifactId>
                <version>6.2</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.sk89q.worldguard</groupId>
                <artifactId>worldguard-bukkit</artifactId>
                <version>7.0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.massivecraft.factions</groupId>
                <artifactId>factions</artifactId>
                <version>2.12.0</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.massivecraft.massivecore</groupId>
                <artifactId>massivecore</artifactId>
                <version>2.12.0</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.gmail.nossr50.mcMMO</groupId>
                <artifactId>mcMMO</artifactId>
                <version>2.1.178</version>
            </dependency>

            <dependency>
                <groupId>world.bentobox</groupId>
                <artifactId>bentobox</artifactId>
                <version>1.5.3</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>com.github.TechFortress</groupId>
                <artifactId>GriefPrevention</artifactId>
                <version>16.7.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>com.sk89q</groupId>
                        <artifactId>worldguard</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <!-- Add this yourself to your local Maven repo! -->
            <dependency>
                <groupId>com.github.TownyAdvanced</groupId>
                <artifactId>Towny</artifactId>
                <version>0.96.2.7</version>
            </dependency>

            <!-- NMS -->
            <dependency>
                <groupId>com.plotsquared</groupId>
                <artifactId>PlotSquared-Core</artifactId>
                <version>5.13.0</version>
            </dependency>

            <dependency>
                <groupId>net.coreprotect</groupId>
                <artifactId>coreprotect</artifactId>
                <version>2.14.2</version>
            </dependency>

            <dependency>
                <groupId>com.residence</groupId>
                <artifactId>residence</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>
                    ${project.basedir}/external/Residence.jar
                </systemPath>
            </dependency>

            <dependency>
                <groupId>com.github.LoneDev6</groupId>
                <artifactId>ItemsAdder-API</artifactId>
                <version>0.1.2</version>
            </dependency>

            <dependency>
                <groupId>com.github.angeschossen</groupId>
                <artifactId>LandsAPI</artifactId>
                <version>4.12.12</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>

        <build>
            <resources>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>plugin.yml</include>
                    </includes>
                </resource>
            </resources>

            <finalName>${project.name}</finalName>

            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
     
  14. Change maven-compiler-plugin configuration source and target fields to 16 (at the far bottom).
     
  15. I already tried that, but then i get the error
    Code (Text):
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Builders_Wand: Fatal error compiling: error: invalid target release: 16 -> [Help 1]
     
  16. Solved the problem, using "update-alternatives --config java" and "sudo update-alternatives --config jar" will NOT change the JAVA_HOME enviroment variable (why ever...).
    So i had to update the JAVA_HOME enviroment variable and also i had to install the newest maven version.
     
    • Informative Informative x 1