Advanced NoDrop

Discussion in 'Plugin Development' started by Iervolino, May 21, 2013.

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

    Iervolino

    My currently nodrop:

    Code:
    @EventHandler
    public void onItemDrop(ItemSpawnEvent event){
      if (isEnabled())
      event.setCancelled(true);
    }
    I don't have idea on how to do, but I want a nodrop that the items go to ground but is not possible get it and after 3 secounds the item disappear.

    If a player die or drop a item, these items go to ground normally but the players can't get it and after 3 secounds these items disappear.

    Can someone make this code or a pseudo for me? if yes thanks very much!
     
  2. Offline

    Tux2

    Register on the onItemPickup event and cancel the event for the specific item stacks.
     
  3. Offline

    Iervolino

    Tux2

    Can you please make a pseudo? And if you can add the 3 secounds of item on ground too.

    Thanks!

    Tux2 Technius

    What is wrong with the code? I put 60 for 3 secounds but not worked...

    Code:
    @EventHandler
    public void onPlayerDropItem(PlayerDropItemEvent event)
    {
        Integer time = (60);
        if (time != null)
        {
          final Item itm = event.getItemDrop();
          Bukkit.getScheduler().runTaskLater(this, new Runnable()
          {
            public void run()
            {
              if ((itm != null) && (!itm.isDead()))
              {
                itm.remove();
              }
            }
          }
          , time.intValue() / 40);
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    LucasEmanuel

    Why do you divide by 40? Remove it and it should be fine.
     
    Iervolino likes this.
  5. Offline

    Iervolino

    When I remove the time.invValue() / 40); I get error on the runTaskLater
     
  6. Offline

    LucasEmanuel

    Dont remove the entire line, just remove the part where you divide by 40, like this:
    Code:
      }
      , time.intValue() / 40);
    }
    becomes
    Code:
      }
      , time.intValue());
    }
    Also, the time has to be a long.
     
    Iervolino likes this.
  7. Offline

    Iervolino

    Works pretty well thanks! Also I'm brazilian too!

    Also I have a problem: I would like to when a player get killed the items be removed on the same time too, but it is not working.

    LucasEmanuel

    I do this code but getting error on the 9 line:

    - Type safety: The constructor ArrayList(Collection) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be
    parameterized
    - ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
    - List is a raw type. References to generic type List<E> should be parameterized

    Code:
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event)
    {
      Integer time = (80);
     
      if (time != null)
      {
        World w = event.getEntity().getWorld();
        List iss = new ArrayList(event.getDrops());
     
        event.getDrops().clear();
        final Item[] items = new Item[iss.size()];
     
        for (int i = 0; i < iss.size(); i++)
        {
          items[i] = w.dropItemNaturally(event.getEntity().getLocation(), (ItemStack)iss.get(i));
        }
     
        Bukkit.getScheduler().runTaskLater(this, new Runnable()
        {
          public void run()
          {
            for (Item itm : items)
            {
              if ((itm != null) && (!itm.isDead()))
              {
                itm.remove();
              }
            }
          }
        }
        , time.intValue());
      }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  8. Offline

    LucasEmanuel

    Iervolino
    Change this line:
    Code:
    List iss = new ArrayList(event.getDrops());
    to
    Code:
    List iss = event.getDrops();
     
  9. Offline

    Iervolino

    Change and getting this warn on List:
    List is a raw type. References to generic type List<E> should be parameterized
     
  10. Offline

    LucasEmanuel

    Oh, yea, change it to List<ItemStack> iss = event.getDrops();
     
  11. Offline

    Iervolino

    Not worked, getting bug when the player die!
     
  12. Offline

    Iervolino

    LucasEmanuel this not work.. When the player die the items aren't dropped!
     
  13. Offline

    LucasEmanuel

    Can I see your code?

    EDIT:
    It's because you clear the droplist.

    EDIT2:
    If you wanna stop players from dropping items when they die do this instead of what you have above:
    Code:
    public void onPlayerDeath(PlayerDeathEvent event) {
      if(isEnabled()) {
        event.getDrops().clear();
      }
    }
     
  14. Offline

    Iervolino

    I want the deathdrop enabled, but It get removed from the ground in 3 secounds...

    Code:
    @SuppressWarnings("rawtypes")
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event)
    {
      Integer time = (60);
     
      if (time != null)
      {
        World w = event.getEntity().getWorld();
        @SuppressWarnings("unchecked")
        List iss = new ArrayList(event.getDrops());
     
        event.getDrops().clear();
        final Item[] items = new Item[iss.size()];
     
        for (int i = 0; i < iss.size(); i++)
        {
          items[i] = w.dropItemNaturally(event.getEntity().getLocation(), (ItemStack)iss.get(i));
        }
     
        Bukkit.getScheduler().runTaskLater(this, new Runnable()
        {
          public void run()
          {
            for (Item itm : items)
            {
              if ((itm != null) && (!itm.isDead()))
              {
                itm.remove();
              }
            }
          }
        }
        , time.intValue());
      }
    }
     
  15. Offline

    LucasEmanuel

    Iervolino Well you are scheduling a task to remove the drops after 3 seconds.
     
Thread Status:
Not open for further replies.

Share This Page