Strange Error on executing command

Discussion in 'Plugin Development' started by DeGambler, Oct 13, 2013.

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

    DeGambler

    Hello there people of bukkit! I've come to you to help me out in something I just can't seem to fix, the problem is this:
    Show Spoiler
    Code:
    21:43:35 [INFO] DeGambler issued server command: /ddcollect
    21:43:35 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'ddco
    llect' in plugin DailyDiamond vOR-1.4
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    2)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:959)
            at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.j
    ava:877)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :834)
            at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java
    :116)
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    92)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4
    88)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.NullPointerException
            at com.Xurame.DailyDiamond.Commands.DeliverCommand.deliverMoney(DeliverC
    ommand.java:38)
            at com.Xurame.DailyDiamond.Commands.DeliverCommand.onCommand(DeliverComm
    and.java:109)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more


    Basically its spamming that error each time I execute the "/ddcollect" command, heres the source code for the command:
    Show Spoiler
    Code:java
    1. package com.Xurame.DailyDiamond.Commands;
    2.  
    3. import java.io.File;
    4. import java.util.logging.Logger;
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.economy.EconomyResponse;
    8.  
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Material;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandExecutor;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.configuration.file.FileConfiguration;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.PlayerInventory;
    19.  
    20. import com.Xurame.DailyDiamond.DailyDiamond;
    21.  
    22. public class DeliverCommand implements Listener, CommandExecutor {
    23.  
    24. public static DailyDiamond plugin;
    25. private static final Logger log = Logger.getLogger("Minecraft");
    26. public Economy econ;
    27. public static boolean hasVault;
    28. public static FileConfiguration config;
    29. public static File dataDir = new File("plugins/DailyDiamond");
    30. public static String confFile = dataDir + "/config.yml";
    31.  
    32. public DeliverCommand(DailyDiamond instance) {
    33. plugin = instance;
    34. }
    35.  
    36. public void deliverMoney(Player player)
    37. {
    38. if (config.getBoolean("useVault")
    39. && !(config.getDouble("moneyGiven") <= 0)
    40. && econ.hasAccount(player.getName())
    41. && player.hasPermission("dd.money"))
    42. {
    43. double money = config.getDouble("moneyGiven");
    44. EconomyResponse r = econ.depositPlayer(player.getName(), money);
    45. if (!r.transactionSuccess())
    46. {
    47. log.info("[DailyDiamond]: Unable to pay " + player.getName());
    48. }
    49. player.sendMessage(String.format(ChatColor.GREEN
    50. + "You were given %s for logging in!",
    51. econ.format(r.amount)));
    52. }
    53. }
    54.  
    55. public void deliverItem(Player player)
    56. {
    57. if (player.hasPermission("dd.d"))
    58. {
    59. String diamondmsg = config.getString("Diamondmsg");
    60. int Diamonds = config.getInt("Diamondamount");
    61. PlayerInventory dInventory = ((Player) player).getInventory();
    62. ItemStack dStack = new ItemStack(Material.DIAMOND, Diamonds);
    63. dInventory.addItem(dStack);
    64. player.sendMessage(diamondmsg);
    65. }
    66. if (player.hasPermission("dd.ga"))
    67. {
    68. String GApplemsg = config.getString("GApplemsg");
    69. int GApples = config.getInt("GAppleamount");
    70. PlayerInventory gaInventory = ((Player) player).getInventory();
    71. ItemStack gaStack = new ItemStack(Material.GOLDEN_APPLE, GApples);
    72. gaInventory.addItem(gaStack);
    73. player.sendMessage(GApplemsg);
    74. }
    75. if (player.hasPermission("dd.gi"))
    76. {
    77. String Ingotmsg = config.getString("GoldIngotmsg");
    78. int Ingots = config.getInt("GoldIngotamount");
    79. PlayerInventory giInventory = ((Player) player).getInventory();
    80. ItemStack giStack = new ItemStack(Material.GOLD_INGOT, Ingots);
    81. giInventory.addItem(giStack);
    82. player.sendMessage(Ingotmsg);
    83. }
    84. if (player.hasPermission("dd.a"))
    85. {
    86. String applemsg = config.getString("Cakemsg)");
    87. int Apples = config.getInt("NormalAppleamount");
    88. PlayerInventory aInventory = ((Player) player).getInventory();
    89. ItemStack aStack = new ItemStack(Material.APPLE, Apples);
    90. aInventory.addItem(aStack);
    91. player.sendMessage(applemsg);
    92. }
    93. if (player.hasPermission("dd.c"))
    94. {
    95. String cakemsg = config.getString("Cakemsg)");
    96. int Cake = config.getInt("Cakeamount");
    97. PlayerInventory cInventory = ((Player) player).getInventory();
    98. ItemStack cStack = new ItemStack(Material.CAKE, Cake);
    99. cInventory.addItem(cStack);
    100. player.sendMessage(cakemsg);
    101. }
    102. }
    103.  
    104. @Override
    105. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    106. if (cmd.getName().equalsIgnoreCase("ddcollect")) {
    107. Player player = (Player)sender;
    108. if(player.hasPermission("dd.collect"));
    109. deliverMoney(player);
    110. deliverItem(player);
    111. }
    112. return false;
    113. }
    114. }


    Any help whatsoever is much appreciated!

    Much thanks in advance - DeGambler
     
  2. Offline

    thecrystalflame

    its throwing a nullPointerException and by the looks of it
    Code:java
    1.  
    2. if (config.getboolean("useVault"))
    3.  

    is the cause of the error. perhaps you forgot to set the boolean in the config or the capatilization is different etc.
     
  3. Offline

    inventorman101

    Is the transactionSucess() method returning a Boolean? DeGambler
     
  4. Offline

    DeGambler

    thecrystalflame Well, heres my config, should all be correct but I might be wrong:
    Show Spoiler

    Code:
    useVault: true #If you aren't using vault, change to false
    moneyGiven: 10.0 #Default value change to whatever you want
     
    Diamondmsg: "You were given a diamond for logging in!"
    Diamondamount: 1 #Set this to the amount of diamonds you want given upon login
     
    GApplemsg: "You were given a diamond for logging in!"
    GAppleamount: 1 #Set this to the amount of Gold apples you want given upon login
     
    GoldIngotmsg: "You were given a gold ingot for logging in!"
    GoldIngotamount: 1 #Set this to the amount of gold ingots you want given upon logging in
     
    NormalApplemsg: "You were given an apple for logging in!"
    NormalAppleamount: 1 #Set this to the amount of apples you want given upon login
     
    Cakemsg: "You were given a cake for logging in!"
    Cakeamount: 1 #Set this to the amount of cake you want given upon login
    


    inventorman101 It should be...
     
  5. Offline

    inventorman101

    Try ckecking if get transaction is true rather than checking if it is not DeGambler
     
  6. Offline

    thecrystalflame

    DeGambler
    hmm no that is correct. but somewhere in your deliverMoney method has a null value where it shouldnt
    if i were you i would add debug lines to single out the cause.
     
  7. Looks like you forgot to initialize the variable config.
     
  8. Offline

    DeGambler

  9. Offline

    DeGambler

    hapm Thank you, I got it to work by fixing that! :D
     
Thread Status:
Not open for further replies.

Share This Page