Add shulker to in chest count (#275)

This commit is contained in:
DevSolaris 2023-02-10 04:31:35 +01:00 committed by GitHub
parent 42249a8fc9
commit a493c12f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 7 deletions

View File

@ -24,13 +24,11 @@ import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.scheduler.BukkitTask;
import com.bgsoftware.wildstacker.api.WildStackerAPI;
@ -445,10 +443,16 @@ public class IslandLevelCalculator {
}
private void countItemStack(ItemStack i) {
if (i != null && i.getType().isBlock()) {
if (i == null || !i.getType().isBlock()) return;
for (int c = 0; c < i.getAmount(); c++) {
checkBlock(i.getType(), false);
if (addon.getSettings().isIncludeShulkersInChest()
&& i.getItemMeta() instanceof BlockStateMeta blockStateMeta
&& blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox) {
shulkerBox.getSnapshotInventory().forEach(this::countItemStack);
}
checkBlock(i.getType(), false);
}
}

View File

@ -119,6 +119,12 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
@ConfigEntry(path = "shorthand")
private boolean shorthand = false;
@ConfigComment("")
@ConfigComment("Include Shulker Box content in chests in level calculations.")
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
@ConfigComment("NOTE: include-chests needs to be enabled for this to work!.")
@ConfigEntry(path = "include-shulkers-in-chest")
private boolean includeShulkersInChest = false;
/**
@ -385,4 +391,17 @@ public class ConfigSettings implements ConfigObject {
this.logReportToConsole = logReportToConsole;
}
/**
* @return includeShulkersInChest
*/
public boolean isIncludeShulkersInChest() {
return includeShulkersInChest;
}
/**
* @param includeShulkersInChest the includeChests to set
*/
public void setIncludeShulkersInChest(boolean includeShulkersInChest) {
this.includeShulkersInChest = includeShulkersInChest;
}
}