Solved Commands not Executing

Discussion in 'Plugin Development' started by Butter1484, May 13, 2015.

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

    Butter1484

    I've set up a few different commands with multiple Command Executors and all but one is working. I am setting the executors in
    Code:
        private GamemodeSelector gamemodeSelectorExecutor;
        private PlayerKicker kickerExecutor;
        private PlayerBanner bannerExecutor;
        private PlayerTeleporter teleporterExecutor;
    
    public void onEnable(){
        getCommand("selector").setExecutor(gamemodeSelectorExecutor);
       
        getCommand("kicker").setExecutor(kickerExecutor);
       
        getCommand("banhammer").setExecutor(bannerExecutor);
       
        getCommand("teleporter").setExecutor(teleporterExecutor);
    }
    Then the code in the executor looks like
    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("kicker") && sender instanceof Player){
                Player player = (Player) sender;
    
                if (player.hasPermission("cephalstaff.useKicker")){
                    openGUI(player);
                   
                }
                else {
                    player.sendMessage(ChatColor.RED + "You do not have permission to use the kicker");
                }
                return true;
               
            }
            return false;
        }
    Ok, never mind about just one, they all aren't working now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    Evaluations

    You aren't creating a new instance of any of your command classes.

    Keeping them like;

    private PlayerKicker kickerExecutor;

    and not doing anything with them isn't really doing much.

    Create a new instance of them in your onEnable().
     
  3. Offline

    CoolGamerXD

    @Butter1484
    Check in your command class have you defined the main class? Like this

    Code:java
    1. private kickerExecutor plugin;
    2. public kickerExecutor( [ Your main class] plugin) {
    3. this.plugin = plugin;
    4. }
     
    mine-care likes this.
  4. Offline

    mine-care

    @CoolGamerXD just a correction on your code, you mean
    private PlayerKicker.. Not private kickerExecutor :p
     
    CoolGamerXD likes this.
  5. Offline

    Zombie_Striker

    If this is solved, mark as Solved.
     
  6. Offline

    Butter1484

    @CoolGamerXD All of the executors are also listeners and are already defined because of that
     
  7. Offline

    CoolGamerXD

    @Butter1484 Registering events and registering commands both are different.
     
  8. Offline

    mythbusterma

    Hmmmm doubt it. Show us the code you think is "defining" it.
     
  9. Offline

    Butter1484

    In my main class I have
    Code:
    new PlayerKicker(this);
    Then in the PlayerKicker class I have
    Code:
        public PlayerKicker(CephalStaff cephalStaff) {
            cephalStaff.getServer().getPluginManager().registerEvents(this, cephalStaff);
        }
    The events are registering but the commands in the class do not work
     
  10. Online

    timtower Administrator Administrator Moderator

    @Butter1484 Because that is a different method.
    Something with getCommand("<command here>").setExecutor(this)
    Something along those lines
     
  11. Offline

    Butter1484

    @timtower If you look at my original post you will see I do have that code
     
  12. Online

    timtower Administrator Administrator Moderator

  13. Offline

    Butter1484

    @timtower The commands are not actually executing
     
  14. Online

    timtower Administrator Administrator Moderator

  15. Offline

    Butter1484

  16. Online

    timtower Administrator Administrator Moderator

    @Butter1484 Try
    gamemodeSelectorExecutor = new GamemodeSelector(this);
    instead of just calling the constructor without using it.
     
  17. Offline

    Butter1484

Thread Status:
Not open for further replies.

Share This Page