Solved Disable Protection Enchantment/damage

Discussion in 'Plugin Development' started by gabrielmaennl555, Sep 16, 2015.

Thread Status:
Not open for further replies.
  1. Hello, I was wondering how I could disable the protection enchantment, well, not compleatly disable it but just so when someone gets damaged, it dosnt read the protection, Let me show you what Im trying to do,
    Code:
    @EventHandler
        public void damage(EntityDamageEvent e)
        {
            if(e.getEntity() instanceof Player)
            {
                Player p = (Player) e.getEntity();
                SPPlayer sp = PHandler.getPlayer(p);
                double dmg = e.getDamage();
                e.setDamage(0);
                //damage fixer
                p.damage(dmg);
            }
        }
    Notice Im completely ignoring armour in this code, yet it doesn't ignore the protection enchantment ingame, how could I make it ignore the protection enchantment? Thanks!
     
  2. Offline

    teej107

  3. Offline

    gabizou

    Yeah... no... that's not even close to it, because you're ignoring all sorts of cases, such as absorption, armor in general, and potion effects and others.

    Unfortunately, there's a lot of functions that take place in a specific order to arrive at the total damage to deal to the entity, Bukkit partially represents this with DamageModifiers, but it stops short of exposing the peculiarities of the modifiers (like in the case of specific Protection enchantments), so a blanket coverall is required.

    Put it simply: you can set the DamageModifier.MAGIC to 0 with the following:

    Code:
    public void (EntityDamageEvent event) {
      if (event.isApplicable(DamageModifier.MAGIC)) {
        event.setDamage(DamageModifier.MAGIC, 0);
      }
    }
    
     
    0ct0berBkkitPlgins likes this.
  4. @teej107 that would require calculating a ton of things- strength, armor, resistance, etc. in order for it to be accurate. Gazibou's method is better
     
  5. @gabizou Not sure what I did wrong, but it didnt work for me, but dont warry I had another solution, that was to remove the protection enchantment entirely but replace it with a fake enchantment with a fake glow, although the lore amount is used to depleat some damage, thanks anyway!
     
  6. Offline

    boomboompower

    Can you please mark this thead as Solved if your issue is fixed.
     
Thread Status:
Not open for further replies.

Share This Page