Im startrter, what wrong here?

Discussion in 'Plugin Development' started by ShaharSade, Aug 15, 2013.

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

    ShaharSade

    Code:
    package me.Shahar.Main;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Youtube extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Youtube p;
     
        @Override
        public void OnDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName()+ " Version "+pdfFile.getVersion()+" Has Been Disabled");
        }
        @Override
        public void OnDEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName()+ " Version "+pdfFile.getVersion()+" Has Been Enabled");
      }
     
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
          Player player = (Player) sender;
          if(commandLabel.equalsIgnoreCase("send")){
              player.sendMessage(ChatColor.BLACK+"Worked!");
           
          }
        return false;
      }
     
     
     
         
    }
    

    what in the console its sayis: http://prntscr.com/1lhd6g this is the picture, idk how to copy the wrong
     
  2. Offline

    Rocoty

    These lines are wrong/bad
    1: OnDEnable()
    2: public final Logger logger = Logger.getLogger("Minecraft");
    3: public static Youtube p;
    4: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    5: Player player = (Player) sender;
    6: if(commandLabel.equalsIgnoreCase("send")){
    7: return false;
    8: OnDisable()

    Because:
    1: The method inherited from JavaPlugin is called onEnable, not OnDEnable (code won't compile)
    2: You should use the logger inherited from JavaPlugin rather than getting the Minecraft logger
    3: the field is never used anywhere, nor is it initialized (unless you did that in another class) And why is it static?
    4: This method should have an Override annotation as good practice
    5: This is an unsafe cast, as you are not yet sure that sender is an instance of Player
    6: You should use cmd.getName() instead of commandLabel, as commandLabel might be something else if the command has aliases
    7: Why would you return false even if the command succeeded?
    8: OnDisable is not inherited from JavaPlugin, the correct method is named onDisable
     
  3. Offline

    ShaharSade


    like i sayid im starter i dint understand,
    that what the new:
    http://prntscr.com/1lhesu

    and the code:
    Code:java
    1. package me.Shahar.Main;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Youtube extends JavaPlugin{
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14. public static Youtube p;
    15.  
    16. @Override
    17. public void onDisable(){
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName()+ " Version "+pdfFile.getVersion()+" Has Been Disabled");
    20. }
    21. @Override
    22. public void onEnable(){
    23. PluginDescriptionFile pdfFile = this.getDescription();
    24. this.logger.info(pdfFile.getName()+ " Version "+pdfFile.getVersion()+" Has Been Enabled");
    25. }
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    28. Player player = (Player) sender;
    29. if(commandLabel.equalsIgnoreCase("send")){
    30. player.sendMessage(ChatColor.BLACK+"Worked!");
    31.  
    32. }
    33. return false;
    34. }
    35.  
    36.  
    37.  
    38.  
    39. }
    40.  



    can u fix it for me?
     
  4. Offline

    Tirelessly

    ShaharSade but the real problem is that you never made a plugin.yml file.
     
  5. Offline

    Rocoty

    what's the contents of your plugin.yml?
     
  6. Offline

    ShaharSade

    that what: http://prntscr.com/1lhfq4

    and that the plugin.yml code:
    Code:java
    1. name: Youtube
    2. version: 0.1
    3. main: me.Shahar.Main.Youtube
    4. author: Shahar
    5. description: Just a plugin.
    6.  
    7. commands:
    8. send:
    9. description: Sent
    10.  


    no 1?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    tommycake50

    I always return false. it doesnt make much difference tbh.
    nothing ever checks it so you can just return w/e.
     
  8. Offline

    Rocoty

    tommycake50 Err...When you return false, the usage of the command is displayed to the sender...That makes a pretty significant amount of difference
     
  9. Offline

    tommycake50

    Not for me. every plugin i write i return false and it works 100% of the time.
     
  10. Offline

    Tomskied

    tommycake50 If you have "Usage:" in your plugin.yml for your commands, returning false will return the usage in the plugin.yml


    To the OP, I would recommend this tutorial. Give that a read as it will fully guide you through the process of making a simple Bukkit plugin.
     
  11. Offline

    tommycake50

    Ahh good to know.
    thanks.
     
  12. Offline

    xTrollxDudex

    Tomskied tommycake50 Rocoty
    You would return false at the end of the onCommand, return true everytime the command is run.
     
  13. Offline

    moe097

    Instead of doing public final Logger logger = Logger.getLogger("Minecraft"); Just do this:
    Code:java
    1.  
    2. public void onEnable(){
    3. getLogger().info("MESSAGE");
    4. }
    5. //Than do the same for onDisable.
     
  14. Offline

    Rocoty

    xTrollxDudex It highly depends on your setup. But as a rule of thumb, sure.
     
Thread Status:
Not open for further replies.

Share This Page