Creating a Simple Command

Discussion in 'Wiki Discussion' started by jflory7, May 22, 2015.

  1. Thank you! very helpful!
  2. Thank you for this thread. I'm sure it will be very useful to a lot of people getting to know how to use Spigot.
  3. Thank you for this tutorial !
    • Agree Agree x 1
  4. +1
  5. Tutorials are Nice ^^
  6. this is a very good tutorial and is very basic and user friendly
  7. Excellent work on creating a laid out tutorial for people who don't know how to create a simple command.
    Very well explained and detailed
    *Thumbs Up*
  8. This could be done using skript, however it's a good tutorial for beginners.
    • Funny Funny x 1
  9. pls dont tell people to learn skript on a java thread.
    • Like Like x 1
  10. I'm not, I'm just saying it would be easier on skript. That's all.

    : ) Sorry for confusion.
  11. Thanks!
    • Agree Agree x 1
  12. Very nice tutorial.
  13. There is something here that I'm missing because I've been over this tutorial for days now trying to make a working command with no success. Very new to Java though. I was successful with creating a basic plugin script through another tutorial, this is my first attempt at a simple command. I shall begin with posting the code I have:

    Code (Text):

    package MFJAPackage;

    //import org.bukkit.event.EventHandler;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;

    public class MFJAClass implements CommandExecutor{
    //extends JavaPlugin

     public void onEnable(){
      this.getCommand("MFJA").setExecutor(new MFJAClass());

     public boolean onCommand(CommandSender sender,Command command,String label,String[]arguments){
                // Execute whatever command code here...
    return false; //To my understanding, this will change to true once the command code exist...

    I believe I am missing a import, extends, implements, listener or something of the sorts, but the current error is onEnable() requires a override or implement according to Eclipse. If I put in that extends JavaPlugin, the code compiles, but the server then gives a error about trying to "init" the plugin twice.

    Oh, and for anyone learning via this thread, you can not use the TAB key to indent in the plugin.yml file

    Any help is greatly appreciated, TY :)
  14. When your plugin is loaded it creates an instance of MFJAClass then in onEnable() where you have "(new MFJAClass());" it creates another instance because of the "new" keyword, reason for the multiple "init". Since this is your main class you need it to extend JavaPlugin and have your plugin.yml point to it to start the loading here. I think you did do that at some point if it ever did load. You can also implement the CommandExecutor to get the onCommand() part. You will also need to register the command in your plugin.yml. as your main command. This wiki tutorial is setup with putting things in different classes which is why the "this.getCommand("MFJA").setExecutor(new MFJAClass());" exists. You have it all in one class so that part is not needed. There are of course other ways to do it. I hope this makes sense, I am fairly new to Java myself so i am not really good at explaining things. Also a good look at all of this will be very helpful.
    • Informative Informative x 1

Share This Page