diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java index 936fe1c..c3e8f07 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java @@ -1,6 +1,9 @@ package com.willfp.ecoarmor.conditions; import com.willfp.ecoarmor.EcoArmorPlugin; +import com.willfp.ecoarmor.effects.Effect; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; import lombok.AccessLevel; import lombok.Getter; import org.bukkit.entity.Player; @@ -54,4 +57,29 @@ public final boolean isMet(@NotNull final Player player, protected abstract boolean isConditionMet(@NotNull Player player, @NotNull T value); + + protected final void evaluateEffects(@NotNull final Player player, + @NotNull final T value, + @NotNull final ArmorSet set) { + this.getPlugin().getScheduler().runLater(() -> { + if (isMet(player, value)) { + for (Effect effect : set.getEffects().keySet()) { + Object strength = set.getEffectStrength(effect); + + if (ArmorUtils.isWearingAdvanced(player)) { + Object advancedStrength = set.getAdvancedEffectStrength(effect); + if (advancedStrength != null) { + strength = advancedStrength; + } + } + + if (strength != null) { + effect.enable(player, strength); + } + } + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + }, 1); + } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java index 45cfc76..290c577 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java @@ -39,13 +39,7 @@ public void listener(@NotNull final EntityRegainHealthEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @EventHandler( @@ -71,13 +65,7 @@ public void listener(@NotNull final EntityDamageEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java index c467ed6..2dbe30e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java @@ -33,13 +33,7 @@ public void listener(@NotNull final PlayerExpChangeEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java index 4994e37..cb08efb 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java @@ -33,13 +33,7 @@ public void listener(@NotNull final PlayerMoveEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java index 48bfc45..3b22e9a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java @@ -39,13 +39,7 @@ public void listener(@NotNull final EntityRegainHealthEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @EventHandler( @@ -71,11 +65,7 @@ public void listener(@NotNull final EntityDamageEvent event) { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java index d2d8041..eb0eaf2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java @@ -33,13 +33,7 @@ public void listener(@NotNull final PlayerExpChangeEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java index da716a4..afd9c5f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java @@ -33,13 +33,7 @@ public void listener(@NotNull final PlayerMoveEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java index 65a2d33..b6fe023 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java @@ -34,13 +34,7 @@ public void listener(@NotNull final PlayerMoveEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java index 5a44908..c41ca3e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java @@ -37,13 +37,7 @@ public void listener(@NotNull final PlayerMoveEvent event) { return; } - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } - }, 1); + evaluateEffects(player, value, set); } @Override