Issues with dropping items

Discussion in 'Plugin Development' started by achap1989, Oct 28, 2013.

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

    achap1989

    Ok so, I am attempting to drop only the items in the hotbar on death. Everything runs fine with no errors. However upon death it still drops all items.

    What am I doing wrong?
    My code
    Code:java
    1. package achap1989.hotbardrop;
    2. package achap1989.hotbardrop;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.PlayerDeathEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class HotBarDrop extends JavaPlugin implements Listener {
    11.  
    12. @EventHandler
    13. public void onPlayerDeath(PlayerDeathEvent e) {
    14. e.getDrops().clear();
    15.  
    16. Player p = e.getEntity();
    17. for(int i = 0; i <=8; i++){
    18. p.getWorld().dropItemNaturally(p.getLocation(), p.getInventory().getItem(i));
    19. }
    20.  
    21. }
    22. }
    23.  
     
  2. Offline

    mydeblob

    Well, I Can tell you right now you don't even have your event registered.
     
  3. Offline

    achap1989

    mydeblob , even when I register the event it still drops every item. Am I registering it wrong?

    Added Code
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);


    Complete Code
    Code:java
    1. package achap1989.hotbardrop;
    2. package achap1989.hotbardrop;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.PlayerDeathEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class HotBarDrop extends JavaPlugin implements Listener {
    11.  
    12. @EventHandler
    13. public void onPlayerDeath(PlayerDeathEvent e) {
    14. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    15. e.getDrops().clear();
    16.  
    17. Player p = e.getEntity();
    18. for(int i = 0; i <=8; i++){
    19. p.getWorld().dropItemNaturally(p.getLocation(), p.getInventory().getItem(i));
    20. }
    21.  
    22. }
    23. }
    24.  
     
  4. Offline

    mydeblob

    achap1989
    You aren't registering it in the correct location. It needs to be registered in your onEnable.
    Example Code
    Code:java
    1. package achap1989.hotbardrop;
    2. package achap1989.hotbardrop;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.PlayerDeathEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class HotBarDrop extends JavaPlugin implements Listener {
    11. public void onEnable(){
    12. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    13. }
    14. @EventHandler
    15. public void onPlayerDeath(PlayerDeathEvent e) {
    16. e.getDrops().clear();
    17.  
    18. Player p = e.getEntity();
    19. for(int i = 0; i <=8; i++){
    20. p.getWorld().dropItemNaturally(p.getLocation(), p.getInventory().getItem(i));
    21. }
    22.  
    23. }
    24. }
     
  5. Offline

    Garris0n

  6. Offline

    achap1989

    It simply errors out on my death I mean you are helping and getting me somewhere however being new to this kind of screws me xD Sorry to have to ask again but what on earth am I still doing wrong?
    Show Spoiler

    12:39:07 [SEVERE] Could not pass event PlayerDeathEvent to Hot Bar Drop v0.1
    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_6_R3.event.CraftEventFactory.callPlayerDeat
    hEvent(CraftEventFactory.java:344)
    at net.minecraft.server.v1_6_R3.EntityPlayer.die(EntityPlayer.java:312)
    at net.minecraft.server.v1_6_R3.EntityLiving.damageEntity(EntityLiving.j
    ava:710)
    at net.minecraft.server.v1_6_R3.EntityHuman.damageEntity(EntityHuman.jav
    a:714)
    at net.minecraft.server.v1_6_R3.EntityPlayer.damageEntity(EntityPlayer.j
    ava:383)
    at net.minecraft.server.v1_6_R3.EntityMonster.m(EntityMonster.java:79)
    at net.minecraft.server.v1_6_R3.EntityZombie.m(EntityZombie.java:189)
    at net.minecraft.server.v1_6_R3.PathfinderGoalMeleeAttack.e(PathfinderGo
    alMeleeAttack.java:85)
    at net.minecraft.server.v1_6_R3.PathfinderGoalSelector.a(PathfinderGoalS
    elector.java:104)
    at net.minecraft.server.v1_6_R3.EntityInsentient.bi(EntityInsentient.jav
    a:419)
    at net.minecraft.server.v1_6_R3.EntityLiving.c(EntityLiving.java:1414)
    at net.minecraft.server.v1_6_R3.EntityInsentient.c(EntityInsentient.java
    :306)
    at net.minecraft.server.v1_6_R3.EntityMonster.c(EntityMonster.java:20)
    at net.minecraft.server.v1_6_R3.EntityZombie.c(EntityZombie.java:123)
    at net.minecraft.server.v1_6_R3.EntityLiving.l_(EntityLiving.java:1277)
    at net.minecraft.server.v1_6_R3.EntityInsentient.l_(EntityInsentient.jav
    a:150)
    at net.minecraft.server.v1_6_R3.EntityMonster.l_(EntityMonster.java:24)
    at net.minecraft.server.v1_6_R3.EntityZombie.l_(EntityZombie.java:185)
    at net.minecraft.server.v1_6_R3.World.entityJoinedWorld(World.java:1354)

    at net.minecraft.server.v1_6_R3.World.playerJoinedWorld(World.java:1335)

    at net.minecraft.server.v1_6_R3.World.tickEntities(World.java:1223)
    at net.minecraft.server.v1_6_R3.WorldServer.tickEntities(WorldServer.jav
    a:480)
    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    74)
    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.IllegalArgumentException: Cannot drop a Null item.
    at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    at org.bukkit.craftbukkit.v1_6_R3.CraftWorld.dropItem(CraftWorld.java:29
    4)
    at org.bukkit.craftbukkit.v1_6_R3.CraftWorld.dropItemNaturally(CraftWorl
    d.java:312)
    at achap1989.hotbardrop.HotBarDrop.onPlayerDeath(HotBarDrop.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.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)
    ... 30 more
     
  7. Offline

    mydeblob

    achap1989
    You need to check if the player is holding nothing in their hotbar. Just do a simple if loop checking if the hotbar has any null, or spots that have nothing, in it. And if it does, do nothing.
     
Thread Status:
Not open for further replies.

Share This Page