whats wrong with my code?

Discussion in 'Spigot Plugin Help' started by TheAsher0001, May 15, 2015.

  1. I'm learning java to create plugins. I've made a package, class etc. I've also made a plugin.yml file but the console says every time: plugin.yml file is invalid...
    here is my code:

    package me.TheAsher0001.Test;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;

    public class test {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static test plugin;


    public void onEnable(){
    this.logger.info("Testplugin Enabled");



    }
    public void onDisable(){
    this.logger.info("Testplugin Disabled");

    }

    public boolean onCommand(ConsoleCommandSender sender, Command cmd, String commandLabel, final String[] args ){

    if(commandLabel.equalsIgnoreCase("test")){
    Player player = (Player) sender;
    player.sendMessage("This works!!! :)");

    }
    return false;


    }
    }


    and my plugin.yml
    name: TestPlugin
    main: me.TheAsher0001.Test.test
    version: 0.1
    description: My First Plugin

    Commands:
    test:
    description: sends player a message that the plugin works
     
  2. First of all you have to extends the class at JavaPlugin,and you can also don't put the constant logger(public final Logger logger = Logger.getLogger("Minecraft")),because it is an old method,for the plugin.yml you have to check the sintax ;)
     
  3. it works so im happy
     
  4. i'm happy for you
     
  5. If you need help contact me on skype
     
  6. nick:Napolissimo1926 i will help you!
     
  7. Thank you! Im glad to hear! I only have another problem... It is a valid plugin, but if i type /test it does nothing...
     
  8. it gives this error if i load the plugin:

    [10:47:36 INFO]: CONSOLE: Please note that this command is not supported and may
    cause issues when using some plugins.
    [10:47:36 INFO]: CONSOLE: If you encounter any issues please use the /stop comma
    nd to restart your server.
     
  9. That isn't your plugin causing that error. It tells you this if you use the /reload command, which isn't recommended.
     
  10. ow k... i normally use plugman to reload plugins... but I've I type /test as a player it doesnt show the text: It Works!!!
     
  11. Can you post the code? Also please post it in "[ code ]" and "[ /code ]" (without space before and after [] )[/code]
     
  12. Plugin.yml file:
    Code (Text):

    name: TestPlugin
    main: me.TheAsher0001.Test.test
    version: 0.1
    description: My First Plugin
    commands:
      test:
        description: sends player a message that the plugin works
     
    test.java file
    Code (Text):

    package me.TheAsher0001.Test;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class test extends JavaPlugin {
       
        public final Logger logger = Logger.getLogger("Minecraft");
           public static test plugin;

           @Override
           public void onDisable(){
               this.logger.info("DISABLED");

           }

           
           
           
           @Override
           public void onEnable(){
               this.logger.info("ENABLED");



           }

           public boolean onCommand(ConsoleCommandSender sender, Command cmd, String commandLabel, final String[] args){

               if(commandLabel.equalsIgnoreCase("test")){
                   Player player = (Player) sender;
                   player.sendMessage("This works!!!");

               }
               return false;


           }
    }

     
     
  13. Change the package to package me.TheAsher0001 in main, then in plugin.yml put on main: me.TheAsher0001.Test (just one test)
    Also, add ussage: /<command> like this:
    Code (Text):

       test:
          description: sends player a message that the plugin works
          usage: /<command>
     
    Also make sure before "test:" it's 3 spaces and before description and usage it's 6 spaces
    Also, for me it's more easy to get the command with "if(cmd.getName().equalsIgnoreCase("test")"

    Also, you need to return true after a command is done, so after you use player.sendMessage() before closing the if with }, put return true;
    like that:
    Code (Text):

    if(cmd.getName().equalsIgnoreCase("test"){
       Player player = (Player) sender;
       player.sendMessage("This works!!!");
       return true;
    }
     
     
  14. that /<command> made it worse and it still doesnt say: "It works" when typing /test
     
  15. a friend of mine solved it... it had to be sender.sendMessage
    and Player player = ... could be erased!
     
  16. I can bet it was because you didn't used return true
    The command doesn't work if you don't include the "return true" at the end of if
     
  17. i did that before u said to do that... YT...
     
  18. WTF it's wrong with you? You posted a code with 13 minutes before me to help you where it was wrong, then after i help you, you come here and say you already did that and fixed without our help? Please guy, you are not gonna getting help on this forum with this behaviour.
     
  19. i've posted it 2 days ago... u where too late... And i search internet too get the solution too... this forum isn't supposed to ask something and let other ppl solve it... it's supposed that other ppl try to HELP you...
     
  20. This is an community that helps and teach'es each other so pks be nice
     
    • Agree Agree x 1