9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-28 03:19:25 +00:00

Changed AttributeModifier effect code

This commit is contained in:
Auxilor
2021-02-21 11:58:45 +00:00
parent b1f370cddc
commit 87b024cf0f
3 changed files with 13 additions and 13 deletions

View File

@@ -14,8 +14,8 @@ public class AttackSpeedMultiplier extends Effect<Double> {
@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<Double> {
}
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));
}
}

View File

@@ -23,7 +23,10 @@ public class BonusHearts extends Effect<Integer> {
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<Integer> {
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));
}
}

View File

@@ -24,7 +24,7 @@ public class SpeedMultiplier extends Effect<Double> {
}
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);
}
}