[SOLVED]onCommand doesn't work?

Discussion in 'Plugin Development' started by tbsman, Aug 27, 2012.

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

    tbsman

    onCommand always returns false in my plugin, no errors, just false

    here is my code:
    Code:
    package me.tbsman.Lockdown;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class LockdownPlus extends JavaPlugin implements Listener {
        public boolean lockdownmode;
       
        @Override
        public void onEnable() {
        }
        @Override
        public void onDisable() {
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) {
            if (cmd.equals("lockdown") && sender.hasPermission("admin.yay")) {
                if (lockdownmode != true) {
                    lockdownmode = true;
                    for(Player player : Bukkit.getOnlinePlayers()) {
                        if (!player.hasPermission("admin.yay"))
                            player.kickPlayer("This Server is currently under maintenace");
                    }
                    sender.sendMessage("The Server is now in " + ChatColor.GOLD + "LOCKDOWN mode");
                    return true;
                } else {
                    lockdownmode = false;
                    sender.sendMessage("The Server is now in " + ChatColor.GOLD + "open mode!");
                    return true;
                }
               
               
               
                }
                return false;
            }
           
           
       
        public void onPlayerJoin(PlayerLoginEvent event) {
            if (event.getPlayer().hasPermission("admin.yay") != true && lockdownmode == true) {
                event.getPlayer().kickPlayer("This Server is currently under maintenace");
            }
        }
    }
    
    I'm sure I'm just missing something simple.
     
  2. Offline

    Lolmewn

    Did you register the command in plugin.yml?
    Also, try adding @Override above onCommand.

    Also, your event misses the @EventHandler annotation.

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

    sternmin8or

    oncommands dont need @EventHandler, I think your first solution is the correct one.
     
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    You're comparing a Command and a String. You want cmd.getName().equals
     
  5. Offline

    tbsman

    Thanks, works now. That's what you get when coding at night
     
  6. Offline

    Lolmewn

    No, your event needs the annotation.
     
  7. Offline

    sternmin8or

    oh, didnt event see that tiny event at the bottom, my bad XD
     
Thread Status:
Not open for further replies.

Share This Page