For some reason, getting Unknown Command.

Discussion in 'Plugin Development' started by kayc01, Jan 3, 2016.

Thread Status:
Not open for further replies.
  1. Hey, started on a new plugin but i get Unknown command when i type /arena in game.

    Here is some of my code:

    Code:
    public class Main extends JavaPlugin implements Listener {
       
        //private Map<Integer, List<Player>> inArena;
        private List<Player> inArena2;
       
        Boolean allowAll = false;
       
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
       
        //private static Main instance;
       
        SettingsManager settings = SettingsManager.getInstance();
    
        public void onEnable()
          {
            getServer().getPluginManager().registerEvents(this, this);
           
            settings.setup(this);
           
            //inArena = new HashMap<Integer, List<Player>>();
            inArena2 = new ArrayList<Player>();
           
            //instance = this;
          }
       
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onKill(EntityDeathEvent e)
        {
           
            if (e.getEntity().getType() == EntityType.PLAYER && e.getEntity().getKiller().getType() == EntityType.PLAYER) {
               
                Player pkilled = (Player) e.getEntity();
                Player pkiller = (Player) e.getEntity().getKiller();   
       
        Player killerName = e.getEntity().getKiller();
       
        if (killerName instanceof Player ) {
           
           
       
        Bukkit.broadcastMessage(ChatColor.GREEN + pkilled.getName() + ChatColor.GOLD + " has been slain by " + ChatColor.RED + pkiller.getName() + ChatColor.GOLD + " with a " + killerName.getInventory().getItemInHand().getType());
        for (Player players : Bukkit.getOnlinePlayers()) {
           
            //Player playersOnline = Bukkit.getOnlinePlayers();
           
            Titles.sendTitle(players, 3, 10, 3, ChatColor.GREEN + pkilled.getName() + ChatColor.GOLD + " has been slain by " + ChatColor.RED + pkiller.getName() + ChatColor.GOLD + " with a " + killerName.getInventory().getItemInHand().getType());
            Titles.sendSubtitle(players, 3, 10, 3, ChatColor.GOLD + "There are " + inArena2.size() + " Players left!");
       
        players.playSound(players.getLocation(), Sound.AMBIENCE_THUNDER, 2F, 1F);   
            }   
        }
            }
       
       
                }
       
         @EventHandler
         public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
              Player p = (Player)sender;
             
              if (commandLable.equalsIgnoreCase("arena")) {
                  if (args.length == 0) {
                      if (p.hasPermission("arena.admin")) {
                          p.sendMessage(ChatColor.GREEN + "/arena setwarp waitarea - Sets the waiting area location");
                          p.sendMessage(ChatColor.GREEN + "/arena start - Stats the game by teleporting players to the random locations");
                          p.sendMessage(ChatColor.GREEN + "/arena fillslots - Allows any players to join the arena without the permission");
                      }
                      else {
                      p.sendMessage(ChatColor.GREEN + "/arena join");
                      }
                      }
                  else if (args.length == 1) {
                      if (args[0].equalsIgnoreCase("join")) {
                          if (allowAll == true) {
                          inArena2.add(p);
                         
                          p.sendMessage(ChatColor.GREEN + "You have sucesfully joined the arena, teleporting to waiting area.");
                         
                          if (settings.getData().getConfigurationSection("warps.waitarea") == null) {
                                p.sendMessage(ChatColor.RED + "Warp waitarea does not exist!");
                                return true;
                        }
                            World w = Bukkit.getServer().getWorld(settings.getData().getString("warps.waitarea.world"));
                            double x = settings.getData().getDouble("warps.waitarea.x");
                            double y = settings.getData().getDouble("warps.waitarea.y");
                            double z = settings.getData().getDouble("warps.waitarea.z");
                            p.teleport(new Location(w, x, y, z));
                            p.sendMessage(ChatColor.GREEN + "Teleported to waiting area!");
                         
                          for (Player staff : Bukkit.getOnlinePlayers()) {
                             
                              if (staff.hasPermission("arena.admin")) {
                                  staff.sendMessage(ChatColor.BLUE + "A challenger has joined the arena, there are now " + inArena2.size() + " People in the arena.");
                                 
                                }
                          }
                      }
    Plugin.yml:

    Code:
    name: PVPNotifier
    main: me.Ckay.pvp.Main
    version: 1.0
    author: ABkayCkay
    permissions:
      arena.admin:
        description: Allows admin command access.
      arena.join:
        description: Allows user to join arena.
    commands:
       arena:
          description: Main Arena command
          usage: /arena
    Playing on Spigot 1.8 server using CraftBukkit 1.8.3 in build path.
    Have have been comparing to my other plugins and i have no idea why it would not work.
     
  2. Offline

    mac989898

    Try changing your if statement from:
    Code:
    commandLabel.equalsIgnoreCase("Arena")
    
    To:
    Code:
    cmd.getName().equalsIgnoreCase("Arena")
    
    Maybe that will help I don't know for sure :)
     
  3. Offline

    mcdorli

    Don't use label, use cmd.getName()
    Don't abuse static

    Try to put the commands section in the plugin.yml over permissions
     
  4. Nope tried both of these, :/
    The part where the player death is works, just not the onCommand.
    So the plugin is loading, just not seeing the onCommand for some reason.

    Here is the whole onCommand:


    Code:
    @EventHandler
         public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
              Player p = (Player)sender;
             
              if (cmd.getName().equalsIgnoreCase("arena")) {
                  if (args.length == 0) {
                      if (p.hasPermission("arena.admin")) {
                          p.sendMessage(ChatColor.GREEN + "/arena setwarp waitarea - Sets the waiting area location");
                          p.sendMessage(ChatColor.GREEN + "/arena start - Stats the game by teleporting players to the random locations");
                          p.sendMessage(ChatColor.GREEN + "/arena fillslots - Allows any players to join the arena without the permission");
                      }
                      else {
                      p.sendMessage(ChatColor.GREEN + "/arena join");
                      }
                      }
                  else if (args.length == 1) {
                      if (args[0].equalsIgnoreCase("join")) {
                          if (allowAll == true) {
                          inArena2.add(p);
                         
                          p.sendMessage(ChatColor.GREEN + "You have sucesfully joined the arena, teleporting to waiting area.");
                         
                          if (settings.getData().getConfigurationSection("warps.waitarea") == null) {
                                p.sendMessage(ChatColor.RED + "Warp waitarea does not exist!");
                                return true;
                        }
                            World w = Bukkit.getServer().getWorld(settings.getData().getString("warps.waitarea.world"));
                            double x = settings.getData().getDouble("warps.waitarea.x");
                            double y = settings.getData().getDouble("warps.waitarea.y");
                            double z = settings.getData().getDouble("warps.waitarea.z");
                            p.teleport(new Location(w, x, y, z));
                            p.sendMessage(ChatColor.GREEN + "Teleported to waiting area!");
                         
                          for (Player staff : Bukkit.getOnlinePlayers()) {
                             
                              if (staff.hasPermission("arena.admin")) {
                                  staff.sendMessage(ChatColor.BLUE + "A challenger has joined the arena, there are now " + inArena2.size() + " People in the arena.");
                                 
                                }
                          }
                      }
                          else if (allowAll == false) {
                              if (p.hasPermission("arena.join")) {
                                  inArena2.add(p);
                                 
                                  p.sendMessage(ChatColor.GREEN + "You have sucesfully joined the arena, teleporting to waiting area.");
                                 
                                  if (settings.getData().getConfigurationSection("warps.waitarea") == null) {
                                        p.sendMessage(ChatColor.RED + "Warp waitarea does not exist!");
                                        return true;
                                }
                                    World w = Bukkit.getServer().getWorld(settings.getData().getString("warps.waitarea.world"));
                                    double x = settings.getData().getDouble("warps.waitarea.x");
                                    double y = settings.getData().getDouble("warps.waitarea.y");
                                    double z = settings.getData().getDouble("warps.waitarea.z");
                                    p.teleport(new Location(w, x, y, z));
                                    p.sendMessage(ChatColor.GREEN + "Teleported to waiting area!");
                                 
                                  for (Player staff : Bukkit.getOnlinePlayers()) {
                                     
                                      if (staff.hasPermission("arena.admin")) {
                                          staff.sendMessage(ChatColor.BLUE + "A challenger has joined the arena, there are now " + inArena2.size() + " People in the arena.");
                                         
                                        }
                                  }
                              }
                          }
                  }
                      if (args[0].equalsIgnoreCase("start")) {
                          if (p.hasPermission("arena.admin")) {
                             
                              for (int i = 1; i <= 200; i++) {
                                  int playerSpot = i -1;
                                
                                  Player playerInArena = inArena2.get(playerSpot);
                                 
                                  //Location originalLocation = playerInArena.getLocation();
                                 
                                  Random random = new Random();
                                
                                  int randomX = random.nextInt(1000) +1;
                                  int randomY = 150;
                                  int randomZ = random.nextInt(1000) +1;
                                 
                                  Location teleportLocation = new Location(playerInArena.getWorld(), randomX, randomY, randomZ);
                                  playerInArena.teleport(teleportLocation);
                                 
    //                              if (settings.getData().getConfigurationSection("warps." + playerSpot) == null) {
    //                                    p.sendMessage(ChatColor.RED + "Warp " + playerSpot + " does not exist!");
    //                                    return true;
    //                            }
    //                                World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + playerSpot + ".world"));
    //                                double x = settings.getData().getDouble("warps." + playerSpot + ".x");
    //                                double y = settings.getData().getDouble("warps." + playerSpot + ".y");
    //                                double z = settings.getData().getDouble("warps." + playerSpot + ".z");
    //                                playerInArena.teleport(new Location(w, x, y, z));
    //                                playerInArena.sendMessage(ChatColor.GREEN + "Teleported to " + playerSpot + "!");
                                   
     
                              }
                             
                          }
                      }
                  }
                  else if (args.length == 2) {
                      if ((args[0].equalsIgnoreCase("setwarp"))) {
                             if (p.hasPermission("arena.admin")) {
                                if (settings.getData().get("warps." +args[1]) != (null)) {
                                    p.sendMessage(ChatColor.RED + args[1] + " warp already exists. If you want to overwrite it, do /arena delwarp "+args[1] + ". And then re-set the new warp.");
                                }
                                else {
                                
                                settings.getData().set("warps." + args[1] + ".world", p.getLocation().getWorld().getName());
                                settings.getData().set("warps." + args[1] + ".x", p.getLocation().getX());
                                settings.getData().set("warps." + args[1] + ".y", p.getLocation().getY());
                                settings.getData().set("warps." + args[1] + ".z", p.getLocation().getZ());
                                settings.saveData();
                                p.sendMessage(ChatColor.GREEN + "Set warp " + args[1] + "!");
                                }   
                              }
                             else {
                                 p.sendMessage(ChatColor.RED + "You do not have permission to set a warp!");
                             }
                            }
                           
                            if ((args[0].equalsIgnoreCase("delwarp"))) {
                              if (p.hasPermission("arena.admin")) {
                                if (settings.getData().getConfigurationSection("warps." + args[1]) == null) {
                                    p.sendMessage(ChatColor.RED + "Warp " + args[1] + " does not exist!");
                                    return true;
                            }
                                settings.getData().set("warps." + args[1], null);
                                settings.saveData();
                                p.sendMessage(ChatColor.GREEN + "Removed warp " + args[1] + "!");
                              }
                              else {
                                     p.sendMessage(ChatColor.RED + "You do not have permission to delete a warp!");
                                 }
                            }
                           
                            if ((args[0].equalsIgnoreCase("warp"))) {
                              if (p.hasPermission("arena.admin")) {
                                if (settings.getData().getConfigurationSection("warps." + args[1]) == null) {
                                    p.sendMessage(ChatColor.RED + "Warp " + args[1] + " does not exist!");
                                    return true;
                            }
                                World w = Bukkit.getServer().getWorld(settings.getData().getString("warps." + args[1] + ".world"));
                                double x = settings.getData().getDouble("warps." + args[1] + ".x");
                                double y = settings.getData().getDouble("warps." + args[1] + ".y");
                                double z = settings.getData().getDouble("warps." + args[1] + ".z");
                                p.teleport(new Location(w, x, y, z));
                                p.sendMessage(ChatColor.GREEN + "Teleported to " + args[1] + "!");
                               
                              }
                              else {
                                  p.sendMessage(ChatColor.RED + "You do not have permission to warp to a spawn location!");
                              }
                            }
                  }
                 }
            
             
              return false;
         }
    On a side note, the plugin.yml is in the src folder.
    But if there was a problem with where the plugin.yml file was, it wouldnt even load the plugin.
    So its just more about the command is not being registered or something.
     
  5. Offline

    Xerox262

    @kayc01 Why does your onCommand method have an event handler annotation?
     
  6. I noticed that, i removed that.
    It wouldnt of prevented it would it?
     
  7. Offline

    Xerox262

    I would assume it would since it is counting it as a new method and not as one that is overriding the one in JavaPlugin. Try putting your @Override there and trying again.
     
  8. Putting Override before the onCommand didn't solve it :/
    Code:
     @Override
         public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
              Player p = (Player)sender;
    Here is the whole plugin code:
    http://pastebin.com/2jN4G00P
    see what you can find.

    EDIT: Doing /help PVPNotifier in game says there is no commands.
    [​IMG]
     
  9. Offline

    TechBug2012

    I don't know if this is because of Bukkit formatting, but your plugin.yml has 3 spaces before the first command, and 6 spaces on description and usage.
    Code:
    commands:
       arena:
          description: Main Arena command
          usage: /arena
    
    If there are no commands at all, maybe it means that the formatting in the plugin.yml is wrong
     
  10. Mind doing me the quick favour of creating a new plugin that uses the command and permissions i use in a plugin.yml that when doing /arena, says hi to you.

    This would confirm your plugin.yml works and then send me that plugin.yml ?

    If that makes sense.

    Also, my other plugin has those amounts of spaces in the plugin.yml and seem to work fine.

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

    Xerox262

    @kayc01 And you've checked your server logs to see if there were any errors? If the command does not appear then it means it has not actually been registered in your plugin.yml.
    Are you sure you exported your new plugin jar and put it into the folder?
    Do you have two plugins with the same name?
     
Thread Status:
Not open for further replies.

Share This Page