Reducing Armor Protection

Discussion in 'Plugin Development' started by MistPhizzle, Jul 12, 2014.

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

    MistPhizzle

    Hello, just wondering if it is possible to reduce the amount of protection armor gives you by a factor. IE 1/6 of the protection it would normally give. Haven't been able to figure this out as armor protection varies based on material / enchantments.

    Thanks in advance. (I assume I would need the EntityDamageByEntityEvent)
     
  2. Offline

    RawCode

    get armor of player and add damage back inside ondamage event.
     
  3. Offline

    MrKeals

  4. Offline

    unrealdesign

    I haven't tested this, but this is the only way I can think of to do what you want to do. If you want to calculate the other protection types, you'll have to use the same methods, but check the damage cause and change the epf calculations because they have different multipliers. Also, I just posted the whole thing because I think you know how to code Java and this was easier than explaining it ^.^

    Code:java
    1. /**
    2.  * I am only doing calculations for normal protection. Not feather, fire, blast, or projectile protection.
    3.  * @param e
    4.  */
    5. @EventHandler
    6. public void asdfasd(EntityDamageByEntityEvent e)
    7. {
    8.  
    9. Entity entity = e.getEntity();
    10. if(entity instanceof Player && e.getCause() == DamageCause.ENTITY_ATTACK)
    11. {
    12. double reducedBy = 0.2;
    13. double totalReduction = 0;
    14. double finalReduction = 0;
    15. double finalDamage = 0;
    16. int totalProtectionEPF = 0;
    17.  
    18. Player p = (Player) entity;
    19. ItemStack[] armor = p.getInventory().getArmorContents();
    20. for(ItemStack is : armor)
    21. {
    22. for(Enchantment enchantment : is.getEnchantments().keySet())
    23. {
    24.  
    25. if(enchantment.equals(Enchantment.PROTECTION_ENVIRONMENTAL))
    26. {
    27. int level = is.getEnchantments().get(enchantment);
    28.  
    29. //Calculate the EPF for the item
    30. totalProtectionEPF += (int) Math.floor((6 + level*level) * 0.75 / 3);
    31. }
    32. }
    33. }
    34.  
    35. //If the totalProtectionEPF is 0, then just do the normal event
    36. if(totalProtectionEPF <= 0) return;
    37.  
    38. //Cap at 25
    39. if(totalProtectionEPF > 25) totalProtectionEPF = 25;
    40.  
    41. //Simulate the EPF, you never really know. I don't know how to get this value with bukkit?
    42. int simulatedFinalProtectionEPF = (int) Math.ceil(totalProtectionEPF*((Math.random()*.5) + 0.5));
    43.  
    44. //Cap at 20
    45. if(simulatedFinalProtectionEPF > 20) simulatedFinalProtectionEPF = 20;
    46.  
    47. totalReduction = simulatedFinalProtectionEPF*0.04;
    48. finalReduction = (totalReduction * reducedBy);
    49.  
    50. finalDamage = e.getDamage() * finalReduction;
    51.  
    52. //You have to set the damage to 0 because damage reduction from protection
    53. //is calculated after this event.
    54. e.setDamage(0);
    55. p.damage(finalDamage);
    56. }
    57. }
     
    MistPhizzle likes this.
  5. Offline

    unrealdesign

    MistPhizzle I'm actually curious if my idea was working or if you found your own working solution. It'd be awesome if you could update us!
     
  6. Offline

    fireblast709

  7. Offline

    RawCode

    this done by copypasting 2 lines of core method handling entity damage, just two lines...
     
  8. Offline

    MistPhizzle

    Sorry for the delay (I've been working), I ended up using another Method to nerf armor on my server -- removing it completely. I run a Bending server and armor makes it darn near useless. Thanks everyone for the help though. You guys rock.
     
Thread Status:
Not open for further replies.

Share This Page