Solved Wont register any commands.

Discussion in 'Plugin Development' started by JavaNoob, Aug 28, 2020.

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

    JavaNoob

    I have just been messing around to see what I can learn if I just do stuff. I tried to make a thing where if you type a certain command, then building would be denied. (There is probably way better ways to do it but I'm trying my best.) Then another command that would allow it back again. But even though other parts of the code work, any commands i tried to add wont work or register. It always gives me the Unknown Command message in chat and in console if I try it there. I can't seem to find what is wrong with my code.
    Code:
    package com.nay.testingcommands;
    
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
            System.out.println("PLUGIN ENABLED");
        }
        @Override
        public void onDisable() {
            System.out.println("PLUGIN DISABLED");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equals("fly")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    player.setFlying(true);
                }
            }
            if (cmd.getName().equals("flydeny")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    player.setFlying(false);
                }
            }
           
            return false;
        }
       
    }
     
    Last edited by a moderator: Aug 30, 2020
  2. Offline

    timtower Administrator Administrator Moderator

    @JavaNoob Did you register those commands in the plugin.yml?
     
  3. Offline

    JavaNoob

    Is that necessary every time you insert a command? No, I didn't. I will try it! Thank you.

    Edit: Thank you for the help! It worked!
     
    Last edited: Aug 30, 2020
  4. Offline

    timtower Administrator Administrator Moderator

    Yes, all commands that you have need to be in the plugin.yml
     
Thread Status:
Not open for further replies.

Share This Page