PikaMug / Quests

Easy-to-use, open-source plugin for the creation and execution of quests on Minecraft servers.
https://modrinth.com/plugin/quests.classic
MIT License
141 stars 104 forks source link

When giving custom book to an NPC, null reference exception #2108

Closed Broseten closed 1 year ago

Broseten commented 1 year ago

What is your Quests version / build number (do not say "latest")?

Quests-4.8.1

Describe the problem and how to replicate it.

We have a custom plugin that creates a book but does not set the title. "Plugins should check that hasTitle() returns true before calling this method." -- BookMeta.getTitle() From: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/BookMeta.html#getTitle()

When trying to give this book to an NPC to progress a quest, we got a null reference error.

We fixed in on our side by updating the plugin, but still it would be good to fix it. :) Thx, keep up the good work.

Any console errors to share?

[12:59:52 ERROR]: Could not pass event NPCRightClickEvent to Quests v4.8.1-b404
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "org.bukkit.inventory.meta.BookMeta.getTitle()" is null
        at me.blackvein.quests.util.ItemUtil.compareItems(ItemUtil.java:135) ~[Quests-4.8.1.jar:?]
        at me.blackvein.quests.util.ItemUtil.compareItems(ItemUtil.java:61) ~[Quests-4.8.1.jar:?]
        at me.blackvein.quests.listeners.CitizensListener.onNPCRightClick(CitizensListener.java:79) ~[Quests-4.8.1.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor267.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:git-Paper-321]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:672) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at net.citizensnpcs.EventListen.onPlayerInteractEntity(EventListen.java:419) ~[Citizens-2.0.30-b2878.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor243.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:git-Paper-321]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:672) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl$5.performInteraction(ServerGamePacketListenerImpl.java:2773) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl$5.a(ServerGamePacketListenerImpl.java:2821) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundInteractPacket$InteractionAction.dispatch(ServerboundInteractPacket.java:131) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundInteractPacket.dispatch(ServerboundInteractPacket.java:80) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.handleInteract(ServerGamePacketListenerImpl.java:2762) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:67) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundInteractPacket.handle(ServerboundInteractPacket.java:12) ~[?:?]
        at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
        at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
        at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
        at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1341) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:197) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1318) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1311) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1289) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1177) ~[paper-1.19.3.jar:git-Paper-321]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316) ~[paper-1.19.3.jar:git-Paper-321]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

If applicable, can you provide an example quest from quests.yml?

No response

Broseten commented 1 year ago

Actually the title seems to be null for the "template book" in the plugin (it is trying to check the title for signed book). But we actually didn't want to check the title since it was different for each player. So maybe just add the hasTitle() check everywhere :D

PikaMug commented 1 year ago

@Broseten Please try https://ci.codemc.io/job/PikaMug/job/Quests/418/

Broseten commented 1 year ago

Perfect, now it works! We can finally do what we need to! (btw, we actually have a research project and use Minecraft to build some educational platforms) Thanks :))