NBT-API

NBT-API

98.9k Downloads

Exception while getting NBTCompound from TileEntity!

jman13378 opened this issue ยท 4 comments

commented

I am using this code to modify a blocks nbt but im getting the error below

I have added lines so you can see where the error occurred

// NBTManager.java
41 | NBT.modify(this.block.getState(), (itemt) -> {
42 |	itemt.setString("key-code", "generate");
43 |	itemt.setInteger("uses", 0);
44 | });
//Interact.java
97 | NBTManager manager = new NBTManager(event.getClickedBlock());
98 | manager.applyRequiredNBTTags();
99 | manager.setCode(NBT.get(event.getItem(), t -> t.getString("key-code")));
100 | 			
101 | event.getClickedBlock().setBlockData(manager.buildBlock().getBlockData());
102 | player.getEquipment().getItem(event.getHand()).setType(Material.AIR);
103 | player.playSound(player.getLocation(), plugin.getConfig().getString("config.sounds.lock-placed"), 0, 0);

Error

[22:38:36 ERROR]: Could not pass event PlayerInteractEvent to LockSmith v0.1
de.tr7zw.nbtapi.NbtApiException: [?]Exception while getting NBTCompound from TileEntity!
        at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:250) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBTTileEntity.getCompound(NBTTileEntity.java:39) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBTReflectionUtil.setData(NBTReflectionUtil.java:608) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBTCompound.setString(NBTCompound.java:115) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTManager.lambda$1(NBTManager.java:42) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBT.modify(NBT.java:193) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTManager.applyRequiredNBTTags(NBTManager.java:41) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.events.Interact.onInteract(Interact.java:98) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor3028.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:git-Paper-307]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:670) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:545) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.level.ServerPlayerGameMode.useItemOn(ServerPlayerGameMode.java:526) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItemOn(ServerGamePacketListenerImpl.java:1969) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.handle(ServerboundUseItemOnPacket.java:37) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.a(ServerboundUseItemOnPacket.java:9) ~[?:?]
        at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
        at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.2.jar:git-Paper-307]
        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.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:185) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1318) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1311) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1289) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1177) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-307]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: de.tr7zw.nbtapi.NbtApiException: [?]Error while calling the method 'saveWithId()', loaded: true, Enum: TILEENTITY_GET_NBT_1181, Passed Class: null
        at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:358) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:240) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        ... 31 more
Caused by: java.lang.NullPointerException
        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 de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:355) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at de.tr7zw.nbtapi.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:240) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        ... 31 more
        ```
commented

Few things:
NbtApiException: [?]Error while calling the method 'saveWithId()', loaded: true, Enum: TILEENTITY_GET_NBT_1181, Passed Class: null
it got passed null as target, so probably the chest isn't there yet. You are doing this on the BlockPlaceEvent? At that point in time, the chest isn't physically in the world yet. You need to do it later that same tick/next tick.
Why isn't the API selfchecked? Did you shade it? If so, fix the package name.
Locking chests with a pin to open them is already a vanilla feature(just not accessible without commands/plugins), just saying^^.

commented

Ok

  1. not using a chest
  2. Says at the top of the error PlayerInteractEvent
  3. I am shading
[23:12:41 WARN]: steel_lock
[23:12:41 WARN]: steel_lock
[23:12:41 WARN]: Type `DOORS` is not a type or a valid material; Ignoring!
[23:12:41 WARN]: Clicked Block: OAK_DOOR
[23:12:41 INFO]: [NBTAPI] [NBTAPI] Found Spigot: v1_19_R1! Trying to find NMS support
[23:12:41 INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_19_R1' loaded!
[23:12:41 INFO]: [NBTAPI] [NBTAPI] Found Gson: class com.google.gson.Gson
[23:12:41 ERROR]: Could not pass event PlayerInteractEvent to LockSmith v0.1
info.sokobot.locksmith.NbtApiException: [?]Exception while getting NBTCompound from TileEntity!
        at info.sokobot.locksmith.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:250) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTTileEntity.getCompound(NBTTileEntity.java:39) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTReflectionUtil.setData(NBTReflectionUtil.java:608) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTCompound.setString(NBTCompound.java:115) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTManager.lambda$1(NBTManager.java:42) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBT.modify(NBT.java:193) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTManager.applyRequiredNBTTags(NBTManager.java:41) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.events.Interact.onInteract(Interact.java:99) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor3691.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:git-Paper-307]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:670) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:545) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.level.ServerPlayerGameMode.useItemOn(ServerPlayerGameMode.java:526) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItemOn(ServerGamePacketListenerImpl.java:1969) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.handle(ServerboundUseItemOnPacket.java:37) ~[?:?]
        at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.a(ServerboundUseItemOnPacket.java:9) ~[?:?]
        at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
        at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.2.jar:git-Paper-307]
        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.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:185) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1318) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1311) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1289) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1177) ~[paper-1.19.2.jar:git-Paper-307]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-307]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: info.sokobot.locksmith.NbtApiException: [?]Error while calling the method 'saveWithId()', loaded: true, Enum: TILEENTITY_GET_NBT_1181, Passed Class: null
        at info.sokobot.locksmith.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:358) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:240) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        ... 31 more
Caused by: java.lang.NullPointerException
        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 info.sokobot.locksmith.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:355) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        at info.sokobot.locksmith.NBTReflectionUtil.getTileEntityNBTTagCompound(NBTReflectionUtil.java:240) ~[locksmith-0.0.1-SNAPSHOT.jar:?]
        ... 31 more
[23:12:41 WARN]: null
[23:12:41 WARN]: null
[23:12:41 INFO]: [NBTAPI] [NBTAPI] The NBT-API seems to be up-to-date!
commented

I am shading

Then fix the shading. de.tr7zw.nbtapi is the official plugin, so this will potentially break any other plugin depending on the nbtapi plugin, and next version will also throw a giant warning into the log that this is wrong. Use info.sokobot.locksmith.nbtapi or so.

Clicked Block: OAK_DOOR Oak doors are also not block entities(tile entities). Random blocks like doors don't have nbt.

commented

Closed, see my last comment.