Discussion: Oops, I broke your plugins!

Discussion in 'Plugin Development' started by EvilSeph, Jan 17, 2011.

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

    Dinnerbone Bukkit Team Member

    Post the full error it gives you.
     
  2. Offline

    DjDCH

    I'm not at home right now, but it was an InvalidPluginException, the same exception if you use the old plugin constructor. As soon I can, I will release the complete stacktrace.
     
  3. Offline

    Dinnerbone Bukkit Team Member

    InvalidPluginException can mean many things. Off the top of my head:
    - The jar was corrupt
    - The plugin.yml is invalid
    - The main class was missing or mispelt
    - The plugin threw an exception during initialization
    - The constructor is invalid
    - The plugin isn't compatible with your server
    etc
     
  4. Offline

    DjDCH

    Ok. I will try tonight with a working plugin, only change the package, rebuild and see if I get this exception again.
     
  5. Offline

    Raphfrk

    What about using something like:

    Code:
        @Override
        public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
    
            StringBuilder sb = new StringBuilder();
            sb.append("/" + commandLabel);
    
            for(String arg : args) {
                sb.append(" " + arg);
            }
    
            commandSender.sendMessage("The command line you sent was: " + sb.toString());
        }
    
     
  6. Offline

    xZise

    Jep it is possible (and I'm using this since yesterday (or the day before)). The only problems are first that this unnecessary work (I don't know how effective split and concat are). And second I'm not sure if this will recover every space. For example if you use “Hello␣␣world” as text. But as a work around this will do it. And dinnerbone said here, that he is working on this, so this won't be necessary one day (hopefully these days are near).

    Fabian
     
  7. Offline

    Raphfrk

    I think the split method will preserve all spaces

    Hello<space><space>World

    will give

    args[0] = "Hello"
    args[1] = ""
    args[2] = "World"
     
  8. Offline

    Dinnerbone Bukkit Team Member

     
  9. Offline

    Sammy

    Dinnerbone I'm getting a strange error on my yml file

    Code:
      rpgmod:
        description: SyDeckRPGmod admin console.
        usage: |
               /<command> - Admin help.
               /<command> guild - Guild managemnt.
               /<command> perm - Guild permissions.
    some of the usages apear in two lines on the console for exemple

    /rpg
    mod perm - guild permissions.

    or

    /<command> quests
    - Shows guilds agended quests.

    Sorry if this is mine error not bukkit's :)
     
  10. Offline

    Celtic Minstrel

    @The_Wrecker

    Sorry, but this is just bugging me. You keep asking for an onLoad function, but doesn't the constructor already serve that purpose? I'm not saying you should use it, but if you really need it, that's what it's for. In short, the constructor is called when the plugin is loaded, so if you really need to do something upon loading, put it in the constructor.

    I suppose the finalizer would probably be called when it is unloaded. I'm not sure though.
     
  11. Offline

    xZise

    It doesn't serve the purpose, because in the constructor not all values (e.g. the plugin name) are set.

    Fabian
     
  12. Offline

    Celtic Minstrel

    What, you don't know the name of your own plugin? :p
     
  13. Offline

    xZise

    The name you could maybe use. But the version is a bit trickier (you have to edit two files) and the path to the plugin directory is impossible.

    Fabian
     
  14. Offline

    The_Wrecker

    I thought about not responding, but why the heck not,

    Anyway here goes:

    A Finalizer is not equal to a destructor.
    There's no control when that is called. It depends on the garbage collector. In C/C++ you do have that control and you actually need it (memory leaks anyone?). Relying on the finalizer is bad practice when using Java, I know it's there, but... never know when it's called. I just try to keep away from it (in Java anyway).

    I know about the constructor, I have 14+ years of programming experience so don't worry. I appreciate the help though.
    You are right about using the contructor to already do some initialization and startup, except I don't have any initialized fields in there.

    Which means getDataFolder() returns null! And I want to access that before the onload function gets called. Right now there is just no way to do that.

    I've managed to work around this, but I think this limits the Bukkit API in its flexibility. As I understand it the Bukkit team is afraid that it'll lead to 'dirty hacky programming'.

    Just so you know. An initialize function/method is already there and called, but you can't @Override it because it is marked as final. It's ok and fine to mark things as final so you can't access it or to make sure the code in the super class is executed. I just want to point out that it's a one liner. Such a method does not have to be implemented either btw. If you don't need it you could totally forget about it. It's not a plugin breaking feature either.


    All of the above is based on my opinion. It's just my thought about this. For the most part Bukkit is great.
     
  15. Offline

    Celtic Minstrel

    Yeah, more or less aware of the uselessness of the finalizer. ;)

    So, calling super() does not initialize it? Though I'd expect that to happen automatically, I'm not actually sure if it does.


    I guess I'll agree that being able to do stuff on load is not a bad idea, even though there's not a whole lot you'd want to do then. I don't however see a reason for a separate function for it when you have the constructor.
     
  16. Offline

    xZise

    No super() doesn't initialize anything (how should the plugin access the data?). The plugin loader first creates an instance via the default constructor and then call
    Code:
    JavaPlugin.initialize()
    .

    Fabian
     
  17. Offline

    The_Wrecker

    Of course I meant befor the onEnable() not the onLoad() because that doesn't exist ;)
     
  18. Offline

    Lodran

    I'm not sure about Java, but with C++, doing anything that can cause an exception in a constructor is a very bad idea, for a whole lot of reasons mostly having to do with memory leaks, and the fact that the class of an object is continually changing as it is being constructed.

    This has resulted in C++ programmers getting in the habit of putting only the simplest initialization code in their object constructors, and using separate initialization methods to prepare the object for use.

    I don't know that this habit is really needed for Java coding, but it doesn't hurt all that much [​IMG]
     
  19. Offline

    Celtic Minstrel

    I don't really like that habit, to be honest, and throwing an exception in the constructor is, in my opinion, a better way to indicate failure to initialize than having a separate "isValid()" function with an "initialize()" function that returns true on success; if the constructor succeeds, the object should really not be in a state of limbo. And of course throwing an exception is the only way to indicate failure in a constructor.

    And yes, I do C++. It was my first real programming language.
     
  20. Offline

    Lodran

    TBH, my very bad experiences with exceptions in constructors causing memory leaks is 10-15 years old. Still, calling virtual methods from within a constructor won't get you the behavior you expect (Unless you're expecting overriden methods to be bypassed [​IMG] ). If it wasn't for the second problem, I'd agree with you completely.
     
  21. Offline

    Celtic Minstrel

    If I recall, the virtuality of a function in C++ is ignored when called from inside a constructor; that is, it always calls the version of the function in the class being constructed, regardless of whether it's overridden later (because "later" doesn't exist yet). So yeah, definitely not the behaviour you'd expect.
     
  22. Offline

    SycoPrime

    Code:
    The type <PLUGIN_TYPE> must implement the inherited abstract method Plugin.onLoad()
    What goes in onLoad?
     
  23. Offline

    Sammy

    Code:
        /**
    * Called after a plugin is loaded but before it has been enabled.
    * When mulitple plugins are loaded, the onLoad() for all plugins is called before any onEnable() is called.
    */
        public void onLoad();
     
  24. Offline

    Acru

    Regarding build 561+, and the event changes;

    I was using BLOCK_RIGHTCLICK with a low priority as I wanted it early in the chain before other plugins, but BLOCK_INTERACT with the highest priority, for the last say on local security checks.

    How can I do both with the new single event? o3o
     
  25. Offline

    Celtic Minstrel

    Well, I don't think there's any reason you can't register the same event twice with different priorities. Try that? It'll probably require two listeners, though.
     
  26. Offline

    matejdro

    What to use as alternative?
     
  27. Offline

    Celtic Minstrel

    Clearly you didn't read the post. It's replaced with PlayerInteract.
     
  28. Offline

    matejdro

    Yes, i just glanced through it. Sorry.

    Any ETA, when will these changes go into recommended build?
     
  29. Offline

    NathanWolf

    Anyone else getting a crazy amount of illegal access errors?

    Anything I haven't marked public is now blowing up, even if I'm only accessing from within the same package. Did something change?

    This is only with latest code, not latest RB- does latest RB have the interact changes? People want those, I guess.
     
  30. Offline

    xZise

    How could you access a non public variable/method without the same package? Only inheritance with protected fields/method could work about the package borders.

    The coming RB? Maybe. The RB promoted now? No.

    Fabian
     
Thread Status:
Not open for further replies.

Share This Page