NullPointerException at onCommand

Discussion in 'Plugin Development' started by Creacan, Jul 29, 2020.

  1. Offline

    Creacan

    Hi guys
    I have a problem with my plugin:
    I want players to be able to teleport between worlds, but when I enter the command I always get this error message:

    [15:21:26 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'bw' in plugin Multiverse v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.16.1.jar:git-Paper-101]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.16.1.jar:git-Paper-101]
    at org.bukkit.craftbukkit.v1_16_R1.CraftServer.dispatchCommand(CraftServer.java:794) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.PlayerConnection.handleCommand(PlayerConnection.java:1912) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.PlayerConnection.a(PlayerConnection.java:1723) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:23) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.TickTask.run(SourceFile:18) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.MinecraftServer.aZ(MinecraftServer.java:1136) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.MinecraftServer.executeNext(MinecraftServer.java:1129) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.MinecraftServer.sleepForTick(MinecraftServer.java:1090) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:1004) ~[patched_1.16.1.jar:git-Paper-101]
    at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$a$0(MinecraftServer.java:177) ~[patched_1.16.1.jar:git-Paper-101]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
    Caused by: java.lang.NullPointerException
    at commands.bauwelt.onCommand(bauwelt.java:15) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.16.1.jar:git-Paper-101]
    ... 18 more

    Does anyone know what that means and above all how I can fix it? Here is the code of the command:

    package commands;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class bauwelt implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String arg2, String[] args) {
    Player p = (Player)sender;

    p.teleport(Bukkit.getWorld("world_build").getSpawnLocation());

    return true;
    }

    }

    Thanks in advance!
     
  2. Online

    KarimAKL

    @Creacan
    1. Please format and syntax hightlight your code along with the error.
    2. I'd recommend learning how to read stacktraces and what they mean.
    3. Don't cast your "sender" to Player without checking if it's an instance of Player first.
    4. The world "world_build" doesn't exist, therefore it's returning null.
     
  3. Offline

    Creacan

    @KarimAKL
    Thank you first, but the world folder "world_build" exists in my server folder. That's why I don't know where my mistake is.
     
  4. Offline

    Wick

    Did you actually load the world? Or did you just put it in your folder?
     
  5. Offline

    Creacan

    How do you mean? So I played the world in single player and then dragged it into the server folder.
     

Share This Page