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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user