Solved Basic Config File question

Discussion in 'Spigot Plugin Development' started by CaffeineNYC, Jul 11, 2021.

  1. I have a config file that looks like:

    Code (Text):

    damage.drowning    = false
    damage.entity      = false
    damage.fire        = false
    damage.fall        = false
    damage.falling_block = false
    damage.projectile    = true
     
    I'm trying to access the values via:

    Code (Text):
    public void onEnable()
    {
         FileConfiguration config = getConfig();



         if( config.getBoolean("damage.projectile") == false) {
             System.out.println("no projectile damage");
             EntityDamageEventListener.causelist.add(EntityDamageEvent.DamageCause.PROJECTILE);
         }
    but when I run the server with my plugin, I see "no projectile damage", indicating that the value of damage.projectile was "true" when it was read in.

    Am I using the config file framework correctly?
     
  2. That's not how YAML works, you can read an explanation here. Also, for the if statement, you do not need to put == false, or == true in that case. If you just use the config#getBoolean it returns a boolean and if it's true the method will run. If you want it to run when it's false, use !config#getBoolean, that'll basically reverse the true requirement to false.
     
    • Like Like x 1
  3. What language are you trying to use? The config you are making uses yaml which is formatted like this
    Code (YAML):
    damage_drowning: false
    damage_entity
    : false
    damage_fire
    : false
    damage_fall
    : false
    damage_falling_block
    : false
    damage_projectile
    : true
    Also "." is a section in yaml. For example "damage.entity" would look like
    Code (YAML):
    damage:
      entity
    : int
    But "damage_entity" would be
    Code (YAML):
    damage_entity: int
    Also also, FileConfiguration doesn't work just like that. If you want to keep it simple just use "#getConfig" -- Read the docs
     
    #3 OllieJW, Jul 11, 2021
    Last edited: Jul 11, 2021
    • Like Like x 1
  4. Sorry for the bone-headed questions. You're right -- a little reading goes a long, long way. I was trying to learn from decompiling other plugins, and I shouldn't have.

    Everything works AOK. Thanks.
     
    • Winner Winner x 1