Solved Commands not executing?

Discussion in 'Plugin Development' started by SmallDesk, Feb 25, 2018.

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

    SmallDesk

    I am making a plugin, but all of the commands that I have in it don't do anything at all. I am confused because I have them registered in my Plugin.yml, but it's not doing anything. So the server recognizes it, but does nothing.

    Here is my code for command:

    Code:
    public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
            if (cmd.getLabel().equalsIgnoreCase("status") && sender instanceof Player){
              skyManager.displayLoreStats((Player)sender);
              return true;
            }
            if (cmd.getLabel().equalsIgnoreCase("test") && sender instanceof Player){
                  sender.sendMessage("test");
                  return true;
                }
            if(cmd.getLabel().equalsIgnoreCase("start") && sender instanceof Player){
                Player p = (Player) sender;
                p.sendMessage(ChatColor.GREEN + "Starting new game!");
                p.getLocation().getWorld().getWorldBorder().setCenter(p.getLocation());
                p.getLocation().getWorld().getWorldBorder().setSize(100);
                Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border shrinking in " + ChatColor.GOLD + "20 " + ChatColor.RED + "seconds!");
                Bukkit.getScheduler().runTaskLater(this, new Runnable(){
                    public void run(){
                        p.getLocation().getWorld().getWorldBorder().setSize(50);
                        Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border shrinking in " + ChatColor.GOLD + "20 " + ChatColor.RED + "seconds!");
                    }
                },20L);
                return true;
            }
            return false;
        }
    Plugin.yml:

    Code:
    name: Testing
    main: test.Testing
    version: 1.0
    description: Test
    commands:
      status:
        aliases: [currentstats, itemstats]
        description: Displays your items current stats.
      start:
        description: Starts a new game.
      test:
        description: Test.
     
    Last edited by a moderator: Feb 25, 2018
  2. instead of this
    public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
    do
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)

    im not sure if the parameter placement matters but thats how all commands are setup, also is this command in your main class? if not is it registered in your main class?
     
  3. Offline

    SmallDesk


    Oh, thank you so much! :) The Override annotation and correct sequence worked, thanks. :)
     
  4. Offline

    DutchJellyV2

    Override shouldn't be necesary, but the correct sequance is.
     
Thread Status:
Not open for further replies.

Share This Page