Solved All my getConfig() wrapper methods return null

Discussion in 'Plugin Development' started by ron975, Oct 28, 2012.

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

    ron975

    Like the title says, no matter what I do, all my getConfig() wrappers return null.

    I'm building against Bukkit 1.3.2 R-1.1 BTW

    For example, I have this YAML file
    Code:yaml
    1.  
    2. items:
    3. pumpkin:
    4. enabled: true
    5. healFoodAmount: 1
    6. healHealthAmount: 0
    7. itemAmount: 10
    8. potionEffects:
    9. - regen
    10. potionStrength:
    11. regen: 1
    12. potionDuration:
    13. regen: 1
    14. messageOnEat: 'You nibbled on some seeds'
    15. messageInsufficient: 'Too..little..seeds..must..satisfy..cravings!'
    16. messageUnable: 'Doesnt seem like you are able to nibble on any seeds'
    17.  


    and this is an example of my getter.
    Code:java
    1.  
    2. public String getUnableMessage(String type){
    3. String unableMessage = plugin.getConfig().getString("items."+type+".messageUnable");
    4. return unableMessage;
    5. }
    6.  


    and I'm using this code to debug
    Code:java
    1.  
    2.  
    3. try
    4. {
    5. getLogger().info(config.getUnableMessage("pumpkin"));
    6. }
    7. catch (Exception e)
    8. {
    9. // TODO Auto-generated catch block
    10. getConfig().set("items.pumpkin.messageUnable", "[DEBUG] NOT ENOUGH MESSAGE GOES HERE");
    11. saveConfig();
    12. e.printStackTrace();
    13. }
    14.  


    Now, this throws an NPE when using the getUnableMessage() method, but when I use the normal bukkit getConfig().getString(), it works fine. I don't see anything wrong with my wrapper methods.. Someone help please?

    Full source of my plugin here
    https://github.com/ron975/PumpkiNibble/tree/debug
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    entire stack trace will be helpful for you to determine what is causing the exception
     
  3. Offline

    CorrieKay

    im gonna go out on a limb and take a random guess.

    Your type string in the config is lowercase, are you using something like, getUnableMessage(itemStack.getType().name());?

    If so, try setting it to lowercase, name().toLowerCase()
     
  4. Offline

    ron975

    I'm manually passing the string to the method, i.e.
    getUnableMessage("pumpkin");

    Sagacious_Zed
    As for full stack trace, if I put
    getLogger().info(config.getUnableMessage("pumpkin"));
    in my onEnable()
    Code:java
    1.  
    2. 8:10:08 PM [SEVERE] Error occurred while enabling PumpkiNibble v1.0 (Is it up to date?)
    3. at net.mystia.PumpkiNibble.PumpkiNibbleMain.onEnable(PumpkiNibbleMain.java:84)
    4. at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    5. at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:374)
    6. at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    7. at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:270)
    8. at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:252)
    9. at net.minecraft.server.MinecraftServer.i(MinecraftServer.java:298)
    10. at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:277)
    11. at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:227)
    12. at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:140)
    13. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
    14. at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    15.  
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    the variable config is null. As far as i can tell your alternating between the variable config which you should not have, and the method call.
     
  6. Offline

    ron975

    Sagacious_Zed
    config is a reference to my getters class. However, I guess for this I should be using static-access anyways, so I'll try using a static method.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    config should never be static access.
     
  8. Offline

    ron975

    Take a look at my source code, specifically PumpkiNibbleMain.java

    config is not an instance of my configuration, but an instance of PumkiNibbleAPI.java (or in this case, PumpkiNibbleAPIDebug.java), which contains all my wrapper methods.
     
  9. Offline

    ron975

    Solving this, all I had to do was make my API methods static, I also did
    Code:
    private static ConfigurationSection config = PumpkiNibbleMain.p.getConfig();
    Just in case.
     
Thread Status:
Not open for further replies.

Share This Page