Search code examples
javaminecraftspigot

How to import com.mojang.authlib.GameProfile


I'm currently trying to create a Spigot plugin, but I need to use GameProfile to apply textures, and I can't seem to import it. When I import it using:

import com.mojang.authlib.GameProfile;

I get the error: Cannot resolve symbol 'mojang'

I'm using IntelliJ with Maven, and I've been struggling with this issue for two days now. I've tried the solutions suggested in these posts:

How can I import com.mojang.authlib.GameProfile
https://www.spigotmc.org/threads/how-do-i-access-gameprofile.450589/

None of them have worked so far. In all of these posts, they mention adding a repository and the dependency authlib-1.5.21. I've tried each of their solutions, but each time I end up with the same error.

    <repositories>
        <repository>
            <id>minecraft-repo</id>
            <url>https://libraries.minecraft.net/</url>
        </repository>
    </repositories>

    <dependencies>
       <dependency>
            <groupId>com.mojang</groupId>
            <artifactId>authlib</artifactId>
            <version>1.5.21</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Dependency 'com.mojang:authlib:1.5.21' not found

I also tried importing my spigot-1.20.1.rar file in Project Structure -> Project Settings -> Modules -> Dependencies based on a video I watched, but that didn't work either.

I used the Minecraft extension in IntelliJ to create my plugin, which provides presets. I also tried to do it without using the extension, but it still didn't work.


Solution

  • The problem here is that the preset of MinecraftDev for IntelliJ use org.spigotmc:spigot-api artifact to your dependencies. spigot-api only contains SpigotAPI related code but not any part of the Minecraft or Mojang code. To fix the problem, you should compile your version of Spigot using their BuildTools Compiling with buildtools will add a complete build of spigot (not juste the API) to your maven local repository. This way, you will be able to add org.spigotmc:spigot as a maven dependency, and all Minecraft and Mojang imports from the server will be available.

    Maven code :

    <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>1.20.1-R1.0-SNAPSHOT</version>
            <scope>provided</scope>
    </dependency>