Get Arrow from Stack Fired

Discussion in 'Plugin Development' started by CoderMusgrove, Mar 23, 2014.

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

    CoderMusgrove

    I'm using a ProjectileLaunchEvent currently, and what I want to do is get the Arrow, or other entity such as a Snowball, and see what itemstack it came from. How would I accomplish this? I need to do this to make sure it's the one with the right item lore.

    I could try cancelling the event then seeing if their inventory contains the item with the certain lore, but when a player shoots a bow, there's no way to calculate how charged the bow was, or is there?

    Sorry for being so bleak, but thank you everyone who are going to try to help. :p
     
  2. Offline

    Noxyro

    There is no direct way to get the ItemStack from the ProjectileLaunchEvent here.
    You need to create a workaround:

    1) Save the data and type of the projectile somewhere.
    2) Cancel the event.
    3) Check the inventory of the shooter for the given type of projectile (only if it's a player of course).
    4) Get the (first) ItemStack that matches the given projectile type.
    5) Remove one from that stack manually => here you know exactly which ItemStack was used.
    6) Create a new ProjectileLaunchEvent with the same data as before (same direction and type).

    Hope this helps.
     
Thread Status:
Not open for further replies.

Share This Page