Unknown Error?

Discussion in 'Plugin Development' started by Quidam, Jan 16, 2013.

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

    Quidam

    I am beyond confused why this is throwing errors.

    It throws an error at this line:
    Code:
    listen.infract(args[0]);
                        Integer.parseInt(args[1], listen.pointamount);
    listen is my listener, and infract is a method. Here is the method:
    Code:
        public void infract(String s){
            if(Bukkit.getServer().getPlayer(s) != null){
                namedplayer = Bukkit.getServer().getPlayer(s);
                stupidity.put(namedplayer, pointamount);
                if(plugin.admin != null){
                    plugin.admin.sendMessage(ChatColor.GREEN + namedplayer.getDisplayName() + " had " + pointamount + " point(s) added to their infraction level.");
                    if(plugin != null){
                        if(pointamount >= 0){
                            namedplayer.sendMessage(ChatColor.RED + "You had " + pointamount + " point(s) added to your infraction level.");
                            namedplayer.sendMessage(ChatColor.RED + "Your current infraction level is " + stupidity.get(namedplayer));
                            namedplayer.sendMessage(ChatColor.RED + "Get to 100 points and you'll be banned.");
                        }
                        if(pointamount < 0){
                            namedplayer.sendMessage(ChatColor.GREEN + "You had points removed from your infraction level! Good job!");
                            namedplayer.sendMessage(ChatColor.GREEN + "Your current infraction level is " + stupidity.get(namedplayer));
                        }
                    }
                    else{
                        plugin.admin.sendMessage(ChatColor.RED + "Please specifiy a value.");
                    }
                    plugin.getConfig().set(namedplayer.getName(), stupidity.get(namedplayer));
                }
            }
            else{
                if(plugin.admin != null){
                    plugin.admin.sendMessage(ChatColor.RED + "The player could not be found! Are they online?");
                    plugin.admin.sendMessage(ChatColor.RED + "If this is an error, please contact KaiBB or an admin.");
                }
                else{
                    plugin.log.severe("The player could not be found! Are they online?");
                    plugin.log.severe(ChatColor.RED + "If this is an error, please contact KaiBB or an admin.");
                }
            }
        }
     
  2. Offline

    fireblast709

    Quidam If you want me to guess, there is ArrayIndexOutOfBoundsException, NumberFormatException or NullPointerException... If you want a solution, post the actual stacktrace
     
    devilquak likes this.
  3. Offline

    Quidam

    Code:
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'infract' in plugin Infraction v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
        at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCommand(CraftServer.java:514)
        at net.minecraft.server.v1_4_6.PlayerConnection.handleCommand(PlayerConnection.java:979)
        at net.minecraft.server.v1_4_6.PlayerConnection.chat(PlayerConnection.java:897)
        at net.minecraft.server.v1_4_6.PlayerConnection.a(PlayerConnection.java:852)
        at net.minecraft.server.v1_4_6.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_4_6.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.v1_4_6.PlayerConnection.d(PlayerConnection.java:112)
        at net.minecraft.server.v1_4_6.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at kai.infraction.Main.onCommand(Main.java:56)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
     
  4. Offline

    fireblast709

    check if args.length > 0 before you use it in infract(String) :p
     
    Quidam likes this.
  5. Offline

    Quidam

    WOW. Thanks! I totally forgot about that xD

    fireblast709
    It throws a NullPointerException for:
    Code:
    if(Bukkit.getServer.getPlayer(plugin.admin.getName()) != null){
    Bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    ZeusAllMighty11

    is plugin null,

    what is 'admin' ?
     
  7. Offline

    Quidam

    plugin is my Main class, and admin is a CommandSender instanceof Player. Neither are null.
     
  8. Offline

    fireblast709

    then why the stacktrace eh :3. Post both the stacktrace and the code
     
  9. Offline

    Quidam

    fireblast709
    Stacktrace from console:
    Code:
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'infract' in plugin Infraction v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
        at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCommand(CraftServer.java:514)
        at net.minecraft.server.v1_4_6.PlayerConnection.handleCommand(PlayerConnection.java:979)
        at net.minecraft.server.v1_4_6.PlayerConnection.chat(PlayerConnection.java:897)
        at net.minecraft.server.v1_4_6.PlayerConnection.a(PlayerConnection.java:852)
        at net.minecraft.server.v1_4_6.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_4_6.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.v1_4_6.PlayerConnection.d(PlayerConnection.java:112)
        at net.minecraft.server.v1_4_6.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
        at kai.infraction.EventListener.infract(EventListener.java:40)
        at kai.infraction.Main.onCommand(Main.java:56)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    The section of EventListener that contains line 40:
    Code:
        public void infract(String s){
            if(Bukkit.getServer().getPlayer(s) != null){
                namedplayer = Bukkit.getServer().getPlayer(s);
                stupidity.put(namedplayer, pointamount);
                if(Bukkit.getServer().getPlayer(plugin.admin.getName()) != null){
                    plugin.admin.sendMessage(ChatColor.GREEN + namedplayer.getDisplayName() + " had " + pointamount + " point(s) added to their infraction level.");
                    if(plugin != null){
                        if(pointamount >= 0){
                            namedplayer.sendMessage(ChatColor.RED + "You had " + pointamount + " point(s) added to your infraction level.");
                            namedplayer.sendMessage(ChatColor.RED + "Your current infraction level is " + stupidity.get(namedplayer));
                            namedplayer.sendMessage(ChatColor.RED + "Get to 100 points and you'll be banned.");
                        }
                        if(pointamount < 0){
                            namedplayer.sendMessage(ChatColor.GREEN + "You had points removed from your infraction level! Good job!");
                            namedplayer.sendMessage(ChatColor.GREEN + "Your current infraction level is " + stupidity.get(namedplayer));
                        }
                    }
                    else{
                        plugin.admin.sendMessage(ChatColor.RED + "Please specifiy a value.");
                    }
                    plugin.getConfig().set(namedplayer.getName(), stupidity.get(namedplayer));
                }
            }
            else{
                if(plugin.admin != null){
                    plugin.admin.sendMessage(ChatColor.RED + "The player could not be found! Are they online?");
                    plugin.admin.sendMessage(ChatColor.RED + "If this is an error, please contact KaiBB or an admin.");
                }
                else{
                    plugin.log.severe("The player could not be found! Are they online?");
                    plugin.log.severe(ChatColor.RED + "If this is an error, please contact KaiBB or an admin.");
                }
            }
        }
    NOTE: Line 40 is
    Code:
    if(Bukkit.getServer().getPlayer(plugin.admin.getName()) != null){
    The section of Main that contains line 56:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("infract")){
                if(sender instanceof Player){
                    admin = (Player)sender;
                        listen.infract(args[0]);
                        if(args.length > 0){
                            Integer.parseInt(args[1], listen.pointamount);
                        }
                }
                else{
                    admin = null;
                }
                return true;
            }
            if(cmd.getName().equals("infractionlevel")){
                if(sender instanceof Player){
                    Player p = (Player)sender;
                    if(listen.stupidity.get(p) != null){
                        p.sendMessage(ChatColor.GOLD + "Your infraction level is " + listen.stupidity.get(p) + ".");
                    }
                    else{
                        p.sendMessage(ChatColor.GOLD + "Your infraction level is 0.");
                    }
                }
                else{
                    log.severe(ChatColor.RED + "This command can only be used by players.");
                }
            }
            return false;
        }
    NOTE: Line 56 is
    Code:
    listen.infract(args[0]);
     
  10. Offline

    fireblast709

    the only thing I can think of is plugin or admin being null
     
  11. Offline

    Quidam

    plugin is defined only once, and it is set as the class Main. So it's not plugin. That leaves admin to be null, but how can CommandSender be null?
     
  12. Offline

    fireblast709

    why do you even have a CommandSender variable in the main class?
     
  13. Offline

    Quidam

    I'm putting my commands in the Main, not a CommandExecutor.

    Wait, I just realized I haven't registered the commands in onEnable. Could that be what's throwing a NullPointerException?

    fireblast709

    Registered them in onEnable(). No change in the errors.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  14. Offline

    fireblast709

    you should just pass along the Player object as parameter
     
  15. Offline

    ZachBora

    Isn't it Bukkit.getServer()? With parenthesis?

    Edit: Nvm didn't scroll to where it because ()
     
  16. Offline

    Quidam

    I don't quite understand what you're suggesting
     
  17. Offline

    fireblast709

    public void infract(String s, Player sender)
     
  18. Offline

    Quidam

    Oh, you meant in my method. I suppose it's worth a shot.
     
Thread Status:
Not open for further replies.

Share This Page