diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index 91b498d..2901406 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -48,6 +48,7 @@ public class Level extends Addon implements Listener { private Pipeliner pipeliner; private LevelsManager manager; private boolean stackersEnabled; + private boolean advChestEnabled; @Override public void onLoad() { @@ -98,6 +99,11 @@ public class Level extends Addon implements Listener { if (stackersEnabled) { log("Hooked into WildStackers."); } + // Check if AdvancedChests is enabled on the server + advChestEnabled = Bukkit.getPluginManager().getPlugin("AdvancedChests") != null; + if (advChestEnabled) { + log("Hooked into AdvancedChests."); + } } @EventHandler @@ -278,6 +284,13 @@ public class Level extends Addon implements Listener { return stackersEnabled; } + /** + * @return the advChestEnabled + */ + public boolean isAdvChestEnabled() { + return advChestEnabled; + } + /** * Get level from cache for a player. * @param targetPlayer - target player UUID diff --git a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java index 1b97489..b3668d6 100644 --- a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java +++ b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java @@ -34,6 +34,9 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Multisets; +import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI; +import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest; +import us.lynuxcraft.deadsilenceiv.advancedchests.chest.ChestPage; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Pair; @@ -430,13 +433,21 @@ public class IslandLevelCalculator { // Count blocks in chests for (BlockState bs : chunk.getTileEntities()) { if (bs instanceof Container) { - Inventory inv = ((Container)bs).getSnapshotInventory(); - for (ItemStack i : inv) { - if (i != null && i.getType().isBlock()) { - for (int c = 0; c < i.getAmount(); c++) { - checkBlock(i.getType(), false); - } - } + if (addon.isAdvChestEnabled()) { + AdvancedChest aChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(bs.getLocation()); + aChest.getPages().stream().map(ChestPage::getInventory).forEach(this::countChestItems); + } else { + countChestItems(((Container)bs).getSnapshotInventory()); + } + } + } + } + + private void countChestItems(Inventory inv) { + for (ItemStack i : inv) { + if (i != null && i.getType().isBlock()) { + for (int c = 0; c < i.getAmount(); c++) { + checkBlock(i.getType(), false); } } }