Taking item from itemframe straight to my inventory

Discussion in 'Plugin Development' started by Etsijä, Apr 7, 2014.

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

    Etsijä

    I'm developing this private capture the flag plugin for our server, and it is working quite well already. We are using named netherstars in itemframes at the base, to work as the team flag which the other team tries to steal.

    The annoying thing is when a user hits the itemframe, the nether star flies randomly somewhere to the ground, making it very difficult to collect and steal without getting killed...so I'm looking for a way to prevent the netherstar from falling when the itemframe that contais it is left-clicked. A better way would be that the item gets removed from the itemframe and put straight into the player's inventory.

    Any suggestions as to how to implement this?
     
  2. Offline

    Code0

    I can't help you that well, but since you're already pretty experienced, I could tell how you would most likely do it. You could write an event (method) that checks for left clicks on item frames. If that happens you get the player that left clicked it, and give him the star. Then you'd just kill the drop out of the frame.
     
  3. Offline

    Etsijä

    Yes, that makes sense. The only thing I don't know is how to kill the drop...there is a setItem() method on ItemFrame class, and I guess I can just change it to Air, but do I need also somehow to cancel the left-clicking? Otherwise, I would imagine the item vanishes from the itemframe but is still dropped somewhere, in effect creating two netherstars, one on player's inventory and another one lying on the ground.
     
  4. Offline

    Zethariel

    Hook into the OnItemSpawnEvent (or similar) and cancel it if it is a nether star
     
    Benlewis9000 likes this.
  5. Offline

    Etsijä

    Ah, that's helpful, thanks Zethariel.
     
Thread Status:
Not open for further replies.

Share This Page