Geitenijs / CommandBlocks

The most versatile plugin for assigning commands to blocks!
Other
1 stars 0 forks source link

Command Blocks generates NullPointerException #18

Closed Darkfinst12 closed 11 months ago

Darkfinst12 commented 11 months ago

Describe the bug If a Command Block is right-clicked, it throws a java.lang.NullPointerException

To Reproduce Steps to reproduce the behavior:

  1. Create a Command Block
  2. Remove the Permission of the Command Block
  3. See error

Expected behavior Not throwing a java.lang.NullPointerException

Screenshots

[17:10:50 ERROR]: Could not pass event PlayerInteractEvent to CommandBlocks v1.2.9
java.lang.NullPointerException: permission
        at me.lucko.luckperms.bukkit.inject.permissible.LuckPermsPermissible.hasPermission(LuckPermsPermissible.java:169) ~[?:?]
        at org.bukkit.craftbukkit.v1_20_R2.entity.CraftHumanEntity.hasPermission(CraftHumanEntity.java:233) ~[paper-1.20.2.jar:git-Paper-280]
        at com.geitenijs.commandblocks.Events.onCommandBlockInteract(Events.java:35) ~[CommandBlocks-1.2.9.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor82.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:81) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:git-Paper-280]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[paper-1.20.2.jar:git-Paper-280]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:126) ~[paper-1.20.2.jar:git-Paper-280]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:615) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:593) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.level.ServerPlayerGameMode.useItemOn(ServerPlayerGameMode.java:537) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItemOn(ServerGamePacketListenerImpl.java:1907) ~[?:?]
        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$0(PacketUtils.java:53) ~[?:?]
        at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.20.2.jar:git-Paper-280]
        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:1324) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:193) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1301) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1294) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1272) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1160) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:315) ~[paper-1.20.2.jar:git-Paper-280]
        at java.lang.Thread.run(Thread.java:1589) ~[?:?]

Environment (please complete the following information):

Additional context It can be fixed by adding a Null Check at line 34 in Events.java It could look like this:

 for (final String path : Utilities.blocks.getKeys(false))
 {
    if (Utilities.blocks.getString(path + ".location") != null && Objects.equals(Utilities.blocks.getString(path + ".location"), convertedBlockLocation)) 
    {
    String permission = Utilities.blocks.getString(path + ".permission.value"))
    if(permission == null)
    {
        //Ether send a Message to the Player that the Command Block is not Valid and needs to Contact an Admin
        //Or Send a Console Message that the Command Block could not be executed due to missing permission
        continue;
    }
     if (e.getPlayer().hasPermission(permission) 
     {
        //The rest of your code
     }
 }

But I would recommend making the check at an earlier stage, like the loading of the config.

Geitenijs commented 11 months ago

While it is stated in the configuration file not to leave the permission value empty, this is a bit sloppy from my side.

Will be addressed in the next release, thanks for pointing it out!