Solved getConfig().contains returns false

Discussion in 'Spigot Plugin Development' started by Goksi88, Nov 25, 2021.

  1. Hi, I am using 1.8.8 spigot api and trying to use contains method to check if config already has that path.
    Code (Text):

    String a = String.valueOf(data.getCustomConfig().contains("killstreaks.GoksiMaca" ));
    Bukkit.broadcastMessage(a);
     
    But this always return false even if my config contains that path
    I also tried isSet() but it also returns false.
    my config:
    Code (Text):

    killstreaks:
      GoksiMaca: 0
      GoksiTest: 3
     
     
  2. why do you need that?
     
  3. Code I typed here was actually just for debugging, Im using it to check if my data file (custom yaml config) already have set value of specific player.
     
  4. Strahan

    Benefactor

    Well, another way you could check with a method would be like:
    Code (Text):
    public boolean configPathExists(String path) {
      return data.getCustomConfig().getString(path) != null;
    }
     
    • Useful Useful x 1
  5. Yeah, already done that, looks like contains() is implemented in 1.9 api, thanks alot anyway
     
  6. Add your own. This is what I did:
    Code (Text):
    private boolean contains(String path, boolean ignoreDefault) {
        // This duplicates the method added in 1.9, Bukkit commit facc9c353c3
        return ((ignoreDefault) ? plugin.getConfig().get(path, null) : plugin.getConfig().get(path)) != null;
    }
    You may have to change the plugin.getConfig() parts.
     
    • Agree Agree x 1