Commits

DerFrZocker authored 79c595c0c33
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.
No tags
master

src/main/java/org/bukkit/attribute/AttributeModifier.java

Modified
21 21 private final String name;
22 22 private final double amount;
23 23 private final Operation operation;
24 24 private final EquipmentSlotGroup slot;
25 25
26 26 public AttributeModifier(@NotNull String name, double amount, @NotNull Operation operation) {
27 27 this(UUID.randomUUID(), name, amount, operation);
28 28 }
29 29
30 30 public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation) {
31 - this(uuid, name, amount, operation, (EquipmentSlotGroup) null);
31 + this(uuid, name, amount, operation, (EquipmentSlot) null);
32 32 }
33 33
34 34 public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @Nullable EquipmentSlot slot) {
35 35 this(uuid, name, amount, operation, (slot) == null ? EquipmentSlotGroup.ANY : slot.getGroup());
36 36 }
37 37
38 38 public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @NotNull EquipmentSlotGroup slot) {
39 39 Preconditions.checkArgument(uuid != null, "UUID cannot be null");
40 40 Preconditions.checkArgument(name != null, "Name cannot be null");
41 41 Preconditions.checkArgument(operation != null, "Operation cannot be null");
42 + Preconditions.checkArgument(slot != null, "EquipmentSlotGroup cannot be null");
42 43 this.uuid = uuid;
43 44 this.name = name;
44 45 this.amount = amount;
45 46 this.operation = operation;
46 47 this.slot = slot;
47 48 }
48 49
49 50 /**
50 51 * Get the unique ID for this modifier.
51 52 *
88 89 /**
89 90 * Get the {@link EquipmentSlot} this AttributeModifier is active on,
90 91 * or null if this modifier is applicable for any slot.
91 92 *
92 93 * @return the slot
93 94 * @deprecated use {@link #getSlotGroup()}
94 95 */
95 96 @Nullable
96 97 @Deprecated
97 98 public EquipmentSlot getSlot() {
98 - return slot.getExample();
99 + return slot == EquipmentSlotGroup.ANY ? null : slot.getExample();
99 100 }
100 101
101 102 /**
102 103 * Get the {@link EquipmentSlot} this AttributeModifier is active on,
103 104 * or null if this modifier is applicable for any slot.
104 105 *
105 106 * @return the slot
106 107 */
107 108 @NotNull
108 109 public EquipmentSlotGroup getSlotGroup() {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut