Isolate UltimateStacker imports so no errors if US is not installed (#307)

Fixes #306
This commit is contained in:
tastybento 2024-04-20 09:50:17 -07:00 committed by GitHub
parent 1bd6219f94
commit a4f8d12138
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 431 additions and 417 deletions

View File

@ -40,8 +40,6 @@ import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
import com.google.common.collect.Multiset; import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
import com.craftaro.ultimatestacker.api.utils.Stackable;
import dev.rosewood.rosestacker.api.RoseStackerAPI; import dev.rosewood.rosestacker.api.RoseStackerAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI; import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
@ -448,46 +446,33 @@ public class IslandLevelCalculator {
// Only count to the highest block in the world for some optimization // Only count to the highest block in the world for some optimization
for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) { for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) {
BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z); BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z);
Material m = blockData.getMaterial();
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight; boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
// Slabs can be doubled, so check them twice // Slabs can be doubled, so check them twice
if (Tag.SLABS.isTagged(blockData.getMaterial())) { if (Tag.SLABS.isTagged(m)) {
Slab slab = (Slab) blockData; Slab slab = (Slab) blockData;
if (slab.getType().equals(Slab.Type.DOUBLE)) { if (slab.getType().equals(Slab.Type.DOUBLE)) {
checkBlock(blockData.getMaterial(), belowSeaLevel); checkBlock(m, belowSeaLevel);
} }
} }
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real // Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real
// chunk // chunk
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) if (addon.isStackersEnabled() && (m.equals(Material.CAULDRON) || m.equals(Material.SPAWNER))) {
|| blockData.getMaterial().equals(Material.SPAWNER))) {
stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y, stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y,
(double) z + cp.chunkSnapshot.getZ() * 16)); (double) z + cp.chunkSnapshot.getZ() * 16));
} }
Block block = cp.chunk.getBlock(x, y, z); if (addon.isUltimateStackerEnabled() && !m.isAir()) {
Location l = new Location(cp.chunk.getWorld(), x, y, z);
if (addon.isUltimateStackerEnabled()) { UltimateStackerCalc.addStackers(m, l, results, belowSeaLevel, limitCount(m));
if (!blockData.getMaterial().equals(Material.AIR)) {
Stackable stack = UltimateStackerApi.getBlockStackManager().getBlock(block.getLocation());
if (stack != null) {
int value = limitCount(blockData.getMaterial());
if (belowSeaLevel) {
results.underWaterBlockCount.addAndGet((long) stack.getAmount() * value);
results.uwCount.add(blockData.getMaterial());
} else {
results.rawBlockCount.addAndGet((long) stack.getAmount() * value);
results.mdCount.add(blockData.getMaterial());
}
}
}
} }
// Scan chests // Scan chests
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) { if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
chestBlocks.add(cp.chunk); chestBlocks.add(cp.chunk);
} }
// Add the value of the block's material // Add the value of the block's material
checkBlock(blockData.getMaterial(), belowSeaLevel); checkBlock(m, belowSeaLevel);
} }
} }
} }

View File

@ -0,0 +1,29 @@
package world.bentobox.level.calculators;
import org.bukkit.Location;
import org.bukkit.Material;
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
import com.craftaro.ultimatestacker.api.utils.Stackable;
import world.bentobox.bentobox.BentoBox;
/**
* Isolates UltimateStacker imports so that they are only loaded if the plugin exists
*/
public class UltimateStackerCalc {
public static void addStackers(Material material, Location location, Results results, boolean belowSeaLevel,
int value) {
Stackable stack = UltimateStackerApi.getBlockStackManager().getBlock(location);
if (stack != null) {
if (belowSeaLevel) {
results.underWaterBlockCount.addAndGet((long) stack.getAmount() * value);
results.uwCount.add(material);
} else {
results.rawBlockCount.addAndGet((long) stack.getAmount() * value);
results.mdCount.add(material);
}
}
}
}