[!] Configuration file not working correctly?

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

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

    Unscrewed

    Hello, I recently added a configuration file to my plugin, but it's not working correctly.
    My goal: Add a config that if you add block id's, it stops you from placing these blocks.
    Could someone tell me what's wrong? It's simply not blocking the block id's I add to the file.

    iBlock.class
    -snip-

    iBlockListener.class
    -snip-

    So I added a folder (iBlock) with a file called: "config.yml" in it to /plugins.
    My config looks like this (very simple):

    Code:
    bannedBlocks: 1
    I can still place Stone even when I have no permissions at all.
    What am I doing wrong?

    EDIT: Am I supposed to do this?
    Code:
    bannedBlocks: STONE, COBBLE_STONE
    I am not at home right now, so I can't test but if someone could tell me what's wrong, I would greatly appreciate that.

    Thanks in advance,
    Nathan.
     
  2. in your listener you have
    Code:
    event.getBlock().getType()
    use
    Code:
    event.getBlock().getType().getId()
     
  3. Offline

    Unscrewed

    Will that fix the whole problem? Like, did I do the config part right, or...?

    Thanks by the way!
    - Nathan
     
  4. It should fix it yes. And the configs look correct to me.
     
  5. Offline

    Unscrewed

    Well, thanks so much if it works! I can't try it out yet because I'm not at home, but when I get home in approx. 2hours I will give you an update on wether it works or not. :)

    Well, it can reload the config properly and gives errors in the console when I add weird symbols, so that is a great thing to know. Since it successfully reads the config file, I think this is the problem:

    Part of the listener:
    Code:
    public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    if(iBlock.deniedBlocks.contains(event.getBlock().getType().getId())){
    event.setCancelled(true); //stop player from placing block, correct?
    player.sendMessage(ChatColor.GREEN + "[iBlock] " + ChatColor.RED + "You're not allowed to place this block.");
    }else{
    //nothing
    }
    }
    
    My config, maybe that's not correct?
    Code:
    bannedBlocks:
    50 //torch
    1 //stone
    
    I also tried: "bannedBlocks: 1" and more, doesn't work either.

    I think the

    'if(iBlock.deniedBlocks.contains(event.getBlock().getType().getId())){'

    isn't right because it doesn't ban blocks, whatever I do, deop myself, remove permissions, etc.
    What is another way to do this? Because I read that: "event.getBlock()" doesn't get the block you're placing, but the block you're placing it on... which is not what I want, not sure if I'm really wrong here though.

    I just want it to read the config and if one of the block ID's in the config gets placed,
    the event gets canceled.

    This is still the right way to cancel block placements?
    Code:
    event.setCancelled(true);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  6. When event.getBlock() does not return the block that you want to place then you can try out event.getBlockPlaced
    But I don't think this does change anything...
     
  7. Offline

    Unscrewed

    I think it's the way I write the ids in the config file, doesn't it need some kind of... seperation like a ","?
    I suck at making config files, but I think it needs a way to check for individual id's...
     
  8. As you said you might did something wrong with the config, I took a look again and yes, you're doing something wrong. Since it's a list, you want to either do it like an array so
    Code:
    bannedBlocks: [1,2,45]
    or (how the parse will do it) as an actual list:
    Code:
    bannedBlocks:
    - 1
    - 2
    - 45
     
  9. Offline

    Unscrewed

    Hey, sorry for the late response, it still doesn't work for me, I can just place the blocks.

    iBlock.class:
    -snip-

    iBlockListener.class:
    -snip-

    Also, thanks SO much for all your time, I really appreciate it!
     
  10. 'easy' mistake:
    your forgot the @EventHandler annotation above your event-function.
     
    Unscrewed likes this.
  11. Offline

    Unscrewed

    ...Wow, I have no words for my stupidity and for your cleverness, thanks so much man!
    It finally works! Phew, thanks, once again!

    Oh, there is one more small problem... sorry.
    When I make a config like this:
    It only bans bedrock and ignores the others.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  12. are the comments also in the config? try without them if they are.
     
Thread Status:
Not open for further replies.

Share This Page