Can't get a simple command plugin to work

Discussion in 'Plugin Development' started by Giudf45, Mar 5, 2012.

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

    Giudf45

    I've just started learning java and how to make bukkit plugins. So to see how far I've gotten I decided to make a simple plugin that displays "hi" whenever someone types the command /hi
    When I tried testing it, it said that the command /hi wasn't recognized. Then in my plugin.yml file it said that hi was spelled wrong. Here's my code and the plugin.yml:
    Code:
    package me.Giudf45.NoFriends;
     
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class NoFriends extends JavaPlugin {
        private static final Logger log = Logger.getLogger("NoFriends");
    @Override
    public void onEnable(){
        log.info("Enabled");
    }
    @Override
    public void onDisable(){
        log.info("Disabled");
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
        if(cmd.getName().equalsIgnoreCase("hi")){ // If the player typed /basic then do the following...
            Player player = (Player) sender;
            player.sendMessage("Hello");
            return true;
        } //If this has happened the function will break and return true. if this hasn't happened the a value of false will be returned.
        return false;
    }
    }
    Code:
    name: NoFriends
    main: me.Giudf45.NoFriends.NoFriends
    version: 1
    commands:
      hi:
        description: sends message.
        usage: /hi
        permission: NoFriends.hi
        permission: You don't have <permission>.
     
  2. Offline

    Usche

    You set the permissions? If not just leave them away
     
  3. Offline

    Giudf45

    Nope. So I removed the 2 permission lines, but it still gets saying that hi is spelled wrong. Any errors in the code?
     
  4. Offline

    HON95

    This
    Code:
    permission: You don't have <permission>.
    NVM, didn't reed the last comment.
     
  5. U did forget to write: If (sender instanceof player) {
     
  6. Offline

    HON95

    Just remove the "usage: /hi"... It's basicly useless in most cases.
    And yeah, you should add a "sender instanceof Player" check in case someone tries to use it from console.
     
  7. Offline

    Giudf45

    All fixed. Thanks guys :p
     
Thread Status:
Not open for further replies.

Share This Page