Fixed speed issues

This commit is contained in:
Auxilor
2021-01-31 18:57:20 +00:00
parent 1a13c3f536
commit 57f80cc6b5
2 changed files with 14 additions and 9 deletions

View File

@@ -37,6 +37,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@SuppressWarnings({"unchecked", "deprecation", "RedundantSuppression"})
@@ -53,6 +54,12 @@ public abstract class Talisman implements Listener, Watcher {
@Getter
private final NamespacedKey key;
/**
* UUID created for the talisman.
*/
@Getter
private final UUID uuid;
/**
* The display name of the talisman.
*/
@@ -139,6 +146,7 @@ public abstract class Talisman implements Listener, Watcher {
@NotNull final Prerequisite... prerequisites) {
this.strength = strength;
this.key = this.getPlugin().getNamespacedKeyFactory().create(key + "_" + strength.name().toLowerCase());
this.uuid = UUID.nameUUIDFromBytes(this.getKey().getKey().getBytes());
this.configName = this.key.getKey().replace("_", "");
TalismansConfigs.addTalismanConfig(new TalismanConfig(this.configName, this.strength, this.getClass()));
this.config = TalismansConfigs.getTalismanConfig(this.configName);

View File

@@ -12,11 +12,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class SpeedTalisman extends Talisman {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed_talisman".getBytes());
private static AttributeModifier MODIFIER = new AttributeModifier(MODIFIER_UUID, "speed_talisman", 0.05, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
private AttributeModifier modifier = null;
public SpeedTalisman(@NotNull final TalismanStrength strength) {
super("speed", strength);
@@ -24,7 +21,7 @@ public class SpeedTalisman extends Talisman {
@Override
protected void postUpdate() {
MODIFIER = new AttributeModifier(MODIFIER_UUID, "speed_talisman", this.getConfig().getDouble(Talismans.CONFIG_LOCATION + "percentage-bonus") / 100, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
modifier = new AttributeModifier(this.getUuid(), this.getKey().getKey(), this.getConfig().getDouble(Talismans.CONFIG_LOCATION + "percentage-bonus") / 100, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
}
@EventHandler
@@ -40,14 +37,14 @@ public class SpeedTalisman extends Talisman {
if (event.getType() == EquipType.EQUIP) {
if (this.getDisabledWorlds().contains(player.getWorld())) {
movementSpeed.removeModifier(MODIFIER);
movementSpeed.removeModifier(modifier);
} else {
if (!movementSpeed.getModifiers().contains(MODIFIER)) {
movementSpeed.addModifier(MODIFIER);
if (!movementSpeed.getModifiers().contains(modifier)) {
movementSpeed.addModifier(modifier);
}
}
} else {
movementSpeed.removeModifier(MODIFIER);
movementSpeed.removeModifier(modifier);
}
}
}