Wrong code?

Discussion in 'Plugin Development' started by Urag, Aug 6, 2015.

Thread Status:
Not open for further replies.
  1. It's my code:
    Code:
                final Player target = Bukkit.getServer().getPlayer(args[0]);
                if (settings.getData().getConfigurationSection("Bany." + args[0]) == null){
                    System.out.println(args[0]);
                    sender.sendMessage("§cTen gracz nie jest zbanowany");
                    return true;
                }
                settings.getData().set("Bany." + target.getName(), null);
                target.setBanned(false);
                settings.saveData();
                sender.sendMessage("§aOdbanowano " + args[0]);
    When i try to unban not banned player is says "Player is not banned".
    When i try to unban banned player there's an warn in console and command does not work:
    Code:
    [21:26:55] [Server thread/WARN]: Unexpected exception while parsing console command "unban Urag"
    org.bukkit.command.CommandException: Unhandled exception executing command 'unban' in plugin Ban v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    Caused by: java.lang.NullPointerException
        at me.urag.ban.Main.onCommand(Main.java:86) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        ... 8 more
     
  2. Offline

    Eos

    Remove the . you don't need that.

    Also are you running it through console because that usually happens to me when i'm casting player to a sender.
     
  3. This might help you I guess.
     
  4. @Eos
    @amatokus
    Is there an error because i want to unban offline player?
    If i remove "target.setBanned(false);" everything works, but not like i want to.
     
  5. Offline

    Eos

    Code:
                OfflinePlayer off = Bukkit.getOfflinePlayer(args[1]);
    
     
  6. Do a check to see if target != null, always do that check when messing with target players.
     
Thread Status:
Not open for further replies.

Share This Page