Arrows That Ignore Armor

Discussion in 'Spigot Plugin Development' started by _Zaboomafoo_, Jun 2, 2015.

  1. Hey all, how would I make a method and constructors for special arrows that when shot ignore armor that the players have on? Such as when a bow is shot at a player it depletes 2 hearts regardless of what armor they have on if they have any armor at all.
  2. Cancel the damage event if the arrow is one of your special ones and just set the players health manually.
    • Like Like x 1
  3. Set the final damage in the EntityDamageByEntityEvent if it's your special arrow.
  4. Even though @DarkSeraphim 's solution would be better than @MrBlobman 's
    DarkSeraphim's one would make sure that if any other plugin cancels the event, it will actually get cancelled.

    The only problem is, that EntityDamageByEntityEvent doesn't have a setFinalDamage ;)

    So if you use MrBlobman's solution,
    I highly suggest to put priority on highest ;)
  5. Just because there is no direct setter doesn't mean you can't achieve it ;). Just set all modifiers to 0 (using setDamage(DamageModifier, double)) except BASE (note: make sure to check isApplicable(DamageModifier) before changing it), then set BASE to the final damage.
    • Like Like x 1
  6. I do it the same way. I first set the DamageModifier of ARMOR to 0 and then the FINAL one to the damage I want to deal.
  7. #7 _Zaboomafoo_, Jun 2, 2015
    Last edited: Jun 2, 2015
  8. It's just been explained to you how to make arrows that ignore armour... If you can't make the code yourself, you shouldn't be doing this.
  9. Pseudocode!

    Code (Text):
    if bow shot by arrow has special enchantment then
        give arrow metadata

    if player hit by arrow with metadata then
        apply solution mentioned above
    • Agree Agree x 2
    • Like Like x 1
  10. Ok thanks for your help
  11. Is the user a player? Also is the class this code is in the main class?
  12. No the user is a player said as a living enity also the code is not in the main class but it is registered in the main class.
    Main Class:

    Enchantment Class:

    Also how could I make the living entity a player rather than a living entity for my user but the only thing is that the API needs a living entity rather than a player.
  13. What do you mean by this I am kind of a newbie at minecraft coding. In the API you must register the enchantments in the main class and that is what I have done.
  14. Where do you use this function "applyEffect" ?

    or is it something from the API itself?
  15. It is in the API itself.
  16. Try shooting the player up in the air 1 tick later.
  17. Completely untested but should be similar

    public void onArrowHit(EntitityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Player) {
    if (e.getDamager() instanceof Arrow) {
    Player p = (Player)e.getEntity();
    p.setHealth(e.getHealth() - 4);
  18. The issue is that you try to casy your LiftEnchantment class to Plugin, while it does not extend Plugin.

    Pass the plugin instance through the constructor (assuming you create the instance in the main class, or any class which has that reference), and store it in a field. Then use that field instead of ((Plugin) this).