Use guard clause instead of nested if statememt

This commit is contained in:
Tomás F 2020-07-01 20:08:15 +01:00
parent 1f079051fa
commit c73fcba252

View File

@ -41,14 +41,16 @@ public class DamageHandler implements Listener {
Player player = (Player) event.getEntity();
PlayerInventory playerInventory = player.getInventory();
if (Stream.of(playerInventory.getArmorContents()).allMatch(Objects::nonNull)) {
if (playerInventory.getHelmet().isSimilar(helmet.getResult()) &&
playerInventory.getChestplate().isSimilar(chestplate.getResult()) &&
playerInventory.getLeggings().isSimilar(leggings.getResult()) &&
playerInventory.getBoots().isSimilar(boots.getResult())) {
if (!Stream.of(playerInventory.getArmorContents()).allMatch(Objects::nonNull)) {
return;
}
event.setDamage(reduction * event.getDamage());
}
if (playerInventory.getHelmet().isSimilar(helmet.getResult()) &&
playerInventory.getChestplate().isSimilar(chestplate.getResult()) &&
playerInventory.getLeggings().isSimilar(leggings.getResult()) &&
playerInventory.getBoots().isSimilar(boots.getResult())) {
event.setDamage(reduction * event.getDamage());
}
}
}