1.8.8 Checking the value of a config value

Discussion in 'Spigot Plugin Development' started by FisherGee, Jan 28, 2020.

  1. This is currently what my data custom config looks like:

    Code (Text):
    users:
      b97ca52c-9e76-4bf4-97cd-f77d3d76f8ec:
        location:
          ==: org.bukkit.Location
          world: world
          x: 56.0
          y: 63.0
          z: 295.0
    I'm trying to figure out how to check if my file contains the x value.

    Current method not working:
    Code (Text):
    if(!ConfigManager.get().contains(String.valueOf(ConfigManager.get().getInt("users." + playerUUID + ".location.x", (int) blockX))))
     
  2. May I ask what your goal with this is? Why not just get the location object and check against .getX() ?
     
    • Agree Agree x 1
  3. Strahan

    Benefactor

    If you are writing a Location directly to the config, as it would appear, there will never not be an X value.
     
    • Agree Agree x 1
  4. I’m trying to check if there is an equivalent x value.
     
  5. The plugin has to store values. It’s like special chests, so it needs to store where they are located.
     
  6. Are you trying to check if there is already a chest stored at a certain location?
     
  7. config.getString() returns null if value could not be found.

    Code (Java):
           
    FileConfiguration config = this.getConfig();

    String str = config.getString("users." + playerUUID + ".location.x", (int) blockX);

    if(null == str){
        return;
    }

    //do something here
     
     
    • Agree Agree x 1
  8. Thank you. Will give this a test. :)
     
  9. You can also use if (config.getConfigurationSection(uuid.toString() + ".location" == null) { /* Do stuff */ }
     
    • Agree Agree x 1
  10. Thats true but you should still negate your ifs as its much more clear than interlacing code.
     
    • Agree Agree x 1