diff --git a/src/main/java/org/bukkit/attribute/AttributeModifier.java b/src/main/java/org/bukkit/attribute/AttributeModifier.java index 2a7ac892..6ffc8951 100644 --- a/src/main/java/org/bukkit/attribute/AttributeModifier.java +++ b/src/main/java/org/bukkit/attribute/AttributeModifier.java @@ -7,6 +7,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.UUID; +import java.util.regex.Pattern; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.ConfigurationSerializable; @@ -21,27 +22,28 @@ import org.jetbrains.annotations.Nullable; */ public class AttributeModifier implements ConfigurationSerializable, Keyed { + private static final Pattern UUID_PATTERN = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"); private final NamespacedKey key; private final double amount; private final Operation operation; private final EquipmentSlotGroup slot; - @Deprecated + @Deprecated(since = "1.21", forRemoval = true) public AttributeModifier(@NotNull String name, double amount, @NotNull Operation operation) { this(UUID.randomUUID(), name, amount, operation); } - @Deprecated + @Deprecated(since = "1.21", forRemoval = true) public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation) { this(uuid, name, amount, operation, (EquipmentSlot) null); } - @Deprecated + @Deprecated(since = "1.21", forRemoval = true) public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @Nullable EquipmentSlot slot) { this(uuid, name, amount, operation, (slot) == null ? EquipmentSlotGroup.ANY : slot.getGroup()); } - @Deprecated + @Deprecated(since = "1.21", forRemoval = true) public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @NotNull EquipmentSlotGroup slot) { this(NamespacedKey.fromString(uuid.toString()), amount, operation, slot); } @@ -64,9 +66,18 @@ public class AttributeModifier implements ConfigurationSerializable, Keyed { * @deprecated attributes are now identified by keys */ @NotNull - @Deprecated + @Deprecated(since = "1.21", forRemoval = true) public UUID getUniqueId() { - return UUID.nameUUIDFromBytes(getKey().toString().getBytes(StandardCharsets.UTF_8)); + NamespacedKey namespacedKey = getKey(); + if (namespacedKey.getNamespace().equals(NamespacedKey.MINECRAFT)) { + String key = namespacedKey.getKey(); + + if (key.length() == 36 && UUID_PATTERN.matcher(key).matches()) { + return UUID.fromString(key); + } + } + + return UUID.nameUUIDFromBytes(namespacedKey.toString().getBytes(StandardCharsets.UTF_8)); } @NotNull