Solved Getting the Pathfinder of a mob with the paper API

luismayme

New member
Jan 17, 2024
6
1
1
Hello there, I'm new to the paper API and I'm trying to use the Pathfinder utility. The problem is that my IDE is unable to find the method getPathfinder() when I'm trying to get it from a bukkit Mob.

My dependencies on maven:
XML:
<dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>1.20.4-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>24.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>us.dynmap</groupId>
            <artifactId>dynmap-api</artifactId>
            <version>3.6-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.papermc.paper</groupId>
            <artifactId>paper-api</artifactId>
            <version>1.20.4-R0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
If you know anything about this, please tell me. I'm using the lastest version of IntelliJ
 

electronicboy

Administrator
Staff member
Dec 11, 2021
225
10
38
28
You're importing spigot, which will bundle spigots API classes and thus you won't get to see paper specific API
 

luismayme

New member
Jan 17, 2024
6
1
1
I've tried removing spigot and it didn't work, also I'm using NMS, which paper repo has it? Thank you for the quick reply!
 

electronicboy

Administrator
Staff member
Dec 11, 2021
225
10
38
28
if you can't see papers API methods, you would generally want to check your classpath as it would surmise that something is bundling spigot/bukkit API classes
nms is not inside of a repo, anybody with that in a repo is generally violating mojangs EULA, we do not support using maven for accessing internals, there is however a 3rd party community provided maven plugin for doing so out in the public
 

luismayme

New member
Jan 17, 2024
6
1
1
I've explained myself poorly. I don't want the javadocs of mojang, I know it's not legal. I just want the NMS classes to be recognized on the project. Also, I've checked the classpath and I think there is no other thing than the maven dependencies working...
 

electronicboy

Administrator
Staff member
Dec 11, 2021
225
10
38
28
I never said anything about the javadocs of mojang.
You are bundling spigot, bundling spigot will implictly bundle spigot-api, spigot-api will mask paper-api's classes, and thus, you will need to add an exclusion to spigot in order to not include spigot-api
 

luismayme

New member
Jan 17, 2024
6
1
1
Using NMS is against EULA? Damn, I've seen so many posts and plugins using it that I didn't know. Also, I'm having a hard time doing what you told me. I've tried cleaning maven, looking into the project dependencies and still not finding getPathfinder
EDIT: So if I'm using NMS I can't use Paper differing from using spigot which includes de NMS classes, right?
 

electronicboy

Administrator
Staff member
Dec 11, 2021
225
10
38
28
Using NMS is against EULA?
That's not what I've said in the slightest. using NMS is fine, mojang explictly allows that as per their licensing agreements. Putting spigots jar inside of a maven repo would be a violation of the EULA, as shipping modified versions of mojangs software is a violation of their agreement, hence why spigot has buildtools, and we have paperweight.

EDIT: So if I'm using NMS I can't use Paper differing from using spigot which includes de NMS classes, right?
There can only be 1 class definition detected from the classpath, and so, if you depend on spigot and their API, you are only going to see spigots classes. The most obvious solution would be to build against paper if you want to use paper API and NMS, there is a 3rd party maven plugin which would support this, or switch to using gradle and then use our paperweight userdev tooling which will get you building against paper.

if you want to go down a more weird route, you can, once again, add an exclusion to your spigot dependency in order to tell it to not include the spigot-api with it, however, such a thing will generally create a weird environment in which you have API which basically doesn't exist inside of spigot, etc
 

luismayme

New member
Jan 17, 2024
6
1
1
I've managed to make paper work as the only dependency with the plugin you spoke about since I've never used gradle nor I know how to refactor the project into using gradle. I'm still unable to use paper Pathfinder but at least I've got NMS mapped...
 

LINCKODE

New member
Jan 19, 2024
1
0
1
I've managed to make paper work as the only dependency with the plugin you spoke about since I've never used gradle nor I know how to refactor the project into using gradle. I'm still unable to use paper Pathfinder but at least I've got NMS mapped...
I think Gradle can automatically convert your maven project: https://www.baeldung.com/maven-convert-to-gradle

Also i think you can get a hold of the pathfinder like this:


Java:
import com.destroystokyo.paper.entity.Pathfinder;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;

...

Entity bukkitEntity = //Your entity
Pathfinder pathfinder = ((Mob) bukkitEntity).getPathfinder();
 

luismayme

New member
Jan 17, 2024
6
1
1
I think Gradle can automatically convert your maven project: https://www.baeldung.com/maven-convert-to-gradle

Also i think you can get a hold of the pathfinder like this:


Java:
import com.destroystokyo.paper.entity.Pathfinder;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;

...

Entity bukkitEntity = //Your entity
Pathfinder pathfinder = ((Mob) bukkitEntity).getPathfinder();
Thank you for your reply! I also tried that and it didn't work. I ended up understanding that the order in which you declare your dependencies matters and that the DynmapAPI was importing an old bukkit version that was being resolved before paper, thus making mob the bukkit version, not the paper's. Also having a maven module and a gradle one at the same time was being a bit too confusing, so I ended up sticking to maven. Thank you for your replies, I hope this helps someone with a similar problem.
 
  • Like
Reactions: LINCKODE