9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 10:59:22 +00:00

Added effect uuids

This commit is contained in:
Auxilor
2021-02-06 11:00:26 +00:00
parent 144a140db1
commit d9bab46fb1
4 changed files with 15 additions and 18 deletions

View File

@@ -6,6 +6,8 @@ import lombok.Getter;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public abstract class Effect<T> implements Listener {
/**
* Instance of EcoArmor.
@@ -19,6 +21,12 @@ public abstract class Effect<T> implements Listener {
@Getter
private final String name;
/**
* UUID of the effect, used in attribute modifiers.
*/
@Getter
private final UUID uuid;
/**
* If the effect is enabled.
*/
@@ -41,6 +49,7 @@ public abstract class Effect<T> implements Listener {
@NotNull final Class<T> typeClass) {
this.name = name;
this.typeClass = typeClass;
this.uuid = UUID.nameUUIDFromBytes(name.getBytes());
update();
Effects.addNewEffect(this);

View File

@@ -10,11 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class AttackSpeedMultiplier extends Effect<Double> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("attack-speed-multiplier".getBytes());
public AttackSpeedMultiplier() {
super("attack-speed-multiplier", Double.class);
}
@@ -29,9 +25,9 @@ public class AttackSpeedMultiplier extends Effect<Double> {
this.getPlugin().getScheduler().runLater(() -> {
Double multiplier = ArmorUtils.getEffectStrength(player, this);
if (multiplier == null) {
movementSpeed.removeModifier(new AttributeModifier(MODIFIER_UUID, "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
} else {
AttributeModifier modifier = new AttributeModifier(MODIFIER_UUID, "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
if (!movementSpeed.getModifiers().contains(modifier)) {
movementSpeed.addModifier(modifier);
}

View File

@@ -10,11 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class BonusHearts extends Effect<Integer> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("bonus-hearts".getBytes());
public BonusHearts() {
super("bonus-hearts", Integer.class);
}
@@ -29,9 +25,9 @@ public class BonusHearts extends Effect<Integer> {
this.getPlugin().getScheduler().runLater(() -> {
Integer bonus = ArmorUtils.getEffectStrength(player, this);
if (bonus == null) {
maxHealth.removeModifier(new AttributeModifier(MODIFIER_UUID, "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER));
maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER));
} else {
AttributeModifier modifier = new AttributeModifier(MODIFIER_UUID, "bonus-hearts", bonus * 2, AttributeModifier.Operation.ADD_NUMBER);
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus * 2, AttributeModifier.Operation.ADD_NUMBER);
if (!maxHealth.getModifiers().contains(modifier)) {
maxHealth.addModifier(modifier);
}

View File

@@ -10,11 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class SpeedMutiplier extends Effect<Double> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed-multiplier".getBytes());
public SpeedMutiplier() {
super("speed-multiplier", Double.class);
}
@@ -29,9 +25,9 @@ public class SpeedMutiplier extends Effect<Double> {
this.getPlugin().getScheduler().runLater(() -> {
Double multiplier = ArmorUtils.getEffectStrength(player, this);
if (multiplier == null) {
movementSpeed.removeModifier(new AttributeModifier(MODIFIER_UUID, "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
} else {
AttributeModifier modifier = new AttributeModifier(MODIFIER_UUID, "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
if (!movementSpeed.getModifiers().contains(modifier)) {
movementSpeed.addModifier(modifier);
}