Command Returning False (Showing Usage)

Discussion in 'Spigot Plugin Development' started by Airbornz, Jun 30, 2015.

  1. Hello, in this command its returning false for some reason and I don't get why? It should always return true...
    I've tried getting help from the bukkit forums with no fix, hopefully I can find it here. This plugin is running on a spigot server with bungeecord.

    Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (sender instanceof Player){
                Player player = (Player)sender;
                UUID uuid = player.getUniqueId();
                if (StaffManager.isStaff(player)){
                    if (StaffManager.getStaffLevel(uuid).equals(StaffLevel.Owner)){
                        if (args.length == 4){
                            if (args[0].equalsIgnoreCase("user")){
                                Player target = Bukkit.getPlayer(args[1]);
                                if (target != null){
                                    if (args[2].equalsIgnoreCase("add")){
                                        PermissionManager.addPermission(target.getUniqueId(), args[3]);
                                        player.sendMessage("§eAdded permission "+args[3]+" to player "+target.getName()+".");
                                    }
                                    else if (args[2].equalsIgnoreCase("remove")){
                                        PermissionManager.removePermission(target.getUniqueId(), args[3]);
                                        player.sendMessage("§eRemoved permission "+args[3]+" from player "+target.getName()+".");
                                    }
                                    else if (args[2].equalsIgnoreCase("addgroup")){
                                        PermissionManager.addtoGroup(target.getUniqueId(), args[3]);
                                        player.sendMessage("§eAdded player "+target.getName()+" to group "+args[3]+".");
                                    }
                                    else if (args[2].equalsIgnoreCase("removegroup")){
                                        PermissionManager.removefromGroup(target.getUniqueId(), args[3]);
                                        player.sendMessage("§eRemoved player "+target.getName()+" from group "+args[3]+".");
                                    }
                                    else{
                                        AlertManager.sendBadArguments(player);
                                    }
                                }
                                else{
                                    AlertManager.sendPlayerNotFound(player, args[1]);
                                }
                             
                            }
                            else if (args[0].equalsIgnoreCase("group")){
                                String group = args[1];
                                if (args[2].equalsIgnoreCase("add")){
                                    PermissionManager.addPermission(group, args[3]);
                                    player.sendMessage("§eAdded permission "+args[3]+" to group "+group+".");
                                }
                                else if (args[2].equalsIgnoreCase("remove")){
                                    PermissionManager.removePermission(group, args[3]);
                                    player.sendMessage("§eRemoved permission "+args[3]+" from group "+group+".");
                                }
                                else if (args[2].equalsIgnoreCase("adduser")){
                                    Player target = Bukkit.getPlayer(args[3]);
                                    if (target != null){
                                        PermissionManager.addtoGroup(target.getUniqueId(), group);
                                        player.sendMessage("§eAdded player "+target.getName()+" to group "+group+".");
                                    }
                                    else{
                                        AlertManager.sendPlayerNotFound(player, args[3]);
                                    }
                                }
                                else if (args[2].equalsIgnoreCase("removeuser")){
                                    Player target = Bukkit.getPlayer(args[3]);
                                    if (target != null){
                                        PermissionManager.removefromGroup(target.getUniqueId(), group);
                                        player.sendMessage("§eRemoved player "+target.getName()+" from group "+group+".");
                                    }
                                    else{
                                        AlertManager.sendPlayerNotFound(player, args[3]);
                                    }
                                }
                                else{
                                    AlertManager.sendBadArguments(player);
                                }
                            }
                            else{
                                AlertManager.sendBadArguments(player);
                            }
                        }
                        else{
                            AlertManager.sendBadArguments(player);
                        }
                    }
                    else{
                        AlertManager.sendNoPermission(player);
                    }
                }
                else{
                    AlertManager.sendNoPermission(player);
                }
            }
            else{
                AlertManager.sendOnlyPlayerUse(sender);
            }
            return true;
        }
     
  2. Also to address somethings people were saying on the Bukkit forums. No I dont have (cmd == "gp") because i registered an executor in the core file, the plugin.yml is setup correctly. No, no overriding commands, tried switched the server and I tried setting the command to random numbers, still returning usage.
     
  3. sothatsit

    Patron

    Only thing I can think of where it may send the usage message is if the code throws an error. This method will never return false though.
     
  4. Ok I have this connect to a class PermissionManager that does a lot of work for this command involving yaml etc, if that throws an error this will return false? Also Im not getting any stack traces or anything.
     
  5. graywolf336

    Supporter

    Do you have a try/catch anywhere that would catch the errors silently and not throw them?
     
  6. sothatsit

    Patron

    No, if it throws an error it won't return false, but the command handler part of spigot may catch the error and send the usage message. Try adding a try catch around it all and then print any errors that are thrown.
     
  7. Turns out gp is somewhere an internal command - Switching to aperm, yet no changing any code, worked :/ yet I cant find it anywhere, weird bug.
     
  8. sothatsit

    Patron

    Ah, strange. Good to know. Glad you fixed it.