diff --git a/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java b/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java index 7dd6f3de37..8ba00f743b 100644 --- a/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java +++ b/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java @@ -28,7 +28,7 @@ public class AttributeModifier implements ConfigurationSerializable { } public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation) { - this(uuid, name, amount, operation, (EquipmentSlotGroup) null); + this(uuid, name, amount, operation, (EquipmentSlot) null); } public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @Nullable EquipmentSlot slot) { @@ -39,6 +39,7 @@ public class AttributeModifier implements ConfigurationSerializable { Preconditions.checkArgument(uuid != null, "UUID cannot be null"); Preconditions.checkArgument(name != null, "Name cannot be null"); Preconditions.checkArgument(operation != null, "Operation cannot be null"); + Preconditions.checkArgument(slot != null, "EquipmentSlotGroup cannot be null"); this.uuid = uuid; this.name = name; this.amount = amount; @@ -95,7 +96,7 @@ public class AttributeModifier implements ConfigurationSerializable { @Nullable @Deprecated public EquipmentSlot getSlot() { - return slot.getExample(); + return slot == EquipmentSlotGroup.ANY ? null : slot.getExample(); } /** diff --git a/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlot.java b/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlot.java index d776a0c183..5642d8af60 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlot.java +++ b/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlot.java @@ -1,24 +1,25 @@ package org.bukkit.inventory; +import java.util.function.Supplier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; public enum EquipmentSlot { - HAND(EquipmentSlotGroup.MAINHAND), - OFF_HAND(EquipmentSlotGroup.OFFHAND), - FEET(EquipmentSlotGroup.FEET), - LEGS(EquipmentSlotGroup.LEGS), - CHEST(EquipmentSlotGroup.CHEST), - HEAD(EquipmentSlotGroup.HEAD), + HAND(() -> EquipmentSlotGroup.MAINHAND), + OFF_HAND(() -> EquipmentSlotGroup.OFFHAND), + FEET(() -> EquipmentSlotGroup.FEET), + LEGS(() -> EquipmentSlotGroup.LEGS), + CHEST(() -> EquipmentSlotGroup.CHEST), + HEAD(() -> EquipmentSlotGroup.HEAD), /** * Only for certain entities such as horses and wolves. */ - BODY(EquipmentSlotGroup.ARMOR); + BODY(() -> EquipmentSlotGroup.ARMOR); - private final EquipmentSlotGroup group; + private final Supplier group; // Supplier because of class loading order, since EquipmentSlot and EquipmentSlotGroup reference each other on class init - private EquipmentSlot(/*@NotNull*/ EquipmentSlotGroup group) { + private EquipmentSlot(/*@NotNull*/ Supplier group) { this.group = group; } @@ -30,6 +31,6 @@ public enum EquipmentSlot { @NotNull @ApiStatus.Internal public EquipmentSlotGroup getGroup() { - return group; + return group.get(); } }