Player configuration problem?

Discussion in 'Plugin Development' started by jusjus112, Apr 24, 2014.

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

    jusjus112

    I have setup an class for per player config's
    The creation works fine, every player has the items in their config!
    But when i will get an string or boolean from the config, it doesnt work!
    I have used the normal configuration system, but it returns null!
    Here is the get bollean:
    Code:java
    1. if (Main.pd.getData().getBoolean("Guns." + "uzi", false)) {

    And here is the onPlayerJoinUpdateConfig:
    Code:java
    1. pd.getData().set("Guns." + "ultraPistol", false);
    2. pd.getData().set("Guns." + "shotgun", false);
    3. pd.getData().set("Guns." + "uzi", false);
    4. pd.getData().set("Guns." + "Vip." + "sniper", false);
    5. pd.getData().set("Guns." + "Vip." + "rocketLauncher", false);
    6. pd.getData().set("iceBlock", false); // Use as normal configuration file
    7.  
    8. pd.save(); // You must do this after making any edits.
     
  2. Why are you concatenating strings like "Guns." + "Vip." + "sniper" when you can just do "Guns.Vip.sniper"?

    Is it the getBoolean() method that's returning null? If it is, that means that the config file does not contain a value for the path specified, and there isn't a default. Please post your config.
     
  3. Offline

    raGan.

    getBoolean() won't return null. I believe he is talking about something else, possibly NPE?
     
  4. raGan. That's true, silly me, forgetting what primitives are.
     
  5. Offline

    jusjus112

    AdamQpzm
    raGan.
    What i want is to get the boolean from the config. But when im getting it, its doest work.
    But when i do setting the boolean to null, it works!
    Here is my config:
    Code:
    Guns:
      ultraPistol: false
      shotgun: false
      uzi: false
      Vip:
        sniper: false
        rocketLauncher: false
     
  6. Offline

    jusjus112

    Help?..... (Bump)
     
  7. Offline

    Zethariel

    Full code or it didn't happen.
     
  8. Offline

    jusjus112

  9. Offline

    Zethariel

    jusjus112 Those are snippets. Post FULL code. 90% of the time the snippet does not contain an error, and the fault is something trivial before or afterwards.
     
  10. Offline

    jusjus112

    Zethariel
    Here im setting the config:
    Code:java
    1. public String playerJoiner;
    2. public PlayerData pd = new PlayerData(playerJoiner);
    3.  
    4. public void setData() {
    5. pd.getData().set("Guns.ultraPistol", false);
    6. pd.getData().set("Guns.shotgun", false);
    7. pd.getData().set("Guns.uzi", false);
    8. pd.getData().set("Guns.Vip.sniper", false);
    9. pd.getData().set("Guns.Vip.rocketLauncher", false);
    10. pd.getData().set("iceBlock", false); // Use as normal configuration file
    11.  
    12. pd.save(); // You must do this after making any edits.
    13. }

    But what i said, is that the getMethod is not working!
    If you want my pd class, here it is:
    http://pastebin.com/Gf2kTMLL
     
  11. Offline

    Zethariel

    jusjus112 Are you positive that the values get set in the saved file? Returning the FileConfiguration doesn't set the private fields inside pd - you just return a copy of the current state it was in. You need a separate setter method in order to alter the private field.
     
  12. Offline

    jusjus112

  13. Offline

    jusjus112

Thread Status:
Not open for further replies.

Share This Page