mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Merge pull request #273 from Project-Cepi/avoid-npe-itemtag
Avoid NPE when getting NBT in ItemTag
This commit is contained in:
commit
1699c088f6
@ -84,7 +84,16 @@ public class ItemTag<T> {
|
||||
|
||||
public static @NotNull ItemTag<NBT> NBT(@NotNull String key) {
|
||||
return new ItemTag<>(key,
|
||||
nbt -> nbt.get(key).deepClone(),
|
||||
nbt -> {
|
||||
var currentNBT = nbt.get(key);
|
||||
|
||||
// Avoid a NPE when cloning a null variable.
|
||||
if (currentNBT == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return currentNBT.deepClone();
|
||||
},
|
||||
((nbt, value) -> nbt.set(key, value.deepClone())));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user