Command Returning Usage (Returning false)

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

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

    Airbornz

    Hello, in this command its returning false for some reason and I don't get why? It should always return true...

    Code:
    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. Did you literally print out the result of onCommand to see if it's returning false? Maybe it's not returning false, and it's just not been registered. Have you set the executor in onEnable() to the class which this onCommand method is in (if it's in another class that is) and have you registered the command in plugin.yml?
     
  3. @Airbornz I think you may have forgotten something...
    Code:
    if (cmd.getName().equalsIgnoreCase("command")) {}
     
  4. Offline

    Airbornz

    You really dont need that, since I set this in core
    Code:
    getCommand("gp").setExecutor(new PermissionsCommand());
    Yes I have registered it in the plugin.yml, yes I set executor in the core class.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  5. @Airbornz Ah, my bad. I completely forgot you could do that. So, let me get this straight. When you run the command it returns false. As in, it sends you "/gp", and that's it?
     
  6. Offline

    Airbornz

    Well the entire usage from the plugin.yml but yes.

    Read above forgot to tag :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  7. @Airbornz This is strange... Post the plugin.ml and the main class for me.
     
  8. Has this got anything to do with it?
     
  9. Offline

    Airbornz

    Nope just sends the player a message, doesnt return false

    Main class:
    Code:
    package com.Airbornz.AirAPI.Core;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.Airbornz.AirAPI.Extras.DonorJoin;
    import com.Airbornz.AirAPI.Extras.NotificationsJoinMessage;
    import com.Airbornz.AirAPI.Extras.SilentJoinQuit;
    import com.Airbornz.AirAPI.Friends.FriendCommand;
    import com.Airbornz.AirAPI.Friends.FriendManager;
    import com.Airbornz.AirAPI.Inventories.NotificationsInv;
    import com.Airbornz.AirAPI.Inventories.Settings;
    import com.Airbornz.AirAPI.MiniGame.TimeManager;
    import com.Airbornz.AirAPI.PlayerManagment.PermissionsCommand;
    import com.Airbornz.AirAPI.PlayerManagment.ProfileCreator;
    import com.Airbornz.AirAPI.Punisher.BanCommand;
    import com.Airbornz.AirAPI.Punisher.KickCommand;
    import com.Airbornz.AirAPI.Punisher.TempBanCommand;
    import com.Airbornz.AirAPI.Punisher.UnbanCommand;
    import com.Airbornz.AirAPI.ReportSystem.CombatFlags;
    import com.Airbornz.AirAPI.ReportSystem.ReportCommand;
    
    public class Core extends JavaPlugin{
    
        private static final Double version = 3.0;
        private static final BuildType buildPro = BuildType.Alpha;
        private static File pluginFolder;
        private static final UUID airbornzUUID = UUID.fromString("cd89cc12-718a-4b9a-983c-516e8cc3fddd");
        private static Plugin pl;
       
        @Override
        public void onEnable(){
            Bukkit.getLogger().info("Starting AirAPI version "+getVersion());
            pl = this;   
            pluginFolder = new File("/home/skylarnetwork/AirAPI");
            AlertManager.loadDefaultPrefixes();
            File file = new File(getPluginFolder() + "/bans.yml");
            if (!file.exists()){
                createBanFile();
            }
            //TODO Register listeners etc.
            Bukkit.getLogger().info("Running AirAPI version "+getVersion());
            // Ouput warning messages for unsupported builds!
            if (buildPro.equals(BuildType.Alpha)){getLogger().warning("You are running an Alpha build of AirAPI, this may be unfinshed, use at your own risk.");}
            else if (buildPro.equals(BuildType.Beta)){getLogger().warning("You are running an Beta build of AirAPI, this may be unfinshed, use at your own risk.");}
            // Register listeners
            Bukkit.getServer().getPluginManager().registerEvents(new SilentJoinQuit(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new ProfileCreator(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new CombatFlags(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new BanCommand(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new DonorJoin(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new NotificationsInv(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new NotificationsJoinMessage(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new FriendManager(), this);
            // Register commands
            getCommand("report").setExecutor(new ReportCommand());
            getCommand("ban").setExecutor(new BanCommand());
            getCommand("kick").setExecutor(new KickCommand());
            getCommand("tempban").setExecutor(new TempBanCommand());
            getCommand("unban").setExecutor(new UnbanCommand());
            getCommand("settings").setExecutor(new Settings());
            getCommand("notifications").setExecutor(new NotificationsInv());
            getCommand("friend").setExecutor(new FriendCommand());
            getCommand("gp").setExecutor(new PermissionsCommand());
            // Register runnables
            Bukkit.getScheduler().runTaskTimer(this, new TimeManager(), 20, 20);
            Bukkit.getScheduler().runTaskTimer(this, new CombatFlags(), 20, 20);
           
        }
       
        /**
         * Gets the version of the project.
         * @return The version (Double)
         */
        public static Double getVersion(){
            return version;
        }
       
        /**
         * Gets the build type of the project.
         * @return The build type (BuildType)
         */
        public static BuildType getBuildType(){
            return buildPro;
        }
       
        public static File getPluginFolder(){
            return pluginFolder;
        }
       
        /**
         * Gets My UUID.
         */
        public static UUID getAirbornzUUID(){
            return airbornzUUID;
        }
       
        public void createBanFile(){
            File file = new File(getPluginFolder() + "/bans.yml");
            YamlConfiguration yaml = new YamlConfiguration();
            try {
                yaml.createSection("Bans");
                yaml.save(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
       
        public static Plugin getPlugin(){
            return pl;
        }
       
    }
    
    Plugin.yml
    Code:
    name: AirAPI
    main: com.Airbornz.AirAPI.Core.Core
    version: 3.0
    author: Airbornz
    commands:
      report:
        usage: /report (player) (reason)
        description: Report a player.
      ban:
        usage: /ban (player) (reason)
        description: Ban a player.
      kick:
        usage: /kick (player) (reason)
        description: Kick a player.
      unban:
        usage: /unban (player)
        description: Unban a player.
      tempban:
        usage: /tempban (player) (time) (reason)
        description: Tempban a player.
      settings:
        usage: /settings
        description: Opens the settings menu.
      notifications:
        usage: /notifications
        description: Opens the notifications menu.
      gp:
        usage: /gp (user/group) (name/player) (add/remove/addgroup/removegroup) (permission/group/player)
        description: Allows use of global permissions.
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  10. That's very weird, I have no idea why this'd occur. The only reason I can think of is that another plugin also has the command 'gp' and overwrites this one, but I doubt that's it.
     
  11. Offline

    Airbornz

    Tried switching it to just completely random numbers still returned false
     
  12. Maybe an error is being thrown? Check the console.

    Anyway, I forgot to mention this, but try debugging.

    In a few randomly selected places that seem good, put System.out.println(incrementingNumber++);

    'incrementingNumber' being an int, made at the top inside the onCommand method.

    See if it's printing anything, and see where it gets up to. If it doesn't print anything, the command class isn't being registered properly...
     
    CodePlaysMinecraft likes this.
Thread Status:
Not open for further replies.

Share This Page