Solved NoSuchMethodError with world.spawn() Paper 1.20.1

Xuho

New member
Dec 10, 2023
2
0
1
Hello, I'm using latest 1.20.1 paper build, and I'm getting the NoSuchMethodError when trying to spawn an entity using the method org.bukkit.World.spawn(org.bukkit.Location, java.lang.Class, java.util.function.Consumer)

I have this version of paper in the pom (I dont have any other spigot / paper dependency):
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

And this is the code I'm trying to run.
location.getWorld().spawn(location, Warden.class, entity -> {
entity.setPersistent(true);
entity.setRemoveWhenFarAway(false);
});

The weird part is that I don't get any error in the IDE, the method exists in the API.

Version: This server is running Paper version git-Paper-196 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT)
 

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
132
6
19
18
California
The best way to fix this is to just update. 1.20.1 is not supported.

Are you using a plugin.yml or paper-plugin.yml?

The cause of this issue is probably that you are using paper-plugin.yml which does not include any bytecode remap fixes (on purpose). Upstream changed the type from org.bukkit.util.Consumer to java.util.function.Consumer. You are compiling against a version of the API which expects java.util.function.Consumer but the server you are running it on only has org.bukkit.util.Consumer. They included bytecode fixes to plugins compiled against older versions would continue to work, but if you are using paper-plugin.yml, you won't have those.
 

Xuho

New member
Dec 10, 2023
2
0
1
The best way to fix this is to just update. 1.20.1 is not supported.

Are you using a plugin.yml or paper-plugin.yml?

The cause of this issue is probably that you are using paper-plugin.yml which does not include any bytecode remap fixes (on purpose). Upstream changed the type from org.bukkit.util.Consumer to java.util.function.Consumer. You are compiling against a version of the API which expects java.util.function.Consumer but the server you are running it on only has org.bukkit.util.Consumer. They included bytecode fixes to plugins compiled against older versions would continue to work, but if you are using paper-plugin.yml, you won't have those.
Thanks, seems like it is working fine now.