mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 03:48:01 +01:00
SPIGOT-7637: Bad logic in checking nullability of AttributeModifier slots
Also fix Class loading order issues, which resulted in EquipmentSlot#getGroup returning null, since EquipmentSlot and EquipmentSlotGroup referencing each other on class init. This caused EquipmentSlot to being init first, when the fields in EquipmentSlotGroup are still null, resulting in the group being null. By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
1ba56ce1ca
commit
c30ea3a2d3
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<EquipmentSlotGroup> 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<EquipmentSlotGroup> group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@ -30,6 +31,6 @@ public enum EquipmentSlot {
|
||||
@NotNull
|
||||
@ApiStatus.Internal
|
||||
public EquipmentSlotGroup getGroup() {
|
||||
return group;
|
||||
return group.get();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user