I need help with a config file.

Discussion in 'Plugin Development' started by Unscrewed, Mar 27, 2012.

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

    Unscrewed

    Hello everyone,

    After a long, long time I decided to pick up my simple project again.
    I basically made it for my own server and didn't really need all the fancy stuff that came with it in other plugins. It's a plugin to stop Non-Admins from placing blocks only obtainable by Creative Mode or server plugins.

    I didn't use Java for a long time now and not sure how much the Bukkit API has changed, but I learn by experimenting.

    It would be incredibely nice if someone could tell me how I could let my plugin 'create' and 'load' a config file and when there is a block in the config that isn't allowed, it cancels the Block Place event. I checked the wiki but I don't get it at all, so I'm sorry about that, I really need to learn by experimenting with something existing.

    So just a simple configuration part of the plugin.

    Also, if someone could show me how to do this, I can always add configs to my future projects, so I would be extremely thankful!

    Thanks in advance,
    Unscrewed

    I would like something like this:

    Code:
    //banned blocks
     
    blockIds: 1,2,3,4,5,6
    

    If possible, then you can edit it and the plugin reads it and cancels the BLOCK_PLACE event when the block you're trying to place is in the list, I only need to config part because I tried the things in the wiki but I guess I'm doing it wrong.

    If someone could make the config part for me I can experiment with it and I can finally add configs to my other WIP projects! :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  2. Basically just use getConfig() and getIntegerList("blocks") to get a list of integers and then just check if the ID is inside that list in your listener.

    Something like:
    Code:
    // main class
    public static List<Integer> deniedBlocks = new ArrayList<Integer>();
    
    // on enable
    deniedBlocks = getConfig().getIntegerList("deniedblocks");
    
    //listener
    if(MainClass.deniedBlocks.contains( event.getBlock().getType() ))
    {
        // ...
    }
    If you get that example above, I recommend you try something else tough, cfg.getKeys(false) or cfg.getConfigurationSection("path").getKeys(false) and use the keys and values to specify block id:data, in the config would look like:
    Code:
    path:
      50:0 // restrict chest
      35:0 // restrict white wool
      35:6 // restrict whatever color this wool this is
    // etc...
    The cfg.getKeys() doesn't require the path because it gets all keys from the config, use that if you only have blocks in that config and not other settings.

    And about the new stuff, I guess these are important:
    - new configuration: http://wiki.bukkit.org/Introduction_to_the_New_Configuration
    - new event system: http://forums.bukkit.org/threads/new-event-system.55249/
     
  3. Offline

    Unscrewed

    I will edit this post when I'm done experimenting. :)
     
Thread Status:
Not open for further replies.

Share This Page