nsporillo / GlobalWarming

Server side global warming mechanics in Minecraft!
GNU Lesser General Public License v3.0
473 stars 46 forks source link

NullPointerException when running /gw from the console #31

Closed caelunshun closed 4 years ago

caelunshun commented 5 years ago

When running one of the plugin commands from the console, a NullPointerException occurs.

To Reproduce

  1. Run /gw in the console
  2. Command fails with an NPE

Expected behavior Instead of throwing an exception, a message would be sent saying that a player needs to execute the command.

Exception:

[12:35:35 ERROR]: [GlobalWarming] [ACF] Exception in command: gw 
[12:35:35 ERROR]: [GlobalWarming] [ACF] java.lang.NullPointerException
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.GlobalWarming.lambda$registerCommands$1(GlobalWarming.java:122)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.RegisteredCommand.resolveContexts(RegisteredCommand.java:296)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.RegisteredCommand.resolveContexts(RegisteredCommand.java:215)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.RegisteredCommand.invoke(RegisteredCommand.java:149)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.BaseCommand.executeCommand(BaseCommand.java:576)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.BaseCommand.execute(BaseCommand.java:512)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.RootCommand.execute(RootCommand.java:99)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.porillo.shade.aikar.commands.BukkitRootCommand.execute(BukkitRootCommand.java:79)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:151)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:734)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:696)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.minecraft.server.v1_13_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:483)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:440)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:940)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:837)
[12:35:35 ERROR]: [GlobalWarming] [ACF]     at java.lang.Thread.run(Thread.java:748)
nsporillo commented 5 years ago

@caelunshun thanks for the report. Im aware of this issue, it was mostly a design decision aimed at making things easier on the development side. Since a command sender isnt a player, you get that exception.

I plan on updating the command system eventually to support commands from the console.

nsporillo commented 5 years ago

In case anyone is interested in working on this and submitting a PR, the issue here is with how we use ACF (Annotation Command Framework). All of our methods that have the ACF annotations on them take GPlayer as a parameter. On line 136 in GlobalWarming.java, we register an issuer context using the CommandSender as a Player which is what is necessary to convert a command sender to a GPlayer.

However, we wish to add some support for just CommandSenders to issue commands. So we might want to replace GPlayer with CommandSender in all of our method signatures and instead include logic as needed to convert the command sender to a GPlayer when necessary and display error messages as needed.