Dependency (very) Mini-Tutorial

Discussion in 'Plugin Development' started by Raphfrk, Mar 25, 2011.

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

    Raphfrk

    Basic dependencies were added to Bukkit a few weeks ago and they should work now, with the latest CraftBukkit.

    You can use the feature by adding a depend field to your plugin.yml.

    Example

    This is the "library" plugin's plugin.yml

    Code:
    name: Some Library Plugin
    main: com.raphfrk.bukkit.unloadtest.somelibraryplugin
    version: 123
    
    This is the "client" plugin's plugin.yml

    Code:
    name: Some Client Plugin
    main: com.raphfrk.bukkit.serverport.someclientplugin
    version: 99
    depend:
      - Some Library Plugin
    
    Note: It is also "apparently" possible to use single lines for the depend array. Isn't yml great :).

    Code:
    name: Some Client Plugin
    main: com.raphfrk.bukkit.serverport.someclientplugin
    version: 99
    depend: [Some Library Plugin]
    

    The effect is that before it loads the a plugin, it verifies that all required plugins are loaded. If a required plugin isn't loaded, it skips the plugin.

    It keeps attempting to load the plugins until either all remaining plugins are missing dependencies or all plugins have been loaded.

    Also, the most up to date version of CraftBukkit will scan for classes in all loaded plugins if it can't find it in the local class loader.
     
  2. Offline

    Afforess

    This thread is not very clear, and the example is wrong. It took me 30 minutes for me to puzzle out how to do it correctly.

    One of my plugin.yml files for other curious programmers:

    Code:
    name: Minecart Mania Station
    main: com.afforess.minecartmaniastation.MinecartManiaStation
    version: 1.06
    author: Afforess
    depend: [Minecart Mania Core]
    
     
  3. Offline

    Drakia

    Yours and his are exactly the same, but you used the single-line notation for the depend array as opposed to multi-line.
    Yours in the same format as his would be:
    Code:
    name: Minecart Mania Station
    main: com.afforess.minecartmaniastation.MinecartManiaStation
    version: 1.06
    author: Afforess
    depend:
        - Minecart Mania Core
    
     
  4. Offline

    Afforess

    Okay. Why on Earth does YML make things so mind boggling confusing?
     
  5. Offline

    Drakia

    It is indeed a crazy crazy format.
     
  6. Offline

    petteyg359

    It's a perfectly sensible format for somewhat complex configuration files.
     
  7. Offline

    Afforess

    Mmhmm... *backs away from crazy person slowly*
     
  8. Offline

    Drakia

    It's sensible once you figure out its quirks. It's just a very annoying format to try to get end-users to use :p
     
  9. Offline

    Afforess

    *breaks into run*

    I use XML for complex config, and haven't gotten very many complaints from it. Nothing like the YML issues Permissions and GM cause.
     
  10. Offline

    Raphfrk

    I have updated the OP. What is needed is a link to a yml format description.

    I think the problem is normally you can just ignore spaces. A format where spaces matter is inherently confusing.
     
  11. Offline

    petteyg359

    YAML is pretty darn simple.
    Have a thing. Add a colon after it if it has sub-things, otherwise add a dash and a space before it. Add X number of spaces before each sub-thing. The vast majority of configurations don't need any multi-line text blocks, so below pretty much covers it.

    Code:
    thing:
      sub-thing:
        sub-sub-thing:
          - sub-sub-sub-thing
          - sub-sub-sub-thing2
        sub-sub-thing2: [alternate, list, format, that, can, be, used, if, none, of, the, list, element, have, sub, things]
    
    I vastly prefer to count X spaces per level than to type a dozen extra characters of XML tags twice (begin and end) per line, and then having to add even more opening and closing section tags :)
     
  12. Offline

    AOD_Batman

    If you are on Mac I recommend using Textmate for editing YML files. It makes it hassle free.

    Also is there a place in the wiki or forums that lists the layout and elements of the plugin.yml file? I had to look through other plugins to find out there was a "alias" element for commands.
     
  13. Offline

    Celtic Minstrel

    I use TextWrangler for that. Though I don't think it will insert spaces when you press tab, it does have a quick and easy command to change tabs to spaces.

    If you're annoyed at it being whitespace-sensitive, just use the bracketed forms: {item1: val1, item2: val, ... etc ... } for mappings and [item1, item2, item3, ... etc ... ] for lists. Of course, then you need to worry about missing commas.
     
  14. Offline

    DerTod2

    Dependency is cool...
    My server starts firstly the database plugin. At the moment before I foudn this i use numbers (00_database, 01_x) for the order.
    Does it work for server stops too ? The idea with the number is for the start ok but not for stops ^^
     
Thread Status:
Not open for further replies.

Share This Page