Skip to content

Commit

Permalink
Fixed condition setting incorrect effect values
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Feb 21, 2021
1 parent 87b024c commit 067d810
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 067d810

Please sign in to comment.