I make a code, but I'm getting crash on console: The Code: Code:java @EventHandlerpublic void GorduchoKit(PlayerInteractEvent event){final Player player = event.getPlayer();if((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)){ if (event.getItem().getTypeId() == 364){ player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 3)); player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, 1)); player.getInventory().removeItem(new ItemStack[] { new ItemStack(364, 1) }); player.getWorld().playSound(player.getLocation(), Sound.BURP, 2.0F, 1.0F); player.sendMessage(ChatColor.GREEN + ChatColor.BOLD.toString() + "PICANHA!!!!!!"); }}} The Crash: Code: 15:24:50 [SEVERE] Could not pass event PlayerInteractEvent to IervoAbilities v1. 0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:427) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav a:62) at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j ava:477) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j ava:462) at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerInte ractEvent(CraftEventFactory.java:186) at net.minecraft.server.v1_5_R3.PlayerInteractManager.interact(PlayerInt eractManager.java:370) at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java :631) at net.minecraft.server.v1_5_R3.Packet15Place.handle(SourceFile:58) at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292 ) at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java :109) at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35) at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3 0) at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5 81) at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2 26) at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4 77) at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java :410) at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5 73) Caused by: java.lang.NullPointerException at me.Iervolino.IervoAbilities.IervoAbilities.GorduchoKit(IervoAbilities .java:45) at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:425) ... 16 more > Line 45: if (event.getItem().getTypeId() == 364){
I was trying to convey that the player clicking with nothing in their hand will cause event.getItem() to return null.
Well, I didn't understood it so much, but can you rewrite it with the correct way? This will work? Code:java @EventHandlerpublic void GorduchoKit(PlayerInteractEvent event){final Player player = event.getPlayer();if((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) && (player.getItemInHand().getTypeId() == 364)){ player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 3)); player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, 1)); player.getInventory().removeItem(new ItemStack[] { new ItemStack(364, 1) }); player.getWorld().playSound(player.getLocation(), Sound.BURP, 2.0F, 1.0F); player.sendMessage(ChatColor.GREEN + ChatColor.BOLD.toString() + "PICANHA!!!!!!");}} AngryNerd Working now, I fixed it, but I have another problem.. the 364 is the steak, if I have 5 steaks for example and I use one it will be 4 steaks, but there is a bug when I have only 1 steak, If I use this last one, it won't be removed from the inventory.. Do you know how to fix it? EDIT by Moderator: merged posts, please use the edit button instead of double posting.