Help

Discussion in 'Plugin Development' started by Iervolino, Jun 26, 2013.

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

    Iervolino

    I make a code, but I'm getting crash on console:

    The Code:

    Code:java
    1. @EventHandler
    2. public void GorduchoKit(PlayerInteractEvent event){
    3. final Player player = event.getPlayer();
    4. if((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)){
    5. if (event.getItem().getTypeId() == 364){
    6. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 3));
    7. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, 1));
    8. player.getInventory().removeItem(new ItemStack[] { new ItemStack(364, 1) });
    9. player.getWorld().playSound(player.getLocation(), Sound.BURP, 2.0F, 1.0F);
    10. player.sendMessage(ChatColor.GREEN + ChatColor.BOLD.toString() + "PICANHA!!!!!!");
    11. }
    12. }
    13. }


    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){
     
  2. Offline

    caseif

    What will event.getItem() return if the player has nothing in their hand?
     
  3. Offline

    Iervolino


    Lol, what I understood about it is: if the player have a 364 in your hand add the effects...
     
  4. Offline

    caseif

    I was trying to convey that the player clicking with nothing in their hand will cause event.getItem() to return null.
     
  5. Offline

    Iervolino


    Well, I didn't understood it so much, but can you rewrite it with the correct way?

    This will work?

    Code:java
    1. @EventHandler
    2. public void GorduchoKit(PlayerInteractEvent event){
    3. final Player player = event.getPlayer();
    4. if((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) && (player.getItemInHand().getTypeId() == 364)){
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 3));
    6. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, 1));
    7. player.getInventory().removeItem(new ItemStack[] { new ItemStack(364, 1) });
    8. player.getWorld().playSound(player.getLocation(), Sound.BURP, 2.0F, 1.0F);
    9. player.sendMessage(ChatColor.GREEN + ChatColor.BOLD.toString() + "PICANHA!!!!!!");
    10. }
    11. }


    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.
     
    Last edited by a moderator: Jun 2, 2016
  6. Offline

    Iervolino

    Bump...
     
Thread Status:
Not open for further replies.

Share This Page