From 333ecf93daf5f9663268e22fd964440d5c4a828a Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 30 Jan 2022 13:00:30 +0100 Subject: [PATCH] allow blocks with no drop tables --- .../Indyuce/mmocore/api/block/BlockInfo.java | 17 ++++++++--------- .../Indyuce/mmocore/listener/BlockListener.java | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java index 1007354c..874e3507 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java @@ -14,11 +14,9 @@ import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.logging.Level; public class BlockInfo { @@ -78,18 +76,19 @@ public class BlockInfo { return block; } + @NotNull public DropTable getDropTable() { - return table; - } - - public List collectDrops(LootBuilder builder) { - return hasDropTable() ? table.collect(builder) : new ArrayList<>(); + return Objects.requireNonNull(table, "Block has no drop table"); } public boolean hasDropTable() { return table != null; } + public List collectDrops(LootBuilder builder) { + return table != null ? table.collect(builder) : new ArrayList<>(); + } + public boolean hasRegen() { return regen != null; } diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 19e5f6b7..227203b5 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -85,7 +85,7 @@ public class BlockListener implements Listener { * Find the block drops */ boolean conditionsMet = !info.hasDropTable() || info.getDropTable().areConditionsMet(new ConditionInstance(player)); - List drops = conditionsMet ? info.getDropTable().collect(new LootBuilder(PlayerData.get(player), 0)) : new ArrayList<>(); + List drops = conditionsMet && info.hasDropTable() ? info.getDropTable().collect(new LootBuilder(PlayerData.get(player), 0)) : new ArrayList<>(); /* * Calls the event and listen for cancel & for drops changes... also