Detecting when a player drops an items on a pressure plate

Discussion in 'Plugin Development' started by Suprem20, Sep 2, 2011.

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

    Suprem20

    For now, I have a working method. But because the DropItemEvent is sent to the plugin immediately when a player drops an item, I am using the bukkit scheduler to get the item 15 ticks after the drop. I was wondering if using a delay task every time the item is dropped has any effects on the server performance. Also, I tried using a BlockPhysicsEvent to detect a pressure plate when it activates, only problem is that I don't know how to get the entity above it. Any ideas?

    Thank you.
     
  2. Offline

    Adamki11s

    I think you can get the location the item was dropped and check to see if the block is a pressure plate.
     
  3. Offline

    DDoS

    It won't work Adam, the OnItemDrop event is directly after an item drop, which means the player would need to be on top of the pressure plate when he drops.
     
  4. Offline

    Adamki11s

    Ah ok. Maybe you could write an algorithm which takes their pitch and yaw and calculates the block it'll drop on.
     
  5. Offline

    Suprem20

    Yes, but what if the item hits a wall? How am I suppose to calculate the landing then? Plus I need would need to get the height of the pressure plate if i want to get the x and z coords.
     
  6. Offline

    Ryo

    make a temporary Location variable that holds the item's Location as soon as its dropped. Set into a for loop for when the location stops changing (meaning it has landed). Get that Location and check if in that location there is also a pressure plate...

    That's something you could try, I've done something similar but not exactly this so I'm not 100% it will work, but it's worth a try if you're stomped.
     
  7. Offline

    Drei Gyuu

    Any news on this?
     
  8. Offline

    adamjon858

    Here's how I would do it:

    Whenever an item is dropped, put it into a list
    Have your plugin run a thread every 10 ticks that goes through every item in the list. If the item is still falling keep it in the list, if it's stopped falling check if it's on a pressure plate. If it's on a pressure plate...do whatever you want. After the check, remove all the items that have stopped falling from the list.

    Much more efficient for a large number of users vs. a single thread for each item dropping. You're still doing a lot of looping but that's inevitable for any type of event based system. This way, all the looping is consolidated in a single place.
     
Thread Status:
Not open for further replies.

Share This Page