Hello world?

Discussion in 'Plugin Development' started by bierbuikje, Feb 2, 2012.

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

    bierbuikje

    Every scripting experience has to start with Hello World, so I decided to create a command '/hello' which sends the sender a message with 'Hello World!' in it. Well, I try to get it to work, but it doesn't. Nothing works yet, the server log says I issue the command /hello, but there is no output at all. What is the problem with my code? Thanks a lot!

    HelloWorld.java
    Code:
    package me.HelloWorld;
     
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HelloWorld extends JavaPlugin
    {
        Logger log = Logger.getLogger("Minecraft");
     
        public void onEnable()
        {
            log.info("Your plugin has been enabled!");
        }
     
        public void onDisable()
        {
            log.info("Your plugin has been disabled.");
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("hello"))
            {
                sender.sendMessage("Hello World!");
                return true;
            }
            return false;
        }
    }
    
    Plugin.yml
    Code:
    name: Hello World
    main: me.HelloWorld.HelloWorld
    version: 0.1
    commands:
        hello:
            description: Hello World command
            permission: HelloWorld.hello
            usage: /<command>
     
  2. Offline

    SirTyler

    Try changing cmd.getName() to commandLabel
     
  3. cmd.getName() should be fine, but using the above method can be tried as well. Anyway, as a player, did you have the permission?
    and in the console you don't need the '/' in front of the command.
     
  4. Offline

    theguynextdoor

    Try removing the permission first. cmd.getName() should work perfectly fine.
     
  5. Offline

    emericask8ur

    Remove the permission.
    If adding Permission you must do:
    Code:
    if(p.hasPermission("blah.yeah")){
    //Do stuff
    }
    
     
  6. Offline

    bierbuikje

    I removed the permission and changed cmd.getCommand() into commandLabel, but it still doesn't work. Is there a setting I need to change? Like if there is some 'plugins: true' setting?

    My code right now.

    Code:
    package me.HelloWorld;
    
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class HelloWorld extends JavaPlugin
    {
        Logger log = Logger.getLogger("Minecraft");
        
        public void onEnable()
        {
            log.info("Your plugin has been enabled!");
        }
        
        public void onDisable()
        {
            log.info("Your plugin has been disabled.");
        }
        
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if (commandLabel.equalsIgnoreCase("hello"))
            {
                sender.sendMessage("Hello World!");
                return true;
            }
            return false; 
        }
    }
    
    Code:
    name: Hello World
    main: me.HelloWorld.HelloWorld
    version: 0.1
    commands:
        hello:
            description: Hello World command
            permission:
            usage: /<command>
     
  7. Offline

    RROD

    Try without the permission alltogether:
    Code:
    name: Hello World
    main: me.HelloWorld.HelloWorld
    version: 0.1
    commands:
        hello:
            description: Hello World Command
            usage: /<command>
     
  8. Offline

    bierbuikje

    Also not working, wouldn't there be a critical step in installing bukkit on my localhost to enable plugins?
     
  9. Offline

    SirTyler

    Plugins are loaded by bukkit, no setting. Just have it in the plugins folder and bukkit will try to load it. Only other suggestion I can make is to try this:
    Code:java
    1.  
    2. String cmd = args[0].toString();
    3. if(cmd.equalsIgnoreCase("hello")) {
    4. sender.sendMessage("Hello World!");
    5. return true;
    6. }
    7.  
     
  10. Offline

    emericask8ur

    Make sure your YML has correct Spacing.
     
  11. Offline

    BloodShura

    I don't know... no one think this...

    You need to register the command.

    onEnable():

    getServer().getPluginCommand("command").setExecutor("class");

    For example:

    getServer().getPluginCommand("hello").setExecutor(this);

    You can use 'this' if the command is in the same class as onEnable.
     
  12. Offline

    NerdsWBNerds

    if (commandLabel.equalsIgnoreCase("/hello"))
    try this ^^^^
    Could you upload the .jar for download so I could look at the EXACT code and spacing and everything?
    In the console (server) are there any errors given when you try /hello?
    If so what are the errors.
     
  13. Offline

    nisovin

    You don't have to do that if you're handling commands in your main JavaPlugin class.

    Are you sure your plugin is loading at all? If you type /plugins, does your plugin show up?
     
  14. Offline

    number1_Master

    HelloWorld.java
    Code:
    package me.HelloWorld;
     
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HelloWorld extends JavaPlugin
    {
        Logger log = Logger.getLogger("Minecraft");
     
        public void onEnable()
        {
            log.info("Your plugin has been enabled!");
        }
     
        public void onDisable()
        {
            log.info("Your plugin has been disabled.");
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("hello") && sender.hasPermission("HelloWorld.hello")
            {
                sender.sendMessage("Hello World!");
                return true;
            }
            return false;
        }
    }
    
    Plugin.yml
    Code:
    name: Hello World
    main: me.HelloWorld.HelloWorld
    version: 0.1
    commands:
        hello:
            description: Hello World command
            usage: /<command>
    permissions:
        HelloWorld.hello:
            description: This is a description
            default: <who gets this by default>
    that should work try that
     
  15. Offline

    dannycrafts

    What is het probleem? Wat krijg je te zien als het fout gaat en wat gebeurd er?
     
  16. Offline

    bierbuikje

    I tried to test my server with another plugin, I chose the Antihunger plugin, but when I use commands of this plugin it doesn't show up anything. I think the problem is not with the coding, but with the plugin loading. What could cause this? Thanks for helping!
     
Thread Status:
Not open for further replies.

Share This Page