java.lang.NullPointerException error in my plugin

Discussion in 'Plugin Help/Development/Requests' started by TehCoderHD, Jul 13, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    TehCoderHD

    Stacktrace:
    Stacktrace (open)

    18:36:46 [INFO] TheCoderX issued server command: /ban TheCoderX hi
    18:36:46 [ERROR] null
    18:36:46 org.bukkit.command.CommandException: Unhandled exception executing command 'ban' in plugin Hub v1.0
    18:36:46 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:642) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_71]
    18:36:46 at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_71]
    18:36:46 at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 at java.lang.Thread.run(Unknown Source) [?:1.7.0_71]
    18:36:46 Caused by: java.lang.NullPointerException
    18:36:46 at me.minedeck.pluginmanager.punish.PunishmentCommands.onCommand(PunishmentCommands.java:37) ~[?:?]
    18:36:46 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    18:36:46 ... 14 more

    Code:
    Code:
    if(cmd.getName().equalsIgnoreCase("ban")){
              
              
                // Players
                Player ban = Bukkit.getServer().getPlayer(args[0]);
                String bann = args[0].toString();
                Player banner = (Player) sender;
                String reason = "";
              
                //Creates the reason
                for(int i = 1; i != args.length; i++)
                    reason += args[i] + " ";
              
                //Checks for permission
                if(banner.hasPermission("punish.ban")){
                  
                // Checks for arguments
                  
                  
                if(args.length < 1){
                    banner.sendMessage("§cPunish> §7Usage: §f/ban <player> <reason>");
                }else{
                  
                    //Sets config for player
                    plugin.getConfig().set(bann + ".banned", "true");
                    plugin.getConfig().set(bann + ".banreason", reason);
                  
                    // Sends message to banner
                    banner.sendMessage("§cPunish> §7You banned §d" + ban.getName() + " §7for §d" + reason);
                  
                    //Kicks player banned
                    ban.kickPlayer("§cMinedeck §8- §7Your account has been banned.\n\n§cReason §8> §7" + reason + "\n§cBanned by §8> §7" + banner.getDisplayName() + "\n§7Unfair ban? Appeal on our website,\n§eWebsite: §c§nhttp://minedeck.net/appeal");
                  
                    //Sends notification to console.
                    Server server = Bukkit.getServer();
                   
                    ConsoleCommandSender console = server.getConsoleSender();
                  
                    console.sendMessage(ChatColor.RED + "Punish> " + ChatColor.GRAY + "The player " + ChatColor.YELLOW + args[0].toString() + ChatColor.GRAY + " was banned!");
                }
                }else{
                    banner.sendMessage("§5MDUtils> §7This command requires the rank §a§lMod§7.");
                }
            }
    Please help me fix this error :)
     
  2. Offline

    TarsisPisso

    Hey, post all the code of the class
     
  3. Offline

    Forge_User_45064837 Retired Staff

    @TehCoderHD You are grabbing an argument you haven't checked for.
     
    TehCoderHD likes this.
  4. Offline

    TarsisPisso

    You have to check if the player that will be banned is online

    Code:
    If (ban != null) {
    //CODE
     
    Last edited: Jul 13, 2015
Thread Status:
Not open for further replies.

Share This Page