How would I use an 'if' statement, using config.yml?

Discussion in 'Plugin Development' started by BestMcPlayers, Dec 29, 2014.

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

    BestMcPlayers

    Hi,

    I vaguely know about configuration files, but I'm learning about them. I can make a simple plugin using configuration files, but I'm working on something big.

    Let's say that I would disable an command if in the configuration file (BlahBlah = false). How would I do this? Remember I'm new to configuration files. If (blah is true in config run the command and if blah is false in config don't run it and send a error message.

    Thanks.
     
    Last edited: Jan 3, 2015
  2. Offline

    SuperOriginal

    Configuration#getStringList(key).contains(command)
     
  3. Offline

    Gamesareme

    @BestMcPlayers Something like this.
    Code:
    if(plugin.getConfig().getBoolean("SomeBoolean") == true){
    //Do something.
    }
     
  4. Offline

    567legodude

    I personally use a configuration API that I found when I was first learning plugins.
    So I would call that class as data and use it like this:
    if (data.getString("name").equals("other string")) {
    // action
    }
     
  5. Offline

    stoneminer02

    1. Why was that in a JavaScript code mark?
    2. Why the == true?
     
    Concurrent likes this.
  6. Offline

    Gamesareme

    @stoneminer02 It is not needed, and I do not use them. I added them here though, so that it is clear how it works.
     
  7. @Gamesareme The "SomeBoolean" part makes it look like you put a boolean inside that, though. :D
     
  8. Offline

    Gamesareme

    Lionhard likes this.
  9. @Gamesareme Yes, yes. :) You did everything correct. :) But I'm not sure if == would even work.
     
    Gamesareme likes this.
  10. Offline

    API_Tutorials

    @Lionhard
    Of course it would work, it's just not necessary.
     
  11. @API_Tutorials Alright. :p Not used to this, because I do not use = neither I use == :p
     
  12. Offline

    WampyCakes

    Just instance your plugin's Main class. Then check the config then check if that string contains true or false. Then use if statements to check if it's true or false, so you can decide what happens next.
     
  13. Offline

    Concurrent

    @BestMcPlayers pseudo:
    Code:
    onCommand(){
       if(getConfig().getBoolean("some.path"){
      // do stuff
    }else{
    // send message
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page