You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Improve DataComponents class
- Added #contains and #remove methods
- Make #put allow null values
- Add Javadoc to make usage of null values clear
* Add fromKey method to DataComponentTypes
Copy file name to clipboardExpand all lines: protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentTypes.java
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -181,6 +181,10 @@ public static DataComponentType<?> from(int id) {
Copy file name to clipboardExpand all lines: protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponents.java
+30-3Lines changed: 30 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,24 @@
2
2
3
3
importlombok.AllArgsConstructor;
4
4
importlombok.Data;
5
-
importlombok.NonNull;
6
5
importorg.jetbrains.annotations.Nullable;
7
6
8
7
importjava.util.HashMap;
9
8
importjava.util.Map;
10
9
10
+
/**
11
+
* Wrapper around a map of data components and their respective values.
12
+
*
13
+
* <p>This map can either be a complete data component map, or a data component patch to another map. The meaning of {@code null} values in the map depends on if the map
14
+
* is a patch or full map. If the map:</p>
15
+
*
16
+
* <ul>
17
+
* <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>
18
+
* <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>
19
+
* </ul>
20
+
*
21
+
* <p>Make sure to initialise this class with a map that accepts null values if representing a patch.</p>
22
+
*/
11
23
@Data
12
24
@AllArgsConstructor
13
25
publicclassDataComponents {
@@ -25,8 +37,13 @@ public <T> T getOrDefault(DataComponentType<T> type, T def) {
25
37
returnvalue != null ? value : def;
26
38
}
27
39
28
-
public <T> voidput(DataComponentType<T> type, @NonNullTvalue) {
29
-
if (typeinstanceofIntComponentTypeintType) {
40
+
/**
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.
42
+
*/
43
+
public <T> voidput(DataComponentType<T> type, @NullableTvalue) {
0 commit comments