Plugin commands won't work

Discussion in 'Plugin Development' started by LazeFox, May 24, 2021.

  1. Offline

    LazeFox

    Hey, I'm currently trying to get into coding, and I've tried developing a simple plugin that returns a message when executing a command. However, the command doesn't show up in the help menu, and I can't use it either.

    Here is the code for my Main class:

    Code:
    package me.lazefox.helloworld;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.lazefox.helloworld.commands.heya;
    
    public class Main extends JavaPlugin{
    
        public void onEnable() {
            new heya(this);
        }
    
    }
    
    The Command class:

    Code:
    package me.lazefox.helloworld.commands;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import me.lazefox.helloworld.Main;
    
    public class heya implements CommandExecutor {
       
        private Main plugin;
       
        public heya(Main plugin) {
            this.plugin = plugin;
            plugin.getCommand("hello").setExecutor(this);
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You're not a player.");
                return true;       
            }
           
            Player p = (Player) sender;
           
            if (p.hasPermission("hello.use")) {
                p.sendMessage("Hey");
                return true;
            } else {
                p.sendMessage("No permission.");
            }
            return false;
        }
    }
        
    And the plugin.yml:

    Code:
    name: HelloWorld
    version: 1.0.0
    description: Hello World
    main: me.lazefox.helloworld.Main
    
    
    commands:
    hello:
      usage: /<command>
      aliases: [hey, hi, heya]
     
  2. Offline

    Shqep

    @LazeFox
    I suspect this is the problem:
    Code:
    commands:
    hello:
    usage: /<command>
    aliases: [hey, hi, heya]
    
    Indentation! It matters! What you're doing is that you're putting a main key "hello" but the server doesn't understand that, all it knows is that the key "commands" contains nothing.
    Code:
    commands:
      hello:
        usage: stuff
        aliases: [stuff]
    
     
    LazeFox likes this.
  3. Offline

    LazeFox

    Thank you very much! That is what fixed it!
     
    Shqep likes this.

Share This Page