Beginner, Please could you help?

Discussion in 'Plugin Development' started by jnicholls92, Feb 10, 2012.

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

    jnicholls92

    Hey all.

    I have resently started my own minecraft server using bukkit, and i would like to develope a plugin and i got this far before hitting a snag in the road. Please could someone point me in the right direction?

    classfile
    Code:
    package uk.co.hewparg.sparton224.hewparg;
     
    import java.util.logging.Logger;
     
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    class hewparg 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.");
        }
       
       
       
    }
    
    .yml file
    Code:
    name: hewparg
    main: uk.co.hewparg.sparton224.hewparg.hewparg
    version: 0.1
    
    I get errors in my command pompt when i try to run the server and enable the plugin.
    Sorry i am realy new to java, I usally code PHP, HTML, CSS, MySQL

    Error Image :
    [​IMG]
     
  2. Offline

    SirTyler

    Your missing the plugin.yml in the jar, make sure you compiled it with the yml
     
  3. you forgot the
    Code:
    @Override
    above onEnable and onDisable


    No I don't think so. That would give another error, like "couldn't load xy.jar because it doesn't contains a plugin.yml" or something.
     
  4. Offline

    SirTyler

    and I cant believe I missed that xD
     
  5. Offline

    jnicholls92

    So what you saying is the code should look like
    Code:
    package uk.co.hewparg.sparton224.hewparg;
     
    import java.util.logging.Logger;
     
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    class hewparg extends JavaPlugin{
     
        Logger log = Logger.getLogger("Minecraft");
      @Override
        public void onEnable(){
            log.info("Your plugin has been enabled.");
        }
     
        public void onDisable(){
            log.info("Your plugin has been disabled.");
        }
     
     
     
    }
     
  6. partly yes.
    You need another @Override over onDisable.

    Code:
    @Override
    public void onEnable()
    {
        ...
    }
     
    @Override
    public void onDisable()
    {
      ...
    }
    so something like this.
     
  7. Offline

    thehutch

    what's even better is that in Bukkit R4 these methods aren't needed the way you are using them now, yes you use onEnable() when you need to load something on serverload and you don't need you add the log.info("This plugin has loaded") because bukkit has in-built one.
     
  8. this is most likely every time the case. Also it's already implemented in R3.
     
  9. Offline

    Zimp

    The @Override annotation is not required but is considered good programming practice. It tells the compiler that the method it prefixes should be overriding a method from a base class. This means common mistakes like spelling mistakes or wrong parameters will be caught at compile time rather than at runtime which is much harder to debug.

    Bukkit is using reflection to find a no-arg constructor for you class which appears to be failing. I am not sure what the reason is though because it should be automatically created for you as long as you don't declare any constructors yourself.

    Something that may be worth trying is to add "public" at the front of your class declaration

    Code:
    public class hewparg extends JavaPlugin{
     
  10. Offline

    TopGear93

    Code:
    import java.util.logging.Logger;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class hewparg extends JavaPlugin{
    public Logger log;
     
      @Override
        public void onEnable(){
    log.getLogger("Minecraft");
            log.info("Your plugin has been enabled.");
        }
    @Override
        public void onDisable(){
            log.info("Your plugin has been disabled.");
        }
     
     
     
    }
     
Thread Status:
Not open for further replies.

Share This Page