Skip to content

Commit 30e2bad

Browse files
Properly put null values in data component map (#895)
1 parent af3d4ae commit 30e2bad

File tree

1 file changed

+2
-4
lines changed
  • protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component

1 file changed

+2
-4
lines changed

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponents.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* <li>Is a full map, {@code null} means an absence of the component in the map. {@link DataComponents#put(DataComponentType, Object)} should not be used with {@code null} values, rather {@link DataComponents#remove(DataComponentType)} should be used.</li>
1818
* <li>Is a patch, {@code null} can mean an absence of the component in the patch, or that the component should be removed from a map the patch is applied to. Use {@link DataComponents#contains(DataComponentType)}, which returns {@code true} for the latter, to check which is the case.</li>
1919
* </ul>
20-
*
21-
* <p>Make sure to initialise this class with a map that accepts null values if representing a patch.</p>
2220
*/
2321
@Data
2422
@AllArgsConstructor
@@ -38,11 +36,11 @@ public <T> T getOrDefault(DataComponentType<T> type, T def) {
3836
}
3937

4038
/**
41-
* @param value should only be {@code null } if this map is a patch to another map and specifying the removal of the specific component.
39+
* @param value should only be {@code null} if this map is a patch to another map and specifying the removal of the specific component.
4240
*/
4341
public <T> void put(DataComponentType<T> type, @Nullable T value) {
4442
if (value == null) {
45-
dataComponents.put(type, null);
43+
dataComponents.put(type, type.readNullDataComponent());
4644
} else if (type instanceof IntComponentType intType) {
4745
dataComponents.put(intType, intType.primitiveFactory.createPrimitive(intType, (Integer) value));
4846
} else if (type instanceof BooleanComponentType boolType) {

0 commit comments

Comments
 (0)