Saving to config stopped working

Discussion in 'Plugin Development' started by unrealdesign, Mar 22, 2013.

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

    unrealdesign

    Recently after a day of adding code to other commands of the same plugin, I realized that saving to the config has stopped working. I used HashMaps before, and now they aren't working. I know the code didn't change because I have another plugin that used the same type of code and was working, I tried it again, and it wasn't working again anymore. I'll post the code all the code that has to deal with the adding and removing to the config:

    Main Class:
    Code:java
    1. private HashMap<String, Double> playerBounty;
    2.  
    3. public void addPlayerBounty(final String newBounty, final Double newPrice){
    4. this.playerBounty.put(newBounty, newPrice);
    5. this.getConfig().set("bounties."+newBounty, newPrice);
    6. this.saveConfig();
    7. }
    8.  
    9. public void addExtraPlayerBounty(final String newBounty, final Double newPrice){
    10. this.playerBounty.put(newBounty, newPrice);
    11. int oldPrice = this.getConfig().getInt("bounties."+newBounty);
    12. this.getConfig().set("bounties."+newBounty, newPrice+oldPrice);
    13. this.saveConfig();
    14. }
    15.  
    16. public void removePlayerBounty(final String newBounty, final Double newPrice){
    17. this.playerBounty.put(newBounty, newPrice);
    18. this.getConfig().set("bounties."+newBounty, newPrice);
    19. this.saveConfig();
    20. }
    21.  
    22. public void onEnable() {
    23. getLogger().info("has been enabled.");
    24. this.saveDefaultConfig();
    25. if (!new File(getDataFolder(), "config.yml").exists()) {
    26. saveDefaultConfig();
    27. }
    28. }
    29.  
    30. public void onLoad() {
    31. this.getConfig().options().copyDefaults(true);
    32. this.playerBounty = new HashMap<String, Double>();
    33. }


    How I call it in:
    Code:java
    1. private final FZBounty plugin;
    2.  
    3. public Bounty(final FZBounty plugin) {
    4. this.plugin = plugin;
    5. }
    6.  
    7. //Called when a player does a command, so it's not by itself like this
    8. this.plugin.addPlayerBounty(newBounty, newPrice);



    Error:
    Code:
    2013-03-23 07:34:44 [SEVERE] java.lang.reflect.InvocationTargetException
    2013-03-23 07:34:44 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2013-03-23 07:34:44 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    2013-03-23 07:34:44 [SEVERE]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    2013-03-23 07:34:44 [SEVERE]    at java.lang.reflect.Method.invoke(Unknown Source)
    2013-03-23 07:34:44 [SEVERE]    at me.djoutbased.commands.CommandController.onCommand(CommandController.java:185)
    2013-03-23 07:34:44 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    2013-03-23 07:34:44 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:187)
    2013-03-23 07:34:44 [SEVERE]    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServer.java:545)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.handleCommand(PlayerConnection.java:980)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.chat(PlayerConnection.java:896)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:840)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.Packet3Chat.handle(Packet3Chat.java:44)
    2013-03-23 07:34:44 [SEVERE]    at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:174)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:113)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
    2013-03-23 07:34:44 [SEVERE]    at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:66)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:582)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:229)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:471)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:403)
    2013-03-23 07:34:44 [SEVERE]    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    2013-03-23 07:34:44 [SEVERE] Caused by: java.lang.NullPointerException
    2013-03-23 07:34:44 [SEVERE]    at me.djoutbased.FZBounty.FZBounty.addExtraPlayerBounty(FZBounty.java:34)
    2013-03-23 07:34:44 [SEVERE]    at me.djoutbased.commands.Bounty.setBountyCommand(Bounty.java:56)
    2013-03-23 07:34:44 [SEVERE]    ... 21 more
    FZBounty error points to: this.playerBounty.put(newBounty, newPrice);
    Bounty error points to: this.plugin.addExtraPlayerBounty(target.getName(), money);
     
  2. Offline

    c0mp

    Moved to Plugin Development!
     
  3. Offline

    unrealdesign

    Any ideas anyone??
     
  4. Offline

    ZeusAllMighty11

    It's like 2am... (here) ... Don't bump threads so soon, wait like half a day.

    Make sure plugin variable isn't null and also is it an eclipse or stacktrace error?
     
  5. Offline

    unrealdesign

    Alright my bad, first time posting here.

    No inputs are null, if the input is null it will tell the player. Only time a input is null is when it's removing from the config. I have no errors in eclipse, the error is posted above, and I don't know what a stacktrace error is, sorry.

    I check to make sure all values are good with this:
    Code:java
    1. if(target != null && money > 0 && r.transactionSuccess())
     
Thread Status:
Not open for further replies.

Share This Page