BananaPuncher714 / NBTEditor

A single class NBT editor for items, skulls, mobs, and tile entities
MIT License
138 stars 29 forks source link

NBTEditor.contains() throws NPE #29

Closed Laurenshup closed 1 year ago

Laurenshup commented 1 year ago

NBTEditor.contains(object) throws a NullPointerException. This is used with a Block (tried with both pressure plates and chests). It looks like, when the block does not have any tags set, it throws an error. I tested it on Spigot 1.8.8.

Laurenshup commented 1 year ago

[19:55:53 WARN]: java.lang.NullPointerException
[19:55:53 WARN]:        at java.base/java.lang.reflect.Method.invoke(Method.java:559)
[19:55:53 WARN]:        at io.github.bananapuncher714.nbteditor.NBTEditor.getCompound(NBTEditor.java:807)
[19:55:53 WARN]:        at io.github.bananapuncher714.nbteditor.NBTEditor.getBlockTag(NBTEditor.java:781)
[19:55:53 WARN]:        at io.github.bananapuncher714.nbteditor.NBTEditor.getValue(NBTEditor.java:939)
[19:55:53 WARN]:        at io.github.bananapuncher714.nbteditor.NBTEditor.contains(NBTEditor.java:1148)
[19:55:53 WARN]:        at com.lahuca.pouresca.data.action.Action.getActions(Action.java:402)
[19:55:53 WARN]:        at com.lahuca.pouresca.data.action.Action.runActions(Action.java:488)
[19:55:53 WARN]:        at com.lahuca.pouresca.listeners.InteractListener.lambda$onPlayerInteract$0(InteractListener.java:43)
[19:55:53 WARN]:        at java.base/java.util.Optional.ifPresentOrElse(Optional.java:201)
[19:55:53 WARN]:        at com.lahuca.pouresca.listeners.InteractListener.onPlayerInteract(InteractListener.java:36)
[19:55:53 WARN]:        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[19:55:53 WARN]:        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[19:55:53 WARN]:        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[19:55:53 WARN]:        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[19:55:53 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300)
[19:55:53 WARN]:        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:74)
[19:55:53 WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
[19:55:53 WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:517)
[19:55:53 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:502)
[19:55:53 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:763)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
[19:55:53 WARN]:        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[19:55:53 WARN]:        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:774)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:378)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:713)
[19:55:53 WARN]:        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:616)
[19:55:53 WARN]:        at java.base/java.lang.Thread.run(Thread.java:834)```
BananaPuncher714 commented 1 year ago

Ok, thanks. I will take a look at this when I get the time.

BananaPuncher714 commented 1 year ago

I've updated it to throw an IllegalArgumentException in the case that the block which is provided is not a tile entity. You will need to explicitly check if the block type is correct(such as a chest, spawner, etc).