Skip to content

Commit

Permalink
Add UltimateStacker hook for stacked blocks (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceze88 committed Apr 5, 2023
1 parent c093796 commit 9c42a8d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
<!-- UltimateStacker repo -->
<repository>
<id>songoda-public</id>
<url>https://repo.songoda.com/repository/public/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -234,6 +239,12 @@
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Level extends Addon {
private boolean stackersEnabled;
private boolean advChestEnabled;
private boolean roseStackersEnabled;
private boolean ultimateStackerEnabled;
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();

/**
Expand Down Expand Up @@ -146,6 +147,12 @@ public void onEnable() {
if (roseStackersEnabled) {
log("Hooked into RoseStackers.");
}

// Check if UltimateStacker is enabled
ultimateStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
if (ultimateStackerEnabled) {
log("Hooked into UltimateStacker.");
}
}

@Override
Expand Down Expand Up @@ -403,6 +410,13 @@ public boolean isRoseStackersEnabled() {
return roseStackersEnabled;
}

/**
* @return the ultimateStackerEnabled
*/
public boolean isUltimateStackerEnabled() {
return ultimateStackerEnabled;
}

/**
* Method Level#getVisitHook returns the visitHook of this object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.core.compatibility.CompatibleMaterial;
import com.songoda.ultimatestacker.stackable.block.BlockStack;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
Expand Down Expand Up @@ -524,6 +527,25 @@ private void scanAsync(ChunkPair cp) {
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) || blockData.getMaterial().equals(Material.SPAWNER))) {
stackedBlocks.add(new Location(cp.world, (double)x + cp.chunkSnapshot.getX() * 16, y, (double)z + cp.chunkSnapshot.getZ() * 16));
}

Block block = cp.chunk.getBlock(x, y, z);

if (addon.isUltimateStackerEnabled()) {
if (!blockData.getMaterial().equals(Material.AIR)) {
BlockStack stack = UltimateStacker.getInstance().getBlockStackManager().getBlock(block, CompatibleMaterial.getMaterial(block));
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
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
chestBlocks.add(cp.chunk);
Expand Down

0 comments on commit 9c42a8d

Please sign in to comment.