Solved Command doesn't work

Discussion in 'Spigot Plugin Development' started by BroodRooster, Jun 19, 2016.

Thread Status:
Not open for further replies.
  1. Hi all!

    I'm trying to make a new plugin. But now I got a problem, but I can't solve it by my own. So hopefully u guys can help. So here's my code:

    Code (Text):
            if (command.getName().equalsIgnoreCase("achievements")) {
                if(!sender.hasPermission("achievements.test")) {
                    sender.sendMessage("§2Achievements §8- §cHé! Hier heb je geen toegang tot!");
                    return true;
                }
                if(args.length <= 1) {
                    sender.sendMessage("§2Achievements §8- §7/achievements <achievementsnaam> <speler>");
                    return true;
                }
                Player target = Bukkit.getPlayer(args[1]);
                if(target == null) {
                    sender.sendMessage("§2Achievements §8- §7De speler: §c" + target.getName() + "§7 is niet online!");
                }
                if (args[0].equalsIgnoreCase("test")) {
                    if(AchievementsConfig.getString(target.getName() + ".Test").contains("false")) {
                        target.sendMessage(" ");
                        target.sendMessage("§7-=[ §2Achievements §7]=-");
                        target.sendMessage("§7Je hebt de achievement: §cTest§7, gehaald!");
                        target.sendMessage("§7-=[ §2Achievements §7]=-");
                        target.sendMessage(" ");
                       
                        sender.sendMessage("§2Achievements §8- §7Je hebt de achievement toegewezen.");
                       
                        AchievementsConfig.set(target.getName() + ".Test", "true");
                        AchievementsConfig.saveConfig();
                        return true;
                    }
                }
            }
    I don't know what I'm doing wrong so hopefully u can help me out here.

    Goodbye,
    BroodRooster
     
  2. What's the error?
     
  3. the error:
    Code (Text):
    [17:56:43] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'achievements' in plugin Achievements v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[server.jar:git-Spigot-044d928-e8c6403]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[server.jar:git-Spigot-044d928-e8c6403]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:642) ~[server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1135) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:970) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [server.jar:git-Spigot-044d928-e8c6403]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [server.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [server.jar:git-Spigot-044d928-e8c6403]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
        at nl.Achievements.Main.onCommand(Main.java:36) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[server.jar:git-Spigot-044d928-e8c6403]
        ... 15 more
     
  4. Caused by: java.lang.NullPointerException
    at nl.Achievements.Main.onCommand(Main.java:36)
    Something is null at line 36 in class Main
     
  5. Thx I've solved the error ;D. It works right now.
     
  6. NullPointerException is the keyword. Looks like you forget to check if args[1] at Player target = Bukkit.getPlayer(args[1]); is given.
     
Thread Status:
Not open for further replies.