ItemDropEvent

Discussion in 'Plugin Development' started by Hellborn5456, Aug 7, 2014.

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

    Hellborn5456

    Hello! :)
    I ran into a few problems, and it seems that i cannot fix it.
    The problem is that it still drops even thoe its at -1 or 0 durability!
    Code:java
    1. @EventHandler
    2. public void Revoler2(PlayerDropItemEvent e){
    3. if(e.getItemDrop().getItemStack().getType().equals(Material.WOOD_SPADE)){
    4. ItemStack i = new ItemStack(Material.WOOD_SPADE);
    5. if(i.getDurability() <= 0){
    6. e.setCancelled(true);
    7. }else{
    8. e.setCancelled(false);
    9. }
    10. }
    11. }
    12.  


    Edit: I register my events :)
     
  2. Offline

    _Filip

    1. You don't have to set the event cancellation to false.
    2. You check the durability of a brand new item. This will ALWAYS return the the item's full durability.
    3. Just a general recommendation, use == when comparing Enums.
     
  3. Offline

    Hellborn5456

    TheSpherret
    Still does not work. :(
    Code:java
    1.  
    2. @EventHandler
    3. public void Revoler2(PlayerDropItemEvent e){
    4. if(e.getItemDrop().getItemStack().getType().equals(Material.WOOD_SPADE)){
    5. Player p = e.getPlayer();
    6. ItemStack i = p.getInventory().getItemInHand();
    7. if(i.getDurability() == -1){
    8. e.setCancelled(true);
    9. }else{
    10. }
    11. }
    12. }
     
  4. Offline

    Forseth11

    In minecraft the durability starts at 0 then goes up. Each item has a different breaking point. This means you need to put in the max durability and check for that.
     
  5. Offline

    Hellborn5456

    Bump.
    Still need help.
    Code:java
    1.  
    2. @EventHandler
    3. public void Revoler2(PlayerDropItemEvent e){
    4. if(e.getItemDrop().getItemStack().getType().equals(Material.WOOD_SPADE)){
    5. Player p = e.getPlayer();
    6. ItemStack i = p.getInventory().getItemInHand();
    7. if(i.getDurability() == 59) {
    8. p.sendMessage("drop");
    9. }else{
    10. e.setCancelled(true);
    11. }
    12. }
    13. }
     
  6. Offline

    xTigerRebornx

    Hellborn5456 You haven't said your problem, not sure how you expect help.
    Anyway, you are checking the durability of the ItemStack in the Player's hand, not the one they dropped.
     
  7. Offline

    Hellborn5456

    xTigerRebornx
    I'm still not getting it.
    I'm checking for the item drop, which is a wooden spade, then im checking for the durability. but it still doenst drop.
    Code:java
    1.  
    2. @EventHandler
    3. public void Revoler2(PlayerDropItemEvent e){
    4. if(e.getItemDrop().getItemStack().getType().equals(Material.WOOD_SPADE)){
    5. Player p = e.getPlayer();
    6. ItemStack i = e.getItemDrop().getItemStack();
    7. if(i.equals(Material.WOOD_SPADE)){
    8. if(i.getDurability() == 59){
    9.  
    10. }else{
    11. e.setCancelled(true);
    12. }
    13. }
    14. }
    15. }
     
  8. Offline

    Hellborn5456

  9. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page