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. *