NullPointerException

Discussion in 'Plugin Development' started by HyrulesLegend, Nov 16, 2013.

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

    HyrulesLegend

    For some reason, on PlayerDeathEvent, it's throwing a nullpointerexception


    Stacktrace:
    Code:
    org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    16.11 22:05:34 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source)
    16.11 22:05:34 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    16.11 22:05:34 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    16.11 22:05:34 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    16.11 22:05:34 [Server] INFO at me.kitpvp.Events.KillEvent.onPlayerKill(KillEvent.java:26)
    16.11 22:05:34 [Server] INFO Caused by: java.lang.NullPointerException
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.Packet7UseEntity.handle(SourceFile:36)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:1121)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.EntityHuman.attack(EntityHuman.java:884)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.EntityPlayer.damageEntity(EntityPlayer.java:383)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.EntityHuman.damageEntity(EntityHuman.java:714)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.EntityLiving.damageEntity(EntityLiving.java:710)
    16.11 22:05:34 [Server] INFO at net.minecraft.server.v1_6_R3.EntityPlayer.die(EntityPlayer.java:312)
    16.11 22:05:34 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:344)
    16.11 22:05:34 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    16.11 22:05:34 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    16.11 22:05:34 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    16.11 22:05:34 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    16.11 22:05:34 [Server] INFO org.bukkit.event.EventException
    16.11 22:05:34 [Server] SEVERE Could not pass event PlayerDeathEvent to bKitPvP v1.1
    I noticed it said KillEvent.java.26, so here's line 26:
    Code:java
    1. Main.economy.depositPlayer(p.getName(), plugin.getConfig().getInt("cashonkill"));
     
  2. Offline

    xTrollxDudex

    Max_The_Link_Fan
    This is exactly why you should not refer to static fields. Everything simply screws up.

    Back to the topic, make sure your economy field is initialized and there actually exists a path called cashonkill in your config
     
  3. Offline

    HyrulesLegend

    xTrollxDudex cashonkill exists, Economy is initialized.
     
  4. Offline

    xTrollxDudex

  5. Offline

    HyrulesLegend

    xTrollxDudex
    Code:java
    1. public Main plugin;
    2.  
    3. public KillEvent(Main instance)
    4. {
    5. this.plugin = instance;

    That's where I define plugin, Main is my main class's name.
     
  6. Offline

    xTrollxDudex

    Max_The_Link_Fan
    It would be nice if you can post Main and the entire KillEvent class with the config.
     
  7. Offline

    HyrulesLegend

    KillEvent:
    Code:java
    1. package me.kitpvp.Events;
    2.  
    3. import me.kitpvp.SonicKit.Main;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.PlayerDeathEvent;
    10.  
    11. public class KillEvent
    12. implements Listener
    13. {
    14. public Main plugin;
    15.  
    16. public KillEvent(Main instance)
    17. {
    18. this.plugin = instance;
    19. }
    20.  
    21. @EventHandler
    22. public void onPlayerKill(PlayerDeathEvent e) {
    23. Player p = e.getEntity().getKiller();
    24. Player d = e.getEntity();
    25. String prefixmsg = plugin.getConfig().getString("prefixmsg");
    26. Main.economy.depositPlayer(p.getName(), this.plugin.getConfig().getInt("cashonkill"));
    27. p.sendMessage(ChatColor.GREEN + "You have received $" + plugin.getConfig().getInt("cashonkill") + " for killing " + d.getName() + ". Your new balance is " + Main.economy.getBalance(p.getName()));
    28. e.setDeathMessage(null);
    29. Bukkit.broadcastMessage(ChatColor.GRAY + "[" + prefixmsg + "] " + ChatColor.AQUA + p.getName() + " has slain " + d.getName());
    30. }
    31. }


    Main:
    Code:java
    1. package me.kitpvp.SonicKit;
    2.  
    3. import me.kitpvp.Events.DeathEvent;
    4. import me.kitpvp.Events.HungerDisable;
    5. import me.kitpvp.Events.JoinMessage;
    6. import me.kitpvp.Events.KillEvent;
    7. import me.kitpvp.Events.Respawn;
    8. import me.kitpvp.Events.SlashSoup;
    9. import me.kitpvp.Help.Kits;
    10. import me.kitpvp.Help.Main_Help;
    11. import me.kitpvp.Help.Pl;
    12. import me.kitpvp.Help.Pl2;
    13. import me.kitpvp.Help.Rules;
    14. import me.kitpvp.Kits.Archer;
    15. import me.kitpvp.Kits.Blaze;
    16. import me.kitpvp.Kits.Dwarf;
    17. import me.kitpvp.Kits.Elite;
    18. import me.kitpvp.Kits.Fisherman;
    19. import me.kitpvp.Kits.Grandpa;
    20. import me.kitpvp.Kits.Knight;
    21. import me.kitpvp.Kits.PvP;
    22. import me.kitpvp.Kits.Sniper;
    23. import me.kitpvp.Kits.Sonic;
    24. import me.kitpvp.Kits.Switcher;
    25. import me.kitpvp.Kits.Tank;
    26. import me.kitpvp.Kits.Urgal;
    27. import me.kitpvp.Kits.Viking;
    28. import me.kitpvp.Kits.Viper;
    29. import me.kitpvp.Kits.scout;
    30. import me.kitpvp.Mod.Invsee;
    31. import net.milkbowl.vault.economy.Economy;
    32.  
    33. import org.bukkit.event.Listener;
    34. import org.bukkit.plugin.PluginManager;
    35. import org.bukkit.plugin.RegisteredServiceProvider;
    36. import org.bukkit.plugin.java.JavaPlugin;
    37.  
    38. public class Main extends JavaPlugin implements Listener {
    39.  
    40.  
    41. SettingsManager settings = SettingsManager.getInstance();
    42.  
    43.  
    44.  
    45. // Define Command Executors
    46. private PvP executor;
    47. private Archer executor1;
    48. private Elite executor2;
    49. private Knight executor3;
    50. private Blaze executor4;
    51. private Tank executor5;
    52. private Fisherman executor6;
    53. private Switcher executor7;
    54. private Sniper executor9;
    55. private Grandpa executor10;
    56. private scout executor11;
    57. private Viking executor12;
    58. private Main_Help executor13;
    59. private Pl executor14;
    60. private Pl2 executor15;
    61. private Rules executor18;
    62. private Kits executor19;
    63. private Sonic executor20;
    64. private Urgal executor21;
    65. private Dwarf executor22;
    66. private SlashSoup executor23;
    67. private Viper executor24;
    68. private Invsee executor25;
    69. private PotPvP executor26;
    70.  
    71.  
    72.  
    73. public static Economy economy = null;
    74.  
    75. private boolean setupEconomy()
    76. {
    77. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    78. if (economyProvider != null) {
    79. economy = economyProvider.getProvider();
    80. }
    81.  
    82. return (economy != null);
    83. }
    84.  
    85. //Define Events
    86. private HungerDisable PlayerListener = new HungerDisable(this);
    87. private JoinMessage PlayerListener4 = new JoinMessage(this);
    88. private Respawn PlayerListener7 = new Respawn(this);
    89. private KillEvent kill = new KillEvent(this);
    90. private DeathEvent d = new DeathEvent(this);
    91.  
    92.  
    93. public void onEnable() {
    94. getConfig().options().copyDefaults(true);
    95. saveConfig();
    96. settings.setup(this);
    97. setupEconomy();
    98.  
    99.  
    100. //Register Commands
    101. executor = new PvP(this);
    102. getCommand("pvp").setExecutor(executor);
    103.  
    104. executor1 = new Archer(this);
    105. getCommand("archer").setExecutor(executor1);
    106.  
    107. executor2 = new Elite(this);
    108. getCommand("elite").setExecutor(executor2);
    109.  
    110. executor3 = new Knight(this);
    111. getCommand("knight").setExecutor(executor3);
    112.  
    113. executor4 = new Blaze(this);
    114. getCommand("blaze").setExecutor(executor4);
    115.  
    116. executor5 = new Tank(this);
    117. getCommand("tank").setExecutor(executor5);
    118.  
    119. executor6 = new Fisherman(this);
    120. getCommand("fisherman").setExecutor(executor6);
    121.  
    122. executor7 = new Switcher(this);
    123. getCommand("switcher").setExecutor(executor7);
    124.  
    125.  
    126. executor9 = new Sniper(this);
    127. getCommand("sniper").setExecutor(executor9);
    128.  
    129. executor10 = new Grandpa(this);
    130. getCommand("grandpa").setExecutor(executor10);
    131.  
    132. executor11 = new scout(this);
    133. getCommand("scout").setExecutor(executor11);
    134.  
    135. executor12 = new Viking(this);
    136. getCommand("viking").setExecutor(executor12);
    137.  
    138. executor13 = new Main_Help(this);
    139. getCommand("help").setExecutor(executor13);
    140.  
    141. executor14 = new Pl(this);
    142. getCommand("pl").setExecutor(executor14);
    143.  
    144. executor15 = new Pl2(this);
    145. getCommand("?").setExecutor(executor15);
    146.  
    147. executor18 = new Rules(this);
    148. getCommand("rules").setExecutor(executor18);
    149.  
    150. executor19 = new Kits(this);
    151. getCommand("kits").setExecutor(executor19);
    152.  
    153. executor20 = new Sonic(this);
    154. getCommand("sonic").setExecutor(executor20);
    155.  
    156. executor21 = new Urgal(this);
    157. getCommand("urgal").setExecutor(executor21);
    158.  
    159. executor22 = new Dwarf(this);
    160. getCommand("dwarf").setExecutor(executor22);
    161.  
    162. executor23 = new SlashSoup(this);
    163. getCommand("soup").setExecutor(executor23);
    164.  
    165. executor24 = new Viper(this);
    166. getCommand("viper").setExecutor(executor24);
    167.  
    168. executor25 = new Invsee(this);
    169. getCommand("seeinv").setExecutor(executor25);
    170.  
    171. executor26 = new PotPvP(this);
    172. getCommand("potpvp").setExecutor(executor26);
    173.  
    174.  
    175.  
    176.  
    177.  
    178.  
    179.  
    180.  
    181.  
    182.  
    183. //Register Events
    184. PluginManager event = getServer().getPluginManager();
    185. event.registerEvents(this.PlayerListener, this);
    186.  
    187.  
    188.  
    189. PluginManager join = getServer().getPluginManager();
    190. join.registerEvents(this.PlayerListener4, this);
    191.  
    192. PluginManager respawn = getServer().getPluginManager();
    193. respawn.registerEvents(this.PlayerListener7, this);
    194.  
    195. PluginManager kill = getServer().getPluginManager();
    196. kill.registerEvents(this.kill, this);
    197.  
    198. PluginManager d = getServer().getPluginManager();
    199. d.registerEvents(this.d, this);
    200.  
    201.  
    202.  
    203.  
    204.  
    205. }
    206. }
    207.  


    Config:
    Code:
    rule1: No hacking
    rule2: No spamming
    rule3: No kit mixing
    rule4: No asking for ranks
    rule5: No going out of map/greifing
    rule6: No DDoS, Dox, or Dos of any sort
    rule7: Respect all staff
    rule8: No free for all in 1v1 arenas.
    rule9: No advertising other servers
    rule10: No combat logging
    pvpmsg: You have equiped the PvP kit!
    archermsg: You have equiped the Archer kit!
    elitemsg: You have equiped the Elite kit!
    blazemsg: You have equiped the Blaze kit!
    fishermanmsg: You have equiped the Fisherman kit!
    grandpamsg: You have equiped the Grandpa kit!
    knightmsg: You have equiped the Knight kit!
    scoutmsg: You have equiped the Scout kit!
    snipermsg: You have equiped the Sniper kit!
    switchermsg: You have equiped the Switcher kit!
    tankmsg: You have equiped the Tank kit!
    vikingmsg: You have equiped the Viking kit!
    minermsg: You have equiped the Miner kit!
    sonicmsg: You have equiped the Sonic kit!
    dwarfmsg: You have equiped the Dwarf kit!
    urgalmsg: You have equiped the Urgal kit!
    prefixmsg: MinecraftKits
    cashonkill: 30
    xTrollxDudex
     
  8. Offline

    xTrollxDudex

  9. Offline

    HyrulesLegend

    xTrollxDudex Vault is installed.

    Anyone know why?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page