From 3ba3d433446f1e09c038a5d6185a900b69ae6ac0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 25 Feb 2022 11:30:25 +0000 Subject: [PATCH] Fixed rare crash with LootPopulator --- .../support/obtaining/LootPopulator.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index 197352e4..985d6556 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -67,7 +67,7 @@ public class LootPopulator extends BlockPopulator { if (!(entity instanceof StorageMinecart minecart)) { continue; } - modifyInventory(minecart.getInventory()); + modifyInventory(minecart.getInventory(), chunk); } for (BlockState state : chunk.getTileEntities()) { @@ -76,7 +76,7 @@ public class LootPopulator extends BlockPopulator { continue; } Inventory inventory = chestState.getBlockInventory(); - modifyInventory(inventory); + modifyInventory(inventory, chunk); } } @@ -194,14 +194,19 @@ public class LootPopulator extends BlockPopulator { } /** - * Modify given inventory with EcoEnchants enchantments + * Modify given inventory with EcoEnchants enchantments. * - * @param inventory The target inventory + * @param inventory The target inventory. + * @param chunk The chunk. */ - public void modifyInventory(@NotNull final Inventory inventory) { - for (ItemStack item : inventory) { - this.plugin.getScheduler().runLater(1, () -> modifyItem(item)); - } + public void modifyInventory(@NotNull final Inventory inventory, + @NotNull final Chunk chunk) { + this.plugin.getScheduler().runLater(1, () -> { + if (chunk.isLoaded()) { + for (ItemStack item : inventory) { + modifyItem(item); + } + } + }); } - }