Invalid Plugin Exception

Discussion in 'Plugin Development' started by taka, Jul 15, 2012.

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

    taka

    So, I know what the problem is, just not entirely sure how to fix it (as I'm still new to developing plugins). I was working through an old Samkio tutorial on making a simple economy plugin and followed it to the letter, then fixed the listeners for the new Bukkit event system, as I had read previously. All was well, and I'm fairly certain it will function correctly, but there is something wrong with my setup.

    The package is me.taka.MoneyBukkit and my plugin.yml file has

    main: me.taka.MoneyBukkit.MoneyBukkit

    Which, if I infer (also newish to Java, but not to programming) the first three are the package, the fourth is the MoneyBukkit.java file, yes? On starting up the server, it gives me an InvalidPluginException stating that

    java.lang.NoSuchMethodException: me.taka.MoneyBukkit.MoneyBukkit.<init>()

    Which method is called by "init" ? That is the problem yes? Am I way off base? I had assumed the "init" to which it refers would be the onEnable() method. Anyway, I'm rambling, probably just a common newb mistake. Thank you for pointing me in the right direction in advance :)
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    taka
    When the stack trace shows <init> it is referring to the constructor for that class.

    This may be because there is something wrong with that particular class.
     
  3. Offline

    taka

    This is exactly like the Samkio tutorial, save the:

    public static MoneyBukkit plugin;

    Which I noticed was in my working plugin, but this one isn't working, so I added it.
    I also tried by adding @Override before the onEnable() and onDisable() methods, which no tutorial I've ever read has really explained why...but I figured why not, and tried it. Still no dice.

    [EDIT: As I'm reading it now, I do see the constructor there, but it was never referenced/used in the tutorial video. I must've copied it there like a good student and forgot about it, I'm looking at it now and don't remember typing it, heh. I'm sure there's where the error is, as it's an old tutorial.]

    Code:
    package me.taka.MoneyBukkit;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Logger;
     
    import org.bukkit.Server;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MoneyBukkit extends JavaPlugin {
     
        public static MoneyBukkit plugin;
        static String maindirectory = "MoneyBukkit/";
        static File Accounts = new File(maindirectory + "Users.accounts");
        public final Logger logger = Logger.getLogger("Minecraft");
        private final MBPlayerListener playerListener = new MBPlayerListener(this);
     
        public MoneyBukkit(PluginLoader pluginLoaders, Server instance,
                PluginDescriptionFile desc, File folder, File plugin,
                ClassLoader cLoader) {
         
        }
     
        public void onEnable() {
            new File(maindirectory).mkdir();
            if(!Accounts.exists()) {
                try {
                    Accounts.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
         
            PluginDescriptionFile pdfFile = this.getDescription();
            LoadSettings.loadMain();
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.playerListener, this);
            this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
        }
     
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
        }
     
    }
    
     
  4. Offline

    kSafin

    I may be wrong, but I think when the plugin is enabled bukkit tried to make an instance of your plugin using a default (empty) constructor in your main class.

    In your main class however, you defined a custom constructor:

    So it throws an exception because it can't find the empty constructor.

    If you remove that constructor I think it'll work.
     
  5. you used an pretty out to date sticky topic to makethat constructor, mayby we should notify some admins to remove those sticky topics as the might confuse the users
     
  6. Offline

    taka

    I'm fairly sure I used the constructor from the Samkio video (which might be difficult to change, heh) and I knew it was out of date. Should I just remove the constructor? Or change it somehow?
     
  7. remove it
     
  8. Offline

    taka

    Alright, I've removed it, and the plugin initializes correctly, but none of the commands are working :) I assume it has to do with the new Event system and my translation wasn't good (I was inferring some knowledge instead of knowing it firsthand). I'll dig through some tutorials and see what I can fix, or I'll be back later :) Thanks for the help!

    So, last quest, is the constructor really useful to have? Or should it always been excluded?
     
  9. Offline

    Kodfod

    The commands have to be put into the plugin.yml (not sure if you have done this already)

    Check This Tutorial
     
  10. Offline

    taka

    This is true, I was not aware that onPlayerCommand had been deprecated. So, from listing the commands in the plugin.yml, what methods are called and where when the commands are used? And are the permission nodes used in the plugin.yml the ones you'd use with, say, PEX? There really should be a master tutorial on all the changes to Bukkit somewhere...maybe I'll make one when I work out all the kinks.

    Boiled down version:

    I wanna make "/money" a command with one optional parameter being a player name and another an amount to send to that player. How would this be reflected in the plugin.yml and how would it be called in the JAR? Thank you in advance.
     
  11. A "tutorial" for changes ? That would be a changelog and it always has been public :p
    For the latest site, dl.bukkit.org, you have them even easier, just press "What's new ?" and voilla: http://dl.bukkit.org/downloads/craftbukkit/view/latest-rb/ (bottom page, the "commits").
     
  12. Offline

    taka

    I do apologize, but reading the changelog isn't quite a "tutorial". I'm using Bukkit plugins as a fun way to learn Java programming techniques (and enjoying it) but I'll be honest, as a beginner, I need a more step by step approach that the YouTube videos (users like Samkio) are very good at explaining...but unfortunately their information is out of date.

    I'm also looking at the "Commits" section, but unfortunately I'm not sure where that will provide the information on how the plugin.yml Command listings will interact with the JAR files.
     
  13. People don't really have the time to make tutorials on every change... they do on new features to let people know how they can be used (mainly posted here: http://forums.bukkit.org/forums/bukkit-preview.74/ )... but mostly, they do it in the wiki where information can be added easily, so why rely on hard to follow and hard to update VIDEO tutorials when you can read an easy tutorial in writing right from the wiki ?

    General plugin tutorial: http://wiki.bukkit.org/Plugin_Tutorial
    Plugin.yml explained: http://wiki.bukkit.org/Plugin_YAML
    Developer wiki main page: http://wiki.bukkit.org/Portal:Developers

    Also, the commits section I linked was just a general example where you can find the latest changes, it didn't reflect your issue directly.
     
  14. Offline

    taka

    Yes, thank you Digi, the http://wiki.bukkit.org/Plugin_Tutorial was the one place I hadn't looked in a long while. It is there, in the onCommand() section. Thanks!

    [EDIT: Does switch() work in Java? It seems a more efficient method of sorting through commands than if() else if() else if(), no?]

    [EDIT 2:
    Code:
    if(cmd.getName.equalsIgnoreCase("money"))

    Eclipse doesn't seem to like the getName() bit...says it isn't right. Anything tricky about it?]
     
  15. Yes switch() works with Java but only since Java 7 it works with strings.
    However, I recommend you compile your plugins using Java 6 in order to be compatible with most servers, since Java 7 compiled code can't run on a Java 6 machine, gives the "major minor" exception.
    So it's best to just use Java 6 and if-else-if-... :p

    Also, you called getName as a variable, not getName() as a method, the parantheses are the diference.
     
  16. Offline

    taka

    Okay, it's all working, but when I try to transfer money, the console is telling me there's an error here:

    Code:
    List<Player> players = getServer().matchPlayer(toPlayer);
    Something is coming up as Null when it shouldn't be, and it points to this line. toPlayer is a String being passed as the first argument of the command "/money". Is there something obvious I'm doing wrong here?
     
  17. Offline

    bitWolfy

    taka how the heck are you doing getServer() there...


    Never mind, getServer() can be used all by itself from the main plugin class.
     
  18. taka
    Are you sure that's the cause ? Post the stacktrace as it might be "array index out of bounds" which is printed in the "Caused by" at the bottom of the stacktrace and on top it says "null", might be confusing :p

    In any case, you should put more code so we can see how toPlayer is asigned and stuff :}
     
  19. Offline

    pcgamers123

    If you use Notepad++, you can go to "Edit" and "Blank Operations" and then "Tap to Space". That should fix all problems!
     
Thread Status:
Not open for further replies.

Share This Page