Solved Command Not working?

Discussion in 'Plugin Development' started by Verify_x, Feb 17, 2014.

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

    Verify_x

    I'm creating a simple plugin that when you type in a command a message pops up.
    ex: Player types /help, a help menu comes up.
    For some reason it's not working! I did the plugin.yml correctly, I'm not getting any errors in the code, or console. I imported all the commands to the main class file. It doesn't say unknown command when I type it, it says nothing at all. Any idea what it might be?
     
  2. Offline

    random_username

    Could you post your code please? :)
     
  3. Offline

    Verify_x

    Sure
    Code:
    package me.verify.main;
     
    import me.verify.main.InventoryListener;
    import me.verify.main.PlayerListener;
     
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class Main extends JavaPlugin {
       
       
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
             
              pm.registerEvents(new InventoryListener(), this);
              pm.registerEvents(new PlayerListener(), this);
              getCommand("help").setExecutor(new Help());
              getCommand("ecohelp").setExecutor(new EcoHelp());
              System.out.println("cPVP Enabled!");
        }
     
        public void onDisable() {
              System.out.println("cPVP Enabled!");
        }
       
    }

    Code:
    package me.verify.main;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class Help implements CommandExecutor {
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] arg3) {
              if(!(sender instanceof Player)) {
                  Player player = (Player)sender;
                  if(commandLabel.equalsIgnoreCase("ecohelp")){
                      player.sendMessage(ChatColor.DARK_GRAY + "<========== " + ChatColor.GRAY + "Help Menu " + ChatColor.DARK_GRAY + "==========>");
                      player.sendMessage(ChatColor.GRAY + "Team help - /team");
                      player.sendMessage(ChatColor.GRAY + "Tracking help - /track help");
                      player.sendMessage(ChatColor.GRAY + "Request a teleport to a player - /tpa <PlayerName>");
                      player.sendMessage(ChatColor.GRAY + "Deny a teleport request - /tpdeny");
                      player.sendMessage(ChatColor.GRAY + "Teleport to Spawn Location - /spawn");
                      player.sendMessage(ChatColor.GRAY + "Warp help - /go");
                      player.sendMessage(ChatColor.GRAY + "List all the staff - /staff");
                      player.sendMessage(ChatColor.GRAY + "Donate t our server - /donate");
                      player.sendMessage(ChatColor.GRAY + "Send a player a private message - /msg");
                      player.sendMessage(ChatColor.GRAY + "Economy help - /ecohelp");
                      player.sendMessage(ChatColor.GRAY + "List given kits - /kit");
                      player.sendMessage(ChatColor.GRAY + "List online players - /who");
                      player.sendMessage(ChatColor.GRAY + "Accept a teleport request - /tpyes");
                  }
              }
            return false;
        }
       
    }
    
     
  4. Offline

    Harmings

    Verify_x
    You're checking if the sender isn't a player when you have the '!'. Remove the !
     
    random_username likes this.
  5. Offline

    random_username

    Verify_x
    You're making the command ecohelp in the Help class. In your main class, you're setting the command "ecohelp" to the class EcoHelp. Shouldn't the ecohelp command have the Help class as Command executor?

    Edit:
    Also that which I didn't notice :p Good point. :D
     
  6. Offline

    Verify_x

    Thanks a lot man.

    haha, thanks a lot man!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page