From a19c5adc9504b0ebd3189531a01f5ca256b5222b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 19:22:10 +0000 Subject: [PATCH 01/13] Fixed SpeedMultiplier being spelled incorrectly --- .../src/main/java/com/willfp/ecoarmor/effects/Effects.java | 4 ++-- .../effects/{SpeedMutiplier.java => SpeedMultiplier.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/{SpeedMutiplier.java => SpeedMultiplier.java} (94%) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java index f5dc636..606c28b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java @@ -15,7 +15,7 @@ import com.willfp.ecoarmor.effects.effects.Flight; import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier; import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier; import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier; -import com.willfp.ecoarmor.effects.effects.SpeedMutiplier; +import com.willfp.ecoarmor.effects.effects.SpeedMultiplier; import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier; import com.willfp.ecoarmor.effects.effects.WarpChance; import lombok.experimental.UtilityClass; @@ -39,7 +39,7 @@ public class Effects { public static final Effect MELEE_DAMAGE_MULTIPLIER = new MeleeDamageMultiplier(); public static final Effect TRIDENT_DAMAGE_MULTIPLIER = new TridentDamageMultiplier(); public static final Effect BONUS_HEARTS = new BonusHearts(); - public static final Effect SPEED_MULTIPLIER = new SpeedMutiplier(); + public static final Effect SPEED_MULTIPLIER = new SpeedMultiplier(); public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier(); public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier(); public static final Effect WARP_CHANCE = new WarpChance(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMutiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java similarity index 94% rename from eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMutiplier.java rename to eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java index 1a3a162..127a872 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMutiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java @@ -10,8 +10,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; -public class SpeedMutiplier extends Effect { - public SpeedMutiplier() { +public class SpeedMultiplier extends Effect { + public SpeedMultiplier() { super("speed-multiplier", Double.class); } From fc1f67fcd281616ad5efa140a98bee032fb25d84 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 20:58:05 +0000 Subject: [PATCH 02/13] Started adding conditions --- config/checkstyle/suppression.xml | 3 + .../com/willfp/ecoarmor/EcoArmorPlugin.java | 4 +- .../willfp/ecoarmor/conditions/Condition.java | 57 +++++++++++++++ .../ecoarmor/conditions/Conditions.java | 50 +++++++++++++ .../conditions/ConditionBelowY.java | 44 ++++++++++++ .../com/willfp/ecoarmor/effects/Effect.java | 55 +++++++++++++++ .../effects/effects/SpeedMultiplier.java | 37 +++++----- .../ecoarmor/effects/util/EffectWatcher.java | 60 ++++++++++++++++ .../com/willfp/ecoarmor/sets/ArmorSet.java | 28 ++++++++ .../willfp/ecoarmor/sets/util/ArmorUtils.java | 70 ++++++++++++++++++- .../src/main/resources/sets/young.yml | 2 + 11 files changed, 391 insertions(+), 19 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java diff --git a/config/checkstyle/suppression.xml b/config/checkstyle/suppression.xml index c460957..5d0bdaa 100644 --- a/config/checkstyle/suppression.xml +++ b/config/checkstyle/suppression.xml @@ -8,7 +8,10 @@ + + + \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java index 3d8006b..c0596c1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java @@ -11,6 +11,7 @@ import com.willfp.ecoarmor.commands.TabcompleterEagive; import com.willfp.ecoarmor.display.ArmorDisplay; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.effects.Effects; +import com.willfp.ecoarmor.effects.util.EffectWatcher; import com.willfp.ecoarmor.sets.ArmorSets; import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener; import com.willfp.ecoarmor.sets.util.PotionEffectListener; @@ -139,7 +140,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin { new AdvancementShardListener(this), new PotionEffectListener(this), new EffectiveDurabilityListener(this), - new DiscoverRecipeListener(this) + new DiscoverRecipeListener(this), + new EffectWatcher(this) ); } 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 new file mode 100644 index 0000000..936fe1c --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java @@ -0,0 +1,57 @@ +package com.willfp.ecoarmor.conditions; + +import com.willfp.ecoarmor.EcoArmorPlugin; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +public abstract class Condition implements Listener { + /** + * Instance of EcoArmor. + */ + @Getter(AccessLevel.PROTECTED) + private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance(); + + /** + * The name of the effect. + */ + @Getter + private final String name; + + /** + * The class of the config getter type. + */ + @Getter + private final Class typeClass; + + /** + * Create a new condition. + * + * @param name The condition name. + * @param typeClass The class of the config type. + */ + protected Condition(@NotNull final String name, + @NotNull final Class typeClass) { + this.name = name; + this.typeClass = typeClass; + + Conditions.addNewCondition(this); + } + + /** + * Get if condition is met for a player. + * + * @param player The player. + * @param value The value of the condition. + * @return If met. + */ + public final boolean isMet(@NotNull final Player player, + @NotNull final Object value) { + return isConditionMet(player, typeClass.cast(value)); + } + + protected abstract boolean isConditionMet(@NotNull Player player, + @NotNull T value); +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java new file mode 100644 index 0000000..0d22f0d --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java @@ -0,0 +1,50 @@ +package com.willfp.ecoarmor.conditions; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.ImmutableList; +import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY; +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@UtilityClass +@SuppressWarnings("unused") +public class Conditions { + /** + * All registered effects. + */ + private static final BiMap> BY_NAME = HashBiMap.create(); + + public static final Condition BELOW_Y = new ConditionBelowY(); + + /** + * Get condition matching name. + * + * @param name The name to query. + * @return The matching condition, or null if not found. + */ + public static Condition getByName(@NotNull final String name) { + return BY_NAME.get(name); + } + + /** + * List of all registered conditions. + * + * @return The conditions. + */ + public static List> values() { + return ImmutableList.copyOf(BY_NAME.values()); + } + + /** + * Add new condition to EcoArmor. + * + * @param condition The condition to add. + */ + public static void addNewCondition(@NotNull final Condition condition) { + BY_NAME.remove(condition.getName()); + BY_NAME.put(condition.getName(), condition); + } +} 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 new file mode 100644 index 0000000..cd8f8f1 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionBelowY extends Condition { + public ConditionBelowY() { + super("below-y", Double.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + return player.getLocation().getY() < value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java index ff88a3c..2ee6abc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java @@ -3,9 +3,12 @@ package com.willfp.ecoarmor.effects; import com.willfp.ecoarmor.EcoArmorPlugin; import lombok.AccessLevel; import lombok.Getter; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.jetbrains.annotations.NotNull; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; public abstract class Effect implements Listener { @@ -39,6 +42,11 @@ public abstract class Effect implements Listener { @Getter private final Class typeClass; + /** + * Players that the effect is currently enabled for. + */ + private final Set enabledPlayers = new HashSet<>(); + /** * Create a new effect. * @@ -54,6 +62,53 @@ public abstract class Effect implements Listener { update(); Effects.addNewEffect(this); } + /** + * Get if effect is enabled for player. + * + * @param player The player. + * @return If enabled. + */ + public final boolean isEnabledForPlayer(@NotNull final Player player) { + return enabledPlayers.contains(player.getUniqueId()); + } + + /** + * Enable the effect for a player. + * + * @param player The player. + */ + public final void enable(@NotNull final Player player) { + if (enabledPlayers.contains(player.getUniqueId())) { + return; + } + + enabledPlayers.add(player.getUniqueId()); + + this.onEnable(player); + } + + /** + * Disable the effect for a player. + * + * @param player The player. + */ + public final void disable(@NotNull final Player player) { + if (!enabledPlayers.contains(player.getUniqueId())) { + return; + } + + enabledPlayers.remove(player.getUniqueId()); + + this.onDisable(player); + } + + protected void onEnable(@NotNull final Player player) { + // Empty by default + } + + protected void onDisable(@NotNull final Player player) { + // Empty by default + } /** * Update if the effect is enabled. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java index 127a872..acdc6e5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java @@ -1,13 +1,11 @@ package com.willfp.ecoarmor.effects.effects; -import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; public class SpeedMultiplier extends Effect { @@ -15,23 +13,28 @@ public class SpeedMultiplier extends Effect { super("speed-multiplier", Double.class); } - @EventHandler - public void listener(@NotNull final ArmorEquipEvent event) { - Player player = event.getPlayer(); - + @Override + protected void onEnable(@NotNull final Player player) { AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); assert movementSpeed != null; - this.getPlugin().getScheduler().runLater(() -> { - Double multiplier = ArmorUtils.getEffectStrength(player, this); - if (multiplier == null) { - movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); - } else { - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (!movementSpeed.getModifiers().contains(modifier)) { - movementSpeed.addModifier(modifier); - } - } - }, 1); + Double strength = ArmorUtils.getEffectStrength(player, this); + + if (strength == null) { + return; + } + + AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", strength - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); + if (!movementSpeed.getModifiers().contains(modifier)) { + movementSpeed.addModifier(modifier); + } + } + + @Override + protected void onDisable(@NotNull final Player player) { + AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); + assert movementSpeed != null; + + movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java new file mode 100644 index 0000000..97e3795 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java @@ -0,0 +1,60 @@ +package com.willfp.ecoarmor.effects.util; + +import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; +import com.willfp.eco.util.internal.PluginDependent; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoarmor.effects.Effect; +import com.willfp.ecoarmor.effects.Effects; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +public class EffectWatcher extends PluginDependent implements Listener { + /** + * Pass an {@link AbstractEcoPlugin} in order to interface with it. + * + * @param plugin The plugin to manage. + */ + public EffectWatcher(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + + /** + * Listener for armor equipping. + * + * @param event The event to listen for. + */ + @EventHandler + public void armorEquipListener(@NotNull final ArmorEquipEvent event) { + Player player = event.getPlayer(); + + this.getPlugin().getScheduler().runLater(() -> { + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + for (Effect effect : Effects.values()) { + boolean enabled = true; + + if (set == null) { + enabled = false; + } else { + if (set.getEffectStrength(effect) == null) { + enabled = false; + } + + if (ArmorUtils.areConditionsMet(player)) { + enabled = false; + } + } + + if (enabled) { + effect.enable(player); + } else { + effect.disable(player); + } + } + }, 1); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java index 652d717..ffc0519 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java @@ -8,6 +8,8 @@ import com.willfp.eco.util.recipe.RecipeParts; import com.willfp.eco.util.recipe.parts.ComplexRecipePart; import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe; import com.willfp.ecoarmor.EcoArmorPlugin; +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.conditions.Conditions; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.effects.Effects; import com.willfp.ecoarmor.sets.meta.ArmorSlot; @@ -55,6 +57,12 @@ public class ArmorSet { @Getter(AccessLevel.PRIVATE) private final AbstractUndefinedConfig config; + /** + * Conditions and their values. + */ + @Getter + private final Map, Object> conditions = new HashMap<>(); + /** * Effects and their strengths. */ @@ -115,6 +123,14 @@ public class ArmorSet { this.config = config; this.name = name; + for (String definedKey : this.getConfig().getStrings("conditions")) { + String[] split = definedKey.split(":"); + String key = split[0].trim(); + String value = split[1].trim(); + Condition condition = Conditions.getByName(key); + conditions.put(condition, ArmorUtils.getConditionValue(value, condition)); + } + for (String definedKey : this.getConfig().getStrings("set-bonus")) { String[] split = definedKey.split(":"); String key = split[0].trim(); @@ -324,6 +340,18 @@ public class ArmorSet { return advancedItems.get(slot); } + /** + * Get condition value of effect. + * + * @param condition The condition to query. + * @param The type of the condition value. + * @return The value. + */ + @Nullable + public T getConditionValue(@NotNull final Condition condition) { + return (T) conditions.get(condition); + } + /** * Get effect strength of effect. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index a802f56..8c6dc21 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -1,6 +1,7 @@ package com.willfp.ecoarmor.sets.util; import com.willfp.ecoarmor.EcoArmorPlugin; +import com.willfp.ecoarmor.conditions.Condition; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.ArmorSets; @@ -20,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; @UtilityClass @@ -133,6 +135,46 @@ public class ArmorUtils { return getEffectStrength(player, effect) != null; } + /** + * Get the value of a condition on a player's set. + * + * @param player The player to test. + * @param condition The condition to test. + * @param Condition type. + * @return The value or null if not found. + */ + @Nullable + public T getConditionValue(@NotNull final Player player, + @NotNull final Condition condition) { + ArmorSet set = getSetOnPlayer(player); + if (set == null) { + return null; + } + + return set.getConditionValue(condition); + } + + /** + * Get if all conditions are met for a player. + * + * @param player The player. + * @return If conditions are men. + */ + public boolean areConditionsMet(@NotNull final Player player) { + ArmorSet set = getSetOnPlayer(player); + if (set == null) { + return true; + } + + for (Map.Entry, Object> entry : set.getConditions().entrySet()) { + if (!entry.getKey().isMet(player, entry.getValue())) { + return false; + } + } + + return true; + } + /** * Get tier on upgrade crystal. * @@ -184,7 +226,7 @@ public class ArmorUtils { * Set tier on item. * * @param itemStack The item to check. - * @param tier The tier to set. + * @param tier The tier to set. */ public static void setTier(@NotNull final ItemStack itemStack, @NotNull final Tier tier) { @@ -382,4 +424,30 @@ public class ArmorUtils { return string; } + + /** + * Get value of condition. + * + * @param string Value as string. + * @param condition Condition. + * @param The type of the condition. + * @return Value. + */ + @NotNull + public static Object getConditionValue(@NotNull final String string, + @NotNull final Condition condition) { + if (condition.getTypeClass().equals(Boolean.class)) { + return Boolean.parseBoolean(string); + } + + if (condition.getTypeClass().equals(Integer.class)) { + return Integer.parseInt(string); + } + + if (condition.getTypeClass().equals(Double.class)) { + return Double.parseDouble(string); + } + + return string; + } } diff --git a/eco-core/core-plugin/src/main/resources/sets/young.yml b/eco-core/core-plugin/src/main/resources/sets/young.yml index 16d7c26..fe99704 100644 --- a/eco-core/core-plugin/src/main/resources/sets/young.yml +++ b/eco-core/core-plugin/src/main/resources/sets/young.yml @@ -1,4 +1,6 @@ enabled: true +conditions: + - "below-y: 40" set-bonus: - "speed-multiplier: 1.25" advanced-set-bonus: From fe3d33e55ad482017ceaf1901fb0ea4d374d21de Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 21:06:17 +0000 Subject: [PATCH 03/13] Fixed flipping boolean --- .../java/com/willfp/ecoarmor/effects/util/EffectWatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java index 97e3795..eb64696 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java @@ -44,7 +44,7 @@ public class EffectWatcher extends PluginDependent implements Listener { enabled = false; } - if (ArmorUtils.areConditionsMet(player)) { + if (!ArmorUtils.areConditionsMet(player)) { enabled = false; } } From eeb2c9e5b5efd6bebd8ddeea477b41587c007020 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 21:07:34 +0000 Subject: [PATCH 04/13] Changed Effect disabling --- .../src/main/java/com/willfp/ecoarmor/effects/Effect.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java index 2ee6abc..79a15c4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java @@ -93,10 +93,6 @@ public abstract class Effect implements Listener { * @param player The player. */ public final void disable(@NotNull final Player player) { - if (!enabledPlayers.contains(player.getUniqueId())) { - return; - } - enabledPlayers.remove(player.getUniqueId()); this.onDisable(player); From b6387f522bd8f752bf2a524f4af3383a99890656 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 21:10:44 +0000 Subject: [PATCH 05/13] Registered conditions --- .../src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java index c0596c1..934a6ca 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java @@ -8,6 +8,7 @@ import com.willfp.eco.util.protocollib.AbstractPacketAdapter; import com.willfp.ecoarmor.commands.CommandEagive; import com.willfp.ecoarmor.commands.CommandEareload; import com.willfp.ecoarmor.commands.TabcompleterEagive; +import com.willfp.ecoarmor.conditions.Conditions; import com.willfp.ecoarmor.display.ArmorDisplay; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.effects.Effects; @@ -15,9 +16,9 @@ import com.willfp.ecoarmor.effects.util.EffectWatcher; import com.willfp.ecoarmor.sets.ArmorSets; import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener; import com.willfp.ecoarmor.sets.util.PotionEffectListener; +import com.willfp.ecoarmor.upgrades.Tiers; import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener; import com.willfp.ecoarmor.upgrades.listeners.CrystalListener; -import com.willfp.ecoarmor.upgrades.Tiers; import com.willfp.ecoarmor.util.DiscoverRecipeListener; import lombok.Getter; import org.bukkit.event.Listener; @@ -49,6 +50,7 @@ public class EcoArmorPlugin extends AbstractEcoPlugin { @Override public void enable() { Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect)); + Conditions.values().forEach(condition -> this.getEventManager().registerListener(condition)); this.getExtensionLoader().loadExtensions(); From 641d0d5804ff36536c2f312a4c53d456caf1828e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 20 Feb 2021 21:45:53 +0000 Subject: [PATCH 06/13] Updated effects --- .../effects/AttackSpeedMultiplier.java | 39 ++++++++++--------- .../ecoarmor/effects/effects/BonusHearts.java | 37 ++++++++++-------- .../effects/effects/BowDamageMultiplier.java | 4 ++ .../effects/effects/DamageMultiplier.java | 4 ++ .../effects/DamageTakenMultiplier.java | 4 ++ .../effects/effects/DurabilityMultiplier.java | 4 ++ .../ecoarmor/effects/effects/EvadeChance.java | 4 ++ .../effects/effects/ExperienceMultiplier.java | 4 ++ .../effects/effects/FallDamageMultiplier.java | 4 ++ .../ecoarmor/effects/effects/Flight.java | 27 +++++-------- .../effects/effects/HungerLossMultiplier.java | 4 ++ .../effects/MeleeDamageMultiplier.java | 4 ++ .../effects/RegenerationMultiplier.java | 4 ++ .../effects/TridentDamageMultiplier.java | 4 ++ .../ecoarmor/effects/effects/WarpChance.java | 4 -- .../willfp/ecoarmor/sets/util/ArmorUtils.java | 31 --------------- 16 files changed, 94 insertions(+), 88 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java index 38c0087..de3513b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java @@ -1,13 +1,11 @@ package com.willfp.ecoarmor.effects.effects; -import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; public class AttackSpeedMultiplier extends Effect { @@ -15,23 +13,28 @@ public class AttackSpeedMultiplier extends Effect { super("attack-speed-multiplier", Double.class); } - @EventHandler - public void listener(@NotNull final ArmorEquipEvent event) { - Player player = event.getPlayer(); + @Override + protected void onEnable(@NotNull final Player player) { + AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); + assert maxHealth != null; - AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); - assert movementSpeed != null; + Double multiplier = ArmorUtils.getEffectStrength(player, this); - this.getPlugin().getScheduler().runLater(() -> { - Double multiplier = ArmorUtils.getEffectStrength(player, this); - if (multiplier == null) { - movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); - } else { - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (!movementSpeed.getModifiers().contains(modifier)) { - movementSpeed.addModifier(modifier); - } - } - }, 1); + if (multiplier == null) { + return; + } + + AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 1 - multiplier, AttributeModifier.Operation.MULTIPLY_SCALAR_1); + if (!maxHealth.getModifiers().contains(modifier)) { + maxHealth.addModifier(modifier); + } + } + + @Override + protected void onDisable(@NotNull final Player player) { + AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); + assert maxHealth != null; + + maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java index fb83586..5a07b98 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java @@ -1,13 +1,11 @@ package com.willfp.ecoarmor.effects.effects; -import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; public class BonusHearts extends Effect { @@ -15,23 +13,28 @@ public class BonusHearts extends Effect { super("bonus-hearts", Integer.class); } - @EventHandler - public void listener(@NotNull final ArmorEquipEvent event) { - Player player = event.getPlayer(); - + @Override + protected void onEnable(@NotNull final Player player) { AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); assert maxHealth != null; - this.getPlugin().getScheduler().runLater(() -> { - Integer bonus = ArmorUtils.getEffectStrength(player, this); - if (bonus == null) { - maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER)); - } else { - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus * 2, AttributeModifier.Operation.ADD_NUMBER); - if (!maxHealth.getModifiers().contains(modifier)) { - maxHealth.addModifier(modifier); - } - } - }, 1); + Integer bonus = ArmorUtils.getEffectStrength(player, this); + + if (bonus == null) { + return; + } + + maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER)); + } + + @Override + protected void onDisable(@NotNull final Player player) { + AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + assert maxHealth != null; + + AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER); + if (!maxHealth.getModifiers().contains(modifier)) { + maxHealth.addModifier(modifier); + } } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java index bf09977..d27b23f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java @@ -33,6 +33,10 @@ public class BowDamageMultiplier extends Effect { Player player = (Player) shooter; + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java index 726e79d..a709b30 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java @@ -38,6 +38,10 @@ public class DamageMultiplier extends Effect { return; } + if (!this.isEnabledForPlayer(attacker)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(attacker, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java index fbbb941..f74b29f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java @@ -24,6 +24,10 @@ public class DamageTakenMultiplier extends Effect { Player player = (Player) event.getEntity(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java index b2f7071..daf6103 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java @@ -21,6 +21,10 @@ public class DurabilityMultiplier extends Effect { Player player = event.getPlayer(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java index 968b5ef..c71bd6b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java @@ -25,6 +25,10 @@ public class EvadeChance extends Effect { Player player = (Player) event.getEntity(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double chance = ArmorUtils.getEffectStrength(player, this); if (chance == null) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java index d0c03a3..aee6008 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java @@ -16,6 +16,10 @@ public class ExperienceMultiplier extends Effect { public void listener(@NotNull final NaturalExpGainEvent event) { Player player = event.getExpChangeEvent().getPlayer(); + if (!this.isEnabledForPlayer(player)) { + return; + } + if (event.getExpChangeEvent().getAmount() < 0) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java index 17d820d..578e47c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java @@ -28,6 +28,10 @@ public class FallDamageMultiplier extends Effect { Player player = (Player) event.getEntity(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java index 3f1a2ca..ddb8acc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java @@ -1,11 +1,8 @@ package com.willfp.ecoarmor.effects.effects; -import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.GameMode; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; public class Flight extends Effect { @@ -13,21 +10,15 @@ public class Flight extends Effect { super("flight", Boolean.class); } - @EventHandler - public void onArmorEquip(@NotNull final ArmorEquipEvent event) { - Player player = event.getPlayer(); + @Override + protected void onEnable(@NotNull final Player player) { + player.setAllowFlight(true); + } - this.getPlugin().getScheduler().runLater(() -> { - Boolean flight = ArmorUtils.getEffectStrength(player, this); - if (flight == null) { - if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { - player.setAllowFlight(false); - } - } else { - if (flight) { - player.setAllowFlight(true); - } - } - }, 1); + @Override + protected void onDisable(@NotNull final Player player) { + if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { + player.setAllowFlight(false); + } } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java index 7b8174c..43ec8e5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java @@ -21,6 +21,10 @@ public class HungerLossMultiplier extends Effect { Player player = (Player) event.getEntity(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java index 910d9dd..0055713 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java @@ -24,6 +24,10 @@ public class MeleeDamageMultiplier extends Effect { Player attacker = (Player) event.getDamager(); + if (!this.isEnabledForPlayer(attacker)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(attacker, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java index 87b6d00..3602b72 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java @@ -24,6 +24,10 @@ public class RegenerationMultiplier extends Effect { Player player = (Player) event.getEntity(); + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java index 4703c4b..e2a99c0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java @@ -33,6 +33,10 @@ public class TridentDamageMultiplier extends Effect { Player player = (Player) shooter; + if (!this.isEnabledForPlayer(player)) { + return; + } + Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java index e11bd2b..d3836aa 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java @@ -34,10 +34,6 @@ public class WarpChance extends Effect { Player player = (Player) event.getDamager(); LivingEntity victim = (LivingEntity) event.getEntity(); - if (!ArmorUtils.hasEffect(player, this)) { - return; - } - Double chance = ArmorUtils.getEffectStrength(player, this); if (chance == null) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index 8c6dc21..984d28b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -123,37 +123,6 @@ public class ArmorUtils { return strength; } - /** - * If a player has an active effect. - * - * @param player The player to test. - * @param effect The effect to test. - * @return If a player has an active effect. - */ - public boolean hasEffect(@NotNull final Player player, - @NotNull final Effect effect) { - return getEffectStrength(player, effect) != null; - } - - /** - * Get the value of a condition on a player's set. - * - * @param player The player to test. - * @param condition The condition to test. - * @param Condition type. - * @return The value or null if not found. - */ - @Nullable - public T getConditionValue(@NotNull final Player player, - @NotNull final Condition condition) { - ArmorSet set = getSetOnPlayer(player); - if (set == null) { - return null; - } - - return set.getConditionValue(condition); - } - /** * Get if all conditions are met for a player. * From a14360497828e8e5937b3983252592e8b93dd1fb Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:06:20 +0000 Subject: [PATCH 07/13] Optimised effect system --- .../conditions/ConditionBelowY.java | 2 +- .../com/willfp/ecoarmor/effects/Effect.java | 25 +++++++++++------- .../effects/AttackSpeedMultiplier.java | 3 +-- .../ecoarmor/effects/effects/BonusHearts.java | 3 +-- .../effects/effects/BowDamageMultiplier.java | 7 +---- .../effects/effects/DamageMultiplier.java | 7 +---- .../effects/DamageTakenMultiplier.java | 7 +---- .../effects/effects/DurabilityMultiplier.java | 7 +---- .../ecoarmor/effects/effects/EvadeChance.java | 7 +---- .../effects/effects/ExperienceMultiplier.java | 7 +---- .../effects/effects/FallDamageMultiplier.java | 7 +---- .../effects/effects/HungerLossMultiplier.java | 7 +---- .../effects/MeleeDamageMultiplier.java | 6 +---- .../effects/RegenerationMultiplier.java | 7 +---- .../effects/effects/SpeedMultiplier.java | 3 +-- .../effects/TridentDamageMultiplier.java | 6 +---- .../ecoarmor/effects/effects/WarpChance.java | 3 +-- .../ecoarmor/effects/util/EffectWatcher.java | 26 +++++++++++++------ .../willfp/ecoarmor/sets/util/ArmorUtils.java | 25 ------------------ 19 files changed, 49 insertions(+), 116 deletions(-) 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 cd8f8f1..b525b62 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 @@ -30,7 +30,7 @@ public class ConditionBelowY extends Condition { } if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player)); + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); } else { set.getEffects().keySet().forEach(effect -> effect.disable(player)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java index 79a15c4..9df98ec 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java @@ -6,9 +6,10 @@ import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.HashSet; -import java.util.Set; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; public abstract class Effect implements Listener { @@ -45,7 +46,7 @@ public abstract class Effect implements Listener { /** * Players that the effect is currently enabled for. */ - private final Set enabledPlayers = new HashSet<>(); + private final Map enabledPlayers = new HashMap<>(); /** * Create a new effect. @@ -62,27 +63,31 @@ public abstract class Effect implements Listener { update(); Effects.addNewEffect(this); } + /** - * Get if effect is enabled for player. + * Get the effect strength for a player. * * @param player The player. - * @return If enabled. + * @return The strength. */ - public final boolean isEnabledForPlayer(@NotNull final Player player) { - return enabledPlayers.contains(player.getUniqueId()); + @Nullable + public final T getStrengthForPlayer(@NotNull final Player player) { + return enabledPlayers.get(player.getUniqueId()); } /** * Enable the effect for a player. * * @param player The player. + * @param value The strength. */ - public final void enable(@NotNull final Player player) { - if (enabledPlayers.contains(player.getUniqueId())) { + public final void enable(@NotNull final Player player, + @NotNull final Object value) { + if (enabledPlayers.containsKey(player.getUniqueId())) { return; } - enabledPlayers.add(player.getUniqueId()); + enabledPlayers.put(player.getUniqueId(), typeClass.cast(value)); this.onEnable(player); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java index de3513b..8e2b513 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; @@ -18,7 +17,7 @@ public class AttackSpeedMultiplier extends Effect { AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); assert maxHealth != null; - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java index 5a07b98..a27dbd2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; @@ -18,7 +17,7 @@ public class BonusHearts extends Effect { AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); assert maxHealth != null; - Integer bonus = ArmorUtils.getEffectStrength(player, this); + Integer bonus = this.getStrengthForPlayer(player); if (bonus == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java index d27b23f..e96bc07 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -33,11 +32,7 @@ public class BowDamageMultiplier extends Effect { Player player = (Player) shooter; - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java index a709b30..c63dece 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -38,11 +37,7 @@ public class DamageMultiplier extends Effect { return; } - if (!this.isEnabledForPlayer(attacker)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(attacker, this); + Double multiplier = this.getStrengthForPlayer(attacker); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java index f74b29f..c01380f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; @@ -24,11 +23,7 @@ public class DamageTakenMultiplier extends Effect { Player player = (Player) event.getEntity(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java index daf6103..946399a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java @@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerItemDamageEvent; @@ -21,11 +20,7 @@ public class DurabilityMultiplier extends Effect { Player player = event.getPlayer(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java index c71bd6b..2968771 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java @@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; @@ -25,11 +24,7 @@ public class EvadeChance extends Effect { Player player = (Player) event.getEntity(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double chance = ArmorUtils.getEffectStrength(player, this); + Double chance = this.getStrengthForPlayer(player); if (chance == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java index aee6008..06bbe4e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java @@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainEvent; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; @@ -16,15 +15,11 @@ public class ExperienceMultiplier extends Effect { public void listener(@NotNull final NaturalExpGainEvent event) { Player player = event.getExpChangeEvent().getPlayer(); - if (!this.isEnabledForPlayer(player)) { - return; - } - if (event.getExpChangeEvent().getAmount() < 0) { return; } - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java index 578e47c..d940f7b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; @@ -28,11 +27,7 @@ public class FallDamageMultiplier extends Effect { Player player = (Player) event.getEntity(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java index 43ec8e5..bd71fb1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java @@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -21,11 +20,7 @@ public class HungerLossMultiplier extends Effect { Player player = (Player) event.getEntity(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java index 0055713..f4fc350 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -24,11 +23,8 @@ public class MeleeDamageMultiplier extends Effect { Player attacker = (Player) event.getDamager(); - if (!this.isEnabledForPlayer(attacker)) { - return; - } + Double multiplier = this.getStrengthForPlayer(attacker); - Double multiplier = ArmorUtils.getEffectStrength(attacker, this); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java index 3602b72..1c63969 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityRegainHealthEvent; @@ -24,11 +23,7 @@ public class RegenerationMultiplier extends Effect { Player player = (Player) event.getEntity(); - if (!this.isEnabledForPlayer(player)) { - return; - } - - Double multiplier = ArmorUtils.getEffectStrength(player, this); + Double multiplier = this.getStrengthForPlayer(player); if (multiplier == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java index acdc6e5..ff2cd88 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; @@ -18,7 +17,7 @@ public class SpeedMultiplier extends Effect { AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); assert movementSpeed != null; - Double strength = ArmorUtils.getEffectStrength(player, this); + Double strength = this.getStrengthForPlayer(player); if (strength == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java index e2a99c0..5a272a7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java @@ -1,7 +1,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Trident; @@ -33,11 +32,8 @@ public class TridentDamageMultiplier extends Effect { Player player = (Player) shooter; - if (!this.isEnabledForPlayer(player)) { - return; - } + Double multiplier = this.getStrengthForPlayer(player); - Double multiplier = ArmorUtils.getEffectStrength(player, this); if (multiplier == null) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java index d3836aa..bf06ecb 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java @@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; @@ -34,7 +33,7 @@ public class WarpChance extends Effect { Player player = (Player) event.getDamager(); LivingEntity victim = (LivingEntity) event.getEntity(); - Double chance = ArmorUtils.getEffectStrength(player, this); + Double chance = this.getStrengthForPlayer(player); if (chance == null) { return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java index eb64696..b578425 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java @@ -38,19 +38,29 @@ public class EffectWatcher extends PluginDependent implements Listener { boolean enabled = true; if (set == null) { - enabled = false; - } else { - if (set.getEffectStrength(effect) == null) { - enabled = false; - } + effect.disable(player); + continue; + } - if (!ArmorUtils.areConditionsMet(player)) { - enabled = false; + Object strength = set.getEffectStrength(effect); + + if (ArmorUtils.isWearingAdvanced(player)) { + Object advancedStrength = set.getAdvancedEffectStrength(effect); + if (advancedStrength != null) { + strength = advancedStrength; } } + if (strength == null) { + enabled = false; + } + + if (!ArmorUtils.areConditionsMet(player)) { + enabled = false; + } + if (enabled) { - effect.enable(player); + effect.enable(player, strength); } else { effect.disable(player); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index 984d28b..06029f2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -98,31 +98,6 @@ public class ArmorUtils { return null; } - /** - * Get the strength of an effect on a player's set. - * - * @param player The player to test. - * @param effect The effect to test. - * @param Effect type. - * @return The strength, or null if not found. - */ - @Nullable - public T getEffectStrength(@NotNull final Player player, - @NotNull final Effect effect) { - ArmorSet set = getSetOnPlayer(player); - if (set == null) { - return null; - } - - T strength = set.getEffectStrength(effect); - - if (isWearingAdvanced(player)) { - strength = set.getAdvancedEffectStrength(effect); - } - - return strength; - } - /** * Get if all conditions are met for a player. * From 1ea6c4b59d0baed6c2b26c3b29802b9237404644 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:27:04 +0000 Subject: [PATCH 08/13] Added more conditions --- .../ecoarmor/conditions/Conditions.java | 16 +++- .../ConditionAboveHealthPercent.java | 80 +++++++++++++++++++ .../conditions/ConditionAboveXPLevel.java | 44 ++++++++++ .../conditions/ConditionAboveY.java | 44 ++++++++++ .../ConditionBelowHealthPercent.java | 80 +++++++++++++++++++ .../conditions/ConditionBelowXPLevel.java | 44 ++++++++++ .../conditions/ConditionInWater.java | 45 +++++++++++ .../conditions/ConditionInWorld.java | 54 +++++++++++++ .../src/main/resources/sets/young.yml | 2 +- 9 files changed, 407 insertions(+), 2 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java index 0d22f0d..6080636 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java @@ -3,7 +3,14 @@ package com.willfp.ecoarmor.conditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveHealthPercent; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveXPLevel; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveY; +import com.willfp.ecoarmor.conditions.conditions.ConditionBelowHealthPercent; +import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel; import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY; +import com.willfp.ecoarmor.conditions.conditions.ConditionInWater; +import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld; import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; @@ -18,9 +25,16 @@ public class Conditions { private static final BiMap> BY_NAME = HashBiMap.create(); public static final Condition BELOW_Y = new ConditionBelowY(); + public static final Condition ABOVE_Y = new ConditionAboveY(); + public static final Condition ABOVE_HEALTH_PERCENT = new ConditionAboveHealthPercent(); + public static final Condition BELOW_HEALTH_PERCENT = new ConditionBelowHealthPercent(); + public static final Condition IN_WATER = new ConditionInWater(); + public static final Condition IN_WORLD = new ConditionInWorld(); + public static final Condition ABOVE_XP_LEVEL = new ConditionAboveXPLevel(); + public static final Condition BELOW_XP_LEVEL = new ConditionBelowXPLevel(); /** - * Get condition matching name. + * Get condition matching name.s * * @param name The name to query. * @return The matching condition, or null if not found. 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 new file mode 100644 index 0000000..69e3927 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java @@ -0,0 +1,80 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveHealthPercent extends Condition { + public ConditionAboveHealthPercent() { + super("above-health-percent", Double.class); + } + + @EventHandler + public void listener(@NotNull final EntityRegainHealthEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @EventHandler + public void listener(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double health = player.getHealth(); + + return (health / maxHealth) * 100 >= value; + } +} 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 new file mode 100644 index 0000000..204b512 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveXPLevel extends Condition { + public ConditionAboveXPLevel() { + super("above-xp-level", Integer.class); + } + + @EventHandler + public void listener(@NotNull final PlayerExpChangeEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Integer value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Integer value) { + return player.getLevel() >= value; + } +} 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 new file mode 100644 index 0000000..2ca31f1 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveY extends Condition { + public ConditionAboveY() { + super("above-y", Double.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + return player.getLocation().getY() >= value; + } +} 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 new file mode 100644 index 0000000..1b52519 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java @@ -0,0 +1,80 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionBelowHealthPercent extends Condition { + public ConditionBelowHealthPercent() { + super("below-health-percent", Double.class); + } + + @EventHandler + public void listener(@NotNull final EntityRegainHealthEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @EventHandler + public void listener(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double health = player.getHealth(); + + return (health / maxHealth) * 100 < value; + } +} 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 new file mode 100644 index 0000000..0d69799 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionBelowXPLevel extends Condition { + public ConditionBelowXPLevel() { + super("below-xp-level", Integer.class); + } + + @EventHandler + public void listener(@NotNull final PlayerExpChangeEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Integer value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Integer value) { + return player.getLevel() < value; + } +} 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 new file mode 100644 index 0000000..f87bf38 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java @@ -0,0 +1,45 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionInWater extends Condition { + public ConditionInWater() { + super("in-water", Boolean.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Boolean value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Boolean value) { + return (player.getLocation().getBlock().getType() == Material.WATER) == value; + } +} 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 new file mode 100644 index 0000000..42b920f --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java @@ -0,0 +1,54 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; + +public class ConditionInWorld extends Condition { + public ConditionInWorld() { + super("in-world", String.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + String value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final String value) { + List worldNames = Arrays.asList(value.toLowerCase().split(" ")); + World world = player.getLocation().getWorld(); + if (world == null) { + return false; + } + + return worldNames.contains(world.getName().toLowerCase()); + } +} diff --git a/eco-core/core-plugin/src/main/resources/sets/young.yml b/eco-core/core-plugin/src/main/resources/sets/young.yml index fe99704..712be0f 100644 --- a/eco-core/core-plugin/src/main/resources/sets/young.yml +++ b/eco-core/core-plugin/src/main/resources/sets/young.yml @@ -1,6 +1,6 @@ enabled: true conditions: - - "below-y: 40" + - "above-health-percent: 50" set-bonus: - "speed-multiplier: 1.25" advanced-set-bonus: From 1b98259ef6ff59b6973489922db9dd9c6128b848 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:34:35 +0000 Subject: [PATCH 09/13] Added health condition to young armor. --- .../core-plugin/src/main/resources/sets/young.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/src/main/resources/sets/young.yml b/eco-core/core-plugin/src/main/resources/sets/young.yml index 712be0f..56b123e 100644 --- a/eco-core/core-plugin/src/main/resources/sets/young.yml +++ b/eco-core/core-plugin/src/main/resources/sets/young.yml @@ -12,7 +12,7 @@ advanced-lore: - "&lADVANCED BONUS" - "&8» &bPermanent Jump Boost II" - "&8» &bMove 50% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" advancement-shard-name: "Advancement Shard: &bYoung" advancement-shard-lore: - "&8Drop this onto &bYoung Armor" @@ -45,7 +45,7 @@ helmet: lore: - "&b&lYOUNG SET BONUS" - "&8» &bMove 25% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" - "" - "&fTier: %tier%" - "&8&oUpgrade with an Upgrade Crystal" @@ -76,7 +76,7 @@ chestplate: lore: - "&b&lYOUNG SET BONUS" - "&8» &bMove 25% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" - "" - "&fTier: %tier%" - "&8&oUpgrade with an Upgrade Crystal" @@ -105,7 +105,7 @@ elytra: lore: - "&b&lYOUNG SET BONUS" - "&8» &bMove 25% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" - "" - "&fTier: %tier%" - "&8&oUpgrade with an Upgrade Crystal" @@ -136,7 +136,7 @@ leggings: lore: - "&b&lYOUNG SET BONUS" - "&8» &bMove 25% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" - "" - "&fTier: %tier%" - "&8&oUpgrade with an Upgrade Crystal" @@ -168,7 +168,7 @@ boots: lore: - "&b&lYOUNG SET BONUS" - "&8» &bMove 25% faster" - - "&8&oRequires full set to be worn" + - "&8&oRequires full set to be worn above 50% health" - "" - "&fTier: %tier%" - "&8&oUpgrade with an Upgrade Crystal" From c26798e57227ad8d7f92e4a263ebcea3f27310fd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:45:34 +0000 Subject: [PATCH 10/13] Minor changes --- .../src/main/java/com/willfp/ecoarmor/effects/Effect.java | 4 ++++ eco-core/core-plugin/src/main/resources/sets/ender.yml | 1 + eco-core/core-plugin/src/main/resources/sets/miner.yml | 1 + eco-core/core-plugin/src/main/resources/sets/reaper.yml | 1 + 4 files changed, 7 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java index 9df98ec..72863c4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java @@ -83,6 +83,10 @@ public abstract class Effect implements Listener { */ public final void enable(@NotNull final Player player, @NotNull final Object value) { + if (!this.isEnabled()) { + return; + } + if (enabledPlayers.containsKey(player.getUniqueId())) { return; } diff --git a/eco-core/core-plugin/src/main/resources/sets/ender.yml b/eco-core/core-plugin/src/main/resources/sets/ender.yml index 8ef9a22..cac7f15 100644 --- a/eco-core/core-plugin/src/main/resources/sets/ender.yml +++ b/eco-core/core-plugin/src/main/resources/sets/ender.yml @@ -1,4 +1,5 @@ enabled: true +conditions: [] set-bonus: - "warp-chance: 20" - "evade-chance: 10" diff --git a/eco-core/core-plugin/src/main/resources/sets/miner.yml b/eco-core/core-plugin/src/main/resources/sets/miner.yml index 62c5436..ca661b1 100644 --- a/eco-core/core-plugin/src/main/resources/sets/miner.yml +++ b/eco-core/core-plugin/src/main/resources/sets/miner.yml @@ -1,4 +1,5 @@ enabled: true +conditions: [] set-bonus: - "experience-multiplier: 1.25" advanced-set-bonus: diff --git a/eco-core/core-plugin/src/main/resources/sets/reaper.yml b/eco-core/core-plugin/src/main/resources/sets/reaper.yml index 651a937..a293644 100644 --- a/eco-core/core-plugin/src/main/resources/sets/reaper.yml +++ b/eco-core/core-plugin/src/main/resources/sets/reaper.yml @@ -1,4 +1,5 @@ enabled: true +conditions: [] set-bonus: - "damage-multiplier: 1.25" advanced-set-bonus: From b1f370cddc7b6247712dc2dccde277f7b9bc264b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:55:28 +0000 Subject: [PATCH 11/13] Moved condition effect changes off to next tick --- .../ConditionAboveHealthPercent.java | 35 ++++++++++++------- .../conditions/ConditionAboveXPLevel.java | 18 ++++++---- .../conditions/ConditionAboveY.java | 18 ++++++---- .../ConditionBelowHealthPercent.java | 23 ++++++++---- .../conditions/ConditionBelowXPLevel.java | 18 ++++++---- .../conditions/ConditionBelowY.java | 18 ++++++---- .../conditions/ConditionInWater.java | 18 ++++++---- .../conditions/ConditionInWorld.java | 18 ++++++---- 8 files changed, 111 insertions(+), 55 deletions(-) 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 69e3927..45cfc76 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 @@ -6,6 +6,7 @@ import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.jetbrains.annotations.NotNull; @@ -15,7 +16,10 @@ public class ConditionAboveHealthPercent extends Condition { super("above-health-percent", Double.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final EntityRegainHealthEvent event) { if (!(event.getEntity() instanceof Player)) { return; @@ -35,14 +39,19 @@ public class ConditionAboveHealthPercent extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final EntityDamageEvent event) { if (!(event.getEntity() instanceof Player)) { return; @@ -62,11 +71,13 @@ public class ConditionAboveHealthPercent extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 204b512..c467ed6 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 @@ -5,6 +5,7 @@ import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerExpChangeEvent; import org.jetbrains.annotations.NotNull; @@ -13,7 +14,10 @@ public class ConditionAboveXPLevel extends Condition { super("above-xp-level", Integer.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerExpChangeEvent event) { Player player = event.getPlayer(); @@ -29,11 +33,13 @@ public class ConditionAboveXPLevel extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 2ca31f1..4994e37 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 @@ -5,6 +5,7 @@ import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.NotNull; @@ -13,7 +14,10 @@ public class ConditionAboveY extends Condition { super("above-y", Double.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); @@ -29,11 +33,13 @@ public class ConditionAboveY extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 1b52519..48bfc45 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 @@ -6,6 +6,7 @@ import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.jetbrains.annotations.NotNull; @@ -15,7 +16,10 @@ public class ConditionBelowHealthPercent extends Condition { super("below-health-percent", Double.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final EntityRegainHealthEvent event) { if (!(event.getEntity() instanceof Player)) { return; @@ -35,14 +39,19 @@ public class ConditionBelowHealthPercent extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final EntityDamageEvent event) { if (!(event.getEntity() instanceof Player)) { return; 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 0d69799..d2d8041 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 @@ -5,6 +5,7 @@ import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerExpChangeEvent; import org.jetbrains.annotations.NotNull; @@ -13,7 +14,10 @@ public class ConditionBelowXPLevel extends Condition { super("below-xp-level", Integer.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerExpChangeEvent event) { Player player = event.getPlayer(); @@ -29,11 +33,13 @@ public class ConditionBelowXPLevel extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 b525b62..da716a4 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 @@ -5,6 +5,7 @@ import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.NotNull; @@ -13,7 +14,10 @@ public class ConditionBelowY extends Condition { super("below-y", Double.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); @@ -29,11 +33,13 @@ public class ConditionBelowY extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 f87bf38..65a2d33 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 @@ -6,6 +6,7 @@ import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,10 @@ public class ConditionInWater extends Condition { super("in-water", Boolean.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); @@ -30,11 +34,13 @@ public class ConditionInWater extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @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 42b920f..5a44908 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 @@ -6,6 +6,7 @@ import com.willfp.ecoarmor.sets.util.ArmorUtils; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.NotNull; @@ -17,7 +18,10 @@ public class ConditionInWorld extends Condition { super("in-world", String.class); } - @EventHandler + @EventHandler( + priority = EventPriority.MONITOR, + ignoreCancelled = true + ) public void listener(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); @@ -33,11 +37,13 @@ public class ConditionInWorld extends Condition { return; } - if (isMet(player, value)) { - set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - } + 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); } @Override From 87b024cf0fc7b4e1fdfdc336c2dcc71587845213 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:58:45 +0000 Subject: [PATCH 12/13] Changed AttributeModifier effect code --- .../effects/effects/AttackSpeedMultiplier.java | 14 +++++++------- .../ecoarmor/effects/effects/BonusHearts.java | 10 +++++----- .../ecoarmor/effects/effects/SpeedMultiplier.java | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java index 8e2b513..9011f67 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java @@ -14,8 +14,8 @@ public class AttackSpeedMultiplier extends Effect { @Override protected void onEnable(@NotNull final Player player) { - AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); - assert maxHealth != null; + AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); + assert attackSpeed != null; Double multiplier = this.getStrengthForPlayer(player); @@ -24,16 +24,16 @@ public class AttackSpeedMultiplier extends Effect { } AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 1 - multiplier, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (!maxHealth.getModifiers().contains(modifier)) { - maxHealth.addModifier(modifier); + if (attackSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { + attackSpeed.addModifier(modifier); } } @Override protected void onDisable(@NotNull final Player player) { - AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); - assert maxHealth != null; + AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); + assert attackSpeed != null; - maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); + attackSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java index a27dbd2..b73b269 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java @@ -23,7 +23,10 @@ public class BonusHearts extends Effect { return; } - maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER)); + AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus, AttributeModifier.Operation.ADD_NUMBER); + if (maxHealth.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { + maxHealth.addModifier(modifier); + } } @Override @@ -31,9 +34,6 @@ public class BonusHearts extends Effect { AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); assert maxHealth != null; - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER); - if (!maxHealth.getModifiers().contains(modifier)) { - maxHealth.addModifier(modifier); - } + maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java index ff2cd88..d8b3b90 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java @@ -24,7 +24,7 @@ public class SpeedMultiplier extends Effect { } AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", strength - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (!movementSpeed.getModifiers().contains(modifier)) { + if (movementSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { movementSpeed.addModifier(modifier); } } From 067d810ee1a4f9f262ecccd41889c2eafbf25efd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 12:14:56 +0000 Subject: [PATCH 13/13] Fixed condition setting incorrect effect values --- .../willfp/ecoarmor/conditions/Condition.java | 28 +++++++++++++++++++ .../ConditionAboveHealthPercent.java | 16 ++--------- .../conditions/ConditionAboveXPLevel.java | 8 +----- .../conditions/ConditionAboveY.java | 8 +----- .../ConditionBelowHealthPercent.java | 14 ++-------- .../conditions/ConditionBelowXPLevel.java | 8 +----- .../conditions/ConditionBelowY.java | 8 +----- .../conditions/ConditionInWater.java | 8 +----- .../conditions/ConditionInWorld.java | 8 +----- 9 files changed, 38 insertions(+), 68 deletions(-) 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 abstract class Condition implements Listener { 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 class ConditionAboveHealthPercent extends Condition { 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 class ConditionAboveHealthPercent extends Condition { 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 class ConditionAboveXPLevel extends Condition { 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 class ConditionAboveY extends Condition { 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 class ConditionBelowHealthPercent extends Condition { 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 class ConditionBelowHealthPercent extends Condition { 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 class ConditionBelowXPLevel extends Condition { 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 class ConditionBelowY extends Condition { 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 class ConditionInWater extends Condition { 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 class ConditionInWorld extends Condition { 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