Plugin Code Help

Discussion in 'Spigot Plugin Development' started by nick_2002, Jun 3, 2016.

  1. Hey Everyone,

    Plugin Code Help
    I was making very simple plugin, And I don't know why but command didn't work :/.
    When i typed in the command that i coded in to my main.java, Nothing happened.
    Main.java

    Code (Text):
    package com.script01;

    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(){
     
        }
        @Override
        public void onDisable(){
     
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (cmd.getName().equalsIgnoreCase("hey")){
                Player player = (Player) sender;
                player.sendMessage("Hey, " + player.getName());
                return true;
            }
            return false;
        }
    }
    As you can see it should reply "Hey, {User}" when i type the command but it doesn't.

    Just to make sure this is my plugin.yml .

    Code (Text):
    name: plugin
    main: com.script01.main
    version: 1.0
    command:
       hey:
         description: replies Hey, {PlayerName}
         usage: /<command>
    The plugin shows when I do /plugins but it doesn't do shit .
    If you have any ideas feel free to comment down below.

    From » GayLoadYT, FiveDollars_, Nick
    Twitter » @GayLoadYT
    Twitch » https://www.twitch.tv/gayloadyt
    Skype » GayLoadYT
    FaceBook » https://www.facebook.com/profile.php?id=100012345935873
    YouTube » https://www.youtube.com/channel/UCANJl4Kr_fDGqPyCNqnWdCA
    Steam » https://steamcommunity.com/id/GayLoadYT
     
  2. Is the plugin loading correctly? You see it in the /plugins list as a green color?
    You may need to escape what you've put in your plugin.yml. Put ' or " around your description and usage messages.
     
  3. Replace
    Code (Text):
    cmd.getName().equalsIgnoreCase("hey")
    with
    Code (Text):
    label.equalsIgnoreCase("hey")
     
  4. MiniDigger

    Supporter

    No, don't do that. It will break aliases. The name of the command is what was registered in the plugin.yml, the label is what the player entered. If you have aliases the label will not be equal to the name of the command.

    To solve ops problem: the plugin.yml path to your commands should start with 'commands' not 'command'. Bukkit ignores the commands you registered because of that typo.
     
  5. I think you forgot the @Override annotation above your onCommand method ;)
     
  6. MiniDigger

    Supporter

    The @Override annotation is completely optional. You are right tho that op should specify it
     
  7. 1) oh nope doesn't work
     
  8. That wouldn't make a difference. It's only to check whether the method is actually being overridden.
     
  9. Do you have any errors in the console on executing the command?
     
  10. Ah, i found the issue.
    You should replace command with commands in your plugin.yml

    Code (Text):
    name: plugin
    main: com.script01.main
    version: 1.0
    command: << Replace with: commands:
       hey:
         description: replies Hey, {PlayerName}
         usage: /<command>
     
  11. The override annotation gets tagged alot
     
  12. MiniDigger

    Supporter

    That's what i said like 10 messages above...
     
    • Agree Agree x 2
  13. MiniDigger

    Supporter

    Yeah poor guy. I wonder if that's why he left spigot ^^