From c4be51f7bb6462b99ddaf135e518f5a3c9243690 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 24 Feb 2021 15:57:21 +0100 Subject: [PATCH] Fixes #2839 --- CHANGELOG.md | 1 + .../listeners/MiningAndroidListener.java | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e68b0120..9b5dc4e0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ * Fixed exceptions with inventories not being printed using the logger of the addon that caused it * Fixed #2818 * Fixed a duplication glitch with the Woodcutter Android +* Fixed #2839 ## Release Candidate 20 (30 Jan 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiningAndroidListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiningAndroidListener.java index fb8b36dcb..34a43fcdf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiningAndroidListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiningAndroidListener.java @@ -11,6 +11,16 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.BlockStorage; +/** + * This {@link Listener} makes sure that an {@link AndroidMineEvent} gets properly propagated + * to the {@link BlockBreakHandler#onAndroidBreak(AndroidMineEvent)} method of a placed block. + * If that block is a {@link SlimefunItem} of course. + * + * @author TheBusyBiscuit + * + * @see BlockBreakHandler + * + */ public class MiningAndroidListener implements Listener { public MiningAndroidListener(@Nonnull SlimefunPlugin plugin) { @@ -19,14 +29,17 @@ public class MiningAndroidListener implements Listener { @EventHandler(ignoreCancelled = true) public void onAndroidMine(AndroidMineEvent e) { - SlimefunItem item = BlockStorage.check(e.getBlock()); + SlimefunItem slimefunItem = BlockStorage.check(e.getBlock()); - item.callItemHandler(BlockBreakHandler.class, handler -> { - if (handler.isAndroidAllowed(e.getBlock())) { - handler.onAndroidBreak(e); - } else { - e.setCancelled(true); - } - }); + // Fixes #2839 - Can't believe we forgot a null check here + if (slimefunItem != null) { + slimefunItem.callItemHandler(BlockBreakHandler.class, handler -> { + if (handler.isAndroidAllowed(e.getBlock())) { + handler.onAndroidBreak(e); + } else { + e.setCancelled(true); + } + }); + } } }