Event for non-player dropped items?

Discussion in 'Plugin Development' started by agodwin987, Mar 24, 2013.

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

    agodwin987

    I have the code:
    Code:
    @EventHandler
        public void drop(final PlayerDropItemEvent e){
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                @Override
                public void run() {
                    World w = e.getPlayer().getWorld();
                    Location loc = e.getItemDrop().getLocation();
                    w.createExplosion(loc, 1);
                }
             
            }, 60L);
        }
    The issue is this wont work for the dropped item because: 1 it's the players location, 2 it wont work for items that are dropped with the code :
    Code:
    Item dropped = p.getWorld().dropItem(loc, new ItemStack(Material.SLIME_BALL,1));
    dropped.setVelocity(p.getLocation().getDirection().add(dropped.getVelocity().setX(dropped.getVelocity().getX())).add(dropped.getVelocity().setZ(dropped.getVelocity().getZ())));
     
  2. Try storing the item entity before the task as final and then get its location in the task.

    But why do you need an event for that code ?!
    If it's in your code you just call a method after that code to trigger whatever stuff you need.
    If it's called in another plugin then that plugin should provide custom events.
     
  3. Offline

    agodwin987

    The way I have it set up is the slimeball is spawned on right click, and I need to find where it hits the ground to spawn an explosion, like a grenade
     
  4. Offline

    jbman223

    Hey, this is an interesting problem. Hope somebody can offer you a solution. I suggest using tasks and maps but that is just my suggestion.
     
Thread Status:
Not open for further replies.

Share This Page