From 86b457861ce8b06d48df648b5d23c8c141b002e5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 7 Feb 2025 13:43:56 -0800 Subject: [PATCH] fix for NPE during inventory events Fixes #5148 --- Changelog.txt | 1 + .../gmail/nossr50/util/ContainerMetadataUtils.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index ec0da726b..5e098a85f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.2.031 + Fixed potential NPE when player or blockstate is null for Inventory events on Furnaces Fixed bug where en_us locale was being set system-wide (thanks BlvckBytes) Fixed bug where Decimal format would throw exception on non en_us systems (thanks BlvckBytes) (API) Added McMMOPlayerTameEntityEvent event (thanks Warriorrr) diff --git a/src/main/java/com/gmail/nossr50/util/ContainerMetadataUtils.java b/src/main/java/com/gmail/nossr50/util/ContainerMetadataUtils.java index 2a49f0461..516394c21 100644 --- a/src/main/java/com/gmail/nossr50/util/ContainerMetadataUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ContainerMetadataUtils.java @@ -23,9 +23,11 @@ import static java.util.Objects.requireNonNull; public class ContainerMetadataUtils { - public static void changeContainerOwnership(@NotNull BlockState blockState, @NotNull Player player) { - requireNonNull(blockState, "blockState cannot be null"); - requireNonNull(player, "Player cannot be null"); + public static void changeContainerOwnership(@Nullable BlockState blockState, @Nullable Player player) { + // no-op when the blockState is null or player is null + if (blockState == null || player == null) { + return; + } final McMMOPlayer mmoPlayer = UserManager.getPlayer(player); @@ -79,6 +81,11 @@ public class ContainerMetadataUtils { } public static void processContainerOwnership(BlockState blockState, Player player) { + // no-op when the blockState is null or player is null + if (blockState == null || player == null) { + return; + } + if (getContainerOwner(blockState) != null) { if (getContainerOwner(blockState).getUniqueId().equals(player.getUniqueId())) return;