Add support to hook into AdvancedChests.

https://github.com/BentoBoxWorld/Level/issues/214
This commit is contained in:
tastybento 2021-02-23 18:59:20 -08:00
parent e002ade414
commit 311455e921
2 changed files with 31 additions and 7 deletions

View File

@ -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

View File

@ -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);
}
}
}