Shielding arrows

Discussion in 'Spigot Plugin Development' started by HeroVerseWizard, Jun 5, 2017.

  1. Is it possible to create a shield like a thing which deflects Arrows of players?
     
  2. I mean, you could check if players inventory contains a certain item when an arrow hits them, and if they have the shield item, or have some shield activated, cancel the damage.
     
  3. No like
    I can do that but I want to have a Visual reperesentation of them delfecting it
    like the arrow flies bac
     
  4. If i remember well, if you cancel damage event the arrow will deflected from the player. So you should check if the player holds shields, cancel the event
     
  5. You can make an arrow deflect using this
    Code (Java):
    arrow.setVelocity(arrow.getVelocity().normalize().multiply(-0.1));
     
    • Informative Informative x 2
    • Like Like x 1
  6. TomTheDeveloper

    Supporter

    And maybe its a good idea to create some short of circular shield around the player that lightens up for a few seconds once the arrow deflects. This circular shield can be made visible by some sort of particles.
     
  7. Shield created, but how am i supposed to get an instance of multiple arrows that are being shot towards me
     
  8. TomTheDeveloper

    Supporter

    I haven't messed around with the SpigotAPI in about two years but I think there is a event where you can get the arrow instance from. (Try google) Once you have this instance, save it somewhere in some kind of List. Once the arrow is shot, check every x ticks if the arrow is somewhere close to a player with a shield. If so, deflect the error.

    That's a possible way to do it.