what's wrong with my code?

Discussion in 'Plugin Development' started by Tails_Prower_24, Aug 2, 2015.

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

    Tails_Prower_24

    Hello all! I have made a test plugin that isn't supposed to do anything but say "LOL has been enabled!", but instead the console fails to load LOL. is there anything wrong with my code? It's my first plugin.
    Code:
    package luc.plugins;
    
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Plugins extends JavaPlugin {
    
       public void onEnable() {
         PluginDescriptionFile pdfFile = getDescription();
         Logger logger = Logger.getLogger("Minecraft");
        
         logger.info(pdfFile.getName() + " has been enabled! " +pdfFile.getVersion() + ")");
        
       }
       public void onDisable() {
         PluginDescriptionFile pdfFile = getDescription();
         Logger logger = Logger.getLogger("Minecraft");
        
         logger.info(pdfFile.getName() + " has been disabled! " +pdfFile.getVersion() + ")");
       }
    }
    
    Eclipse says there are no errors
     
  2. Offline

    xXCapzXx

    Have you made a plugin.yml?
     
  3. Offline

    Tails_Prower_24

    @xXCapzXx yep i made a plugin.yml
    Code:
    main: luc.plugins.Plugins.Plugins
    version: 1.7.10
    name: LOL
    
     
  4. Offline

    moe097

    @Tails_Prower_24
    Your making it harder on yourself by getting the logger like that. Simply do:
    Code:
    @Override
    public void onEnable() {
    getLogger().info("LOL has been enabled!");
    }
    
    @Override
    public void onDisable() {
    getLogger().info("LOL has been disabled!");
    }
    If you have to do it your way for whatever reason, does the console give you errors?
     
  5. Offline

    Boomer

    There is nothing technically incorrect about your actual code - its just VERY old style, extraneous chunky ways of doing what you're doing, but you're following tutorials written in 2013 probably.

    Therefore the problems lay in how your environment is prepared, your plugin.yml file, and how you are preparing the jar. For this code to not work you MUST be seeing errors during the startup of the server when trying to load this plugin, or else you do not have a jar file present in the test server plugins folder but put it somewhere else - even an incorrect file nameed .jar will attempt to be loaded and generate errors.

    If the error you get refers to 'missing plugin.yml' that is likely due to not having the plugin.yml file in the correct place in your project. You may also get errors due to eclipse needing to 'refresh' the project before compiling the jar, esp if your plugin.yml file was open in an external editor.

    First rule to learn as a new programmer - do not be afraid of error messages. They look intimidating, but, they are VERY helpful when you learn how to get the information you need from them, or how to find the right part to google for possibilities... Dont say "it doesn't work" or "it just crashes with an error" or "it just errors out when loading" - getting an error is the understood part - what particular error you get will tell more experiened people what the issue is, so that you can learn what it is, and recognize (Because believe it or not, you'll see a bunch of the same errors over and over, due to missing a step every time you create a new plugin project, or getting a headof yourself and compiling before doing something in particular, and the particular error will stare back at you enough that you'll recognise what it means from the previous times and do the 'oh, yeah, i forgot to do x.. duh"
     
  6. TheBcBroz virus has got another victim.

    1. Do not get the Logger like that, use Bukkit's
    2. You don't need enable and disable messages, Bukkit does it for you
    3. Please do not follow BcBroz's tutorials. They are not good and are filled with bad practices. If you didn't you wouldn't be here asking for help.

    Also what is your error? You haven't said.
    And you know the plugin.yml version is your plugin version right? Not mc version.

    Oh and of course, moved to Plugin Development
     
  7. Konato_K likes this.
  8. @megamichiel Good spot :D

    @Tails_Prower_24 Fix what I said above and your package in the plugin.yml is invalid. Remove the second Plugins.
    It should be: luc.plugins.Plugins
     
  9. Offline

    Tails_Prower_24

Thread Status:
Not open for further replies.

Share This Page