Cannot stop error code.

Discussion in 'Plugin Development' started by CrazyGuy3000, Nov 2, 2013.

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

    CrazyGuy3000

    Hi there Bukkit!
    I am coding a plugin called Skycraft and i'm getting this error,
    Code:java
    1. 08:50:08 [SEVERE] Could not pass event PlayerMoveEvent to Skycraft-Main v0.1
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    4. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    5. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    6. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    7. at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:227)
    8. at net.minecraft.server.v1_6_R3.Packet10Flying.handle(SourceFile:136)
    9. at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    10. at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    11. at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    12. at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    13. at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    14. at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    15. at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    16. at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    17. at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    18. Caused by: java.lang.NullPointerException
    19. at me.Twipply.SkyCraft.SkyCraft.onPlayerMove(SkyCraft.java:84)
    20. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    21. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    22. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    23. at java.lang.reflect.Method.invoke(Method.java:597)
    24. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    25. ... 14 more


    and then the code I am using is
    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent event) {
    3. Player player = event.getPlayer();
    4. if(player.getInventory().getBoots().getType() == Material.CHAINMAIL_BOOTS){
    5. ItemStack boots = player.getInventory().getBoots();
    6. ItemMeta bootsmeta = boots.getItemMeta();
    7. bootsmeta.setDisplayName(ChatColor.AQUA + "Angelic Boots");
    8. boots.setItemMeta(bootsmeta);
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 160, 1));
    10. }
    11. }


    now the code actually does work but it keeps running errors...

    Line 84 is
    Code:java
    1.  
    2. if(player.getInventory().getBoots().getType() == Material.CHAINMAIL_BOOTS){
     
  2. Offline

    Assist

    CrazyGuy3000
    Now what would happen if the player isn't wearing any boots, and you try to check their type? NullPointerException. Before checking the type, make sure they're not null.
     
  3. Offline

    CrazyGuy3000

    Assist
    Thanks, sorry can't believe I didn't think to check that, will have to remember that in future!
     
Thread Status:
Not open for further replies.

Share This Page