JorelAli / CommandAPI

A Bukkit/Spigot API for the command UI introduced in Minecraft 1.13

Home Page:https://commandapi.jorel.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullPointer while fixing permissions

alkanife opened this issue · comments

CommandAPI version

8.7.5

Minecraft version

1.19.3

Are you shading the CommandAPI?

No

What I did

I was editing the commands.yml file of my paper server to disable some commands.
Like this:

command-block-overrides: []
ignore-vanilla-permissions: false
aliases:
  help:
  - []
  '?':
  - []

What actually happened

By modifying commands.yml the commands 'help' and '?' have been removed. However, this caused the plugin to throw a NullPointerException when trying to fix command permissions, after my change.

What should have happened

I expected CommandAPI to simply ignore these now removed commands.

Server logs and CommandAPI config

I use the default config.yml for CommandAPI.

Error trace:

[09:35:17 INFO]: Running delayed init tasks
[09:35:17 WARN]: [CommandAPI] Task #3 for CommandAPI v8.7.5 generated an exception
java.lang.NullPointerException: Cannot invoke "org.bukkit.command.Command.setPermission(String)" because the return value of "org.bukkit.command.CommandMap.getCommand(String)" is null
        at dev.jorel.commandapi.CommandAPIHandler.fixPermissions(CommandAPIHandler.java:529) ~[CommandAPI-8.7.5.jar:?]
        at dev.jorel.commandapi.CommandAPI.lambda$onEnable$0(CommandAPI.java:199) ~[CommandAPI-8.7.5.jar:?]
        at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.19.3.jar:git-Paper-404]
        at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[paper-1.19.3.jar:git-Paper-404]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1114) ~[paper-1.19.3.jar:git-Paper-404]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316) ~[paper-1.19.3.jar:git-Paper-404]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
[09:35:17 INFO]: Done (4.501s)! For help, type "help"

Other

The best way I found to fix the bug was to re-add a value to the disabled commands. Like this:

command-block-overrides: []
ignore-vanilla-permissions: false
aliases:
  help:
  - minecraft:help
  '?':
  - minecraft:help

However, doing this does not disable the commands, it just creates aliases. It would be cool if CommandAPI ignored null commands, or even had an option to disable the permission fix, that creates problems sometimes.

Thank you for reading.

Thanks for raising the issue, I'll see if I can get a release out that fixes this within the next 3 days.

Also worth noting, aliases accepts an object with list values. As such, this is valid because help is a list containing minecraft:help:

command-block-overrides: []
ignore-vanilla-permissions: false
aliases:
  help:
  - minecraft:help
  '?':
  - minecraft:help

However, your example above uses a list of lists: you have help with a single list entry (denoted with the - character), which has the value of an empty list:

command-block-overrides: []
ignore-vanilla-permissions: false
aliases:
  help:
  - []
  '?':
  - []

Presumably you just wanted to assign an empty list (as opposed to a list containing an empty list), so you probably wanted something along the lines of this:

command-block-overrides: []
ignore-vanilla-permissions: false
aliases:
  help: []
  '?': []

Oh, thank you for pointing this out to me, I'm not really familiar with the yaml haha. Unfortunately doing it this way doesn't seems to change the error on my side, but I greatly appreciate your response! :)

@alkanife I have been having trouble reproducing the issue you've raised. Perhaps there may be some paper version differences or changes to the CommandAPI's config.yml file?

I'm running git-Paper-420 (you can find this with /version) with CommandAPI 8.7.5

[20:31:21 INFO]: This server is running Paper version git-Paper-420 (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT) (Git: 81d7ff6)
You are running the latest version

That said, I did make an attempt to fix this issue! Since I was never able to reproduce the issue on my machine, it also means I can't test if this actually fixes the issue or not. If you would be willing to try this dev build of 8.7.6 and get back to me if it fixes your issue, that would be great: CommandAPI-8.7.6_24_Feb_2023_(08-25-50pm).zip

(Unzip the file and use the .jar file as a drop in replacement for CommandAPI-8.7.5.jar)

I was using the same paper version as you, and I never changed the CommandAPI configuration.

I tested your dev build and I'm happy to tell you that it fixes the problem! No more errors.

Thanks a lot :)

Fixed in version 8.7.6 (this is effectively identical to the dev build above, but it deserves a proper release)