frengor / UltimateAdvancementAPI

A powerful API to create custom advancements for your Minecraft server.
https://modrinth.com/plugin/ultimateadvancementapi
GNU General Public License v3.0
75 stars 5 forks source link

[1.20.2] NPE when sending packets in PlayerLoadingCompletedEvent #54

Closed frengor closed 1 year ago

frengor commented 1 year ago

Source: UltimateAdvancementAPITests#onPlayerLoading(PlayerLoadingCompletedEvent)

Error:

Could not pass event PlayerLoadingCompletedEvent to UltimateAdvancementAPI-Tests v1.0-SNAPSHOT
org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at com.fren_gor.ultimateAdvancementAPI.database.DatabaseManager.lambda$loadPlayerMainFunction$8(DatabaseManager.java:230) ~[?:?]
    at org.bukkit.craftbukkit.v1_20_R2.scheduler.CraftTask.run(CraftTask.java:82) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at org.bukkit.craftbukkit.v1_20_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:415) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1243) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:387) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1179) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:996) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:298) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3922-Spigot-dba3cdc-75502b6]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.server.network.PlayerConnection.b(net.minecraft.network.protocol.Packet)" because "org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer.getHandle().c" is null
    at com.fren_gor.ultimateAdvancementAPI.nms.v1_20_R2.Util.sendTo(Util.java:68) ~[?:?]
    at com.fren_gor.ultimateAdvancementAPI.nms.v1_20_R2.packets.PacketPlayOutAdvancementsWrapper_v1_20_R2.sendTo(PacketPlayOutAdvancementsWrapper_v1_20_R2.java:47) ~[?:?]
    at com.fren_gor.ultimateAdvancementAPI.util.AdvancementUtils.displayToast(AdvancementUtils.java:77) ~[?:?]
    at com.fren_gor.ultimateAdvancementAPITests.UltimateAdvancementAPITests.onPlayerLoading(UltimateAdvancementAPITests.java:135) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    ... 12 more
frengor commented 1 year ago

From what I'm seeing in NMS, the reason for this error is that before 1.20.2 the PlayerJoinEvent fired just after the PlayerLoginEvent, but now they don't fire in the same tick anymore due to the configuration phase.