Check for drops

Discussion in 'Plugin Development' started by Blacky372, Aug 22, 2011.

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

    Blacky372

    How i can check a Block/Location for drops and get them?
    Like this: [​IMG]
    -
    Blacky372
     
  2. Offline

    Darkman2412

    One of the following codes needs to be in your PlayerListener

    Long:
    Code:java
    1. public void onPlayerDropItem(PlayerDropItemEvent event){
    2. Item item = event.getItemDrop(); // The item
    3. int locx = item.getLocation().getBlockX(); // Rounding
    4. int locy = item.getLocation().getBlockY(); // " "
    5. int locz = item.getLocation().getBlockZ(); // " "
    6. Location loc = new Location(locx, locy, locz); // The Location
    7. }


    Short:
    Code:java
    1. public void onPlayerDropItem(PlayerDropItemEvent event){
    2. Item item = event.getItemDrop(); // The item
    3. Location loc = new Location(int locx = item.getLocation().getBlockX(),int locx = item.getLocation().getBlockY(), int locx = item.getLocation().getBlockZ()); // The Location
    4. }
     
  3. Offline

    Blacky372

    No, i want to chech a Location for Drops.
    I dont want to log the drops.
    like this:
    Code:
    Location loc = new Location(12,64,12);
    DropList drops = loc.getAllDrops();
    if(drops.get(0).getTypeId() == 5){
    [...]
    }
    
    Nobody knows?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Offline

    ItsHarry

    Like darkman2412 said, you could use the onPlayerDropItem event.
    See this line: ?
    Code:
    Item item = event.getItemDrop(); // The item
    Use it to create an if statement:
    if (item.getBlah == blahblah) {
    doBlah();
    }
     
  5. Offline

    Crash

    Try this method I made up :
    Code:
        public List<Item> getItemsAt(Location loc){
    
            List<Item> entities = new ArrayList<Item>();
    
            if(loc == null)
                return entities;
    
            for(Entity e : loc.getBlock().getChunk().getEntities()){
    
                if(e instanceof Item){
    
                    Location blockloc = ((Item) e).getLocation().getBlock().getLocation();
                    if(blockloc.equals(loc))
                        entities.add((Item)e);
    
                }
    
            }
    
            return entities;
    
        }
    The location parameter must be a block location (eg 26, 75, 47 not 26.4473, 75.852, 47.122)
     
  6. Offline

    Blacky372

    Thanks a lot!
    I'll try it tomorrow.

    -
    Blacky372
     
Thread Status:
Not open for further replies.

Share This Page