From f779f0ca958b08deb2f00915b710f348963c0cc3 Mon Sep 17 00:00:00 2001
From: Dalton Burchard <48583030+Burchard36@users.noreply.github.com>
Date: Tue, 28 Jan 2020 08:32:52 -0800
Subject: [PATCH] Add support for Wild Stacker (#124)
* Add support for Wild Stackers (Blocks Only)
* Shorten my recent commit, modified checkBlock method slightly to not pass full BlockData; rather just the Material that is used in the method
---
pom.xml | 11 ++++++
src/main/java/world/bentobox/level/Level.java | 8 +++++
.../level/calculators/CalcIslandLevel.java | 36 ++++++++++++++-----
3 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8915588..9530fa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -147,6 +147,11 @@
codemc-public
https://repo.codemc.org/repository/maven-public/
+
+
+ jitpack.io
+ https://jitpack.io
+
@@ -182,6 +187,12 @@
${bentobox.version}
provided
+
+
+ com.github.OmerBenGera
+ WildStackerAPI
+ b17
+
diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java
index 876a58d..c2ef35e 100644
--- a/src/main/java/world/bentobox/level/Level.java
+++ b/src/main/java/world/bentobox/level/Level.java
@@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
+import world.bentobox.level.calculators.CalcIslandLevel;
import world.bentobox.level.commands.admin.AdminLevelCommand;
import world.bentobox.level.commands.admin.AdminTopCommand;
import world.bentobox.level.commands.island.IslandLevelCommand;
@@ -199,6 +200,13 @@ public class Level extends Addon {
registerRequestHandler(new LevelRequestHandler(this));
registerRequestHandler(new TopTenRequestHandler(this));
+ // Check if WildStackers is enabled on the server
+ if (getPlugin().getServer().getPluginManager().getPlugin("WildStacker") != null) {
+ // I only added support for counting blocks into the island level
+ // Someone else can PR if they want spawners added to the Leveling system :)
+ CalcIslandLevel.stackersEnabled = true;
+ } else CalcIslandLevel.stackersEnabled = false;
+
// Done
}
diff --git a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
index b3c396d..f21e1b6 100644
--- a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
+++ b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
@@ -13,12 +13,15 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import com.bgsoftware.wildstacker.api.WildStackerAPI;
+import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
+import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
@@ -37,7 +40,8 @@ public class CalcIslandLevel {
private static final String LINE_BREAK = "==================================";
- public static final long MAX_AMOUNT = 10000;
+ public static final long MAX_AMOUNT = 10000;
+ public static Boolean stackersEnabled;
private final Level addon;
@@ -122,7 +126,7 @@ public class CalcIslandLevel {
ChunkSnapshot snapShot = ch.getChunkSnapshot();
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
- this.scanChunk(snapShot);
+ this.scanChunk(snapShot, ch);
count.getAndIncrement();
if (count.get() == total) {
Bukkit.getScheduler().cancelTask(queueid);
@@ -131,7 +135,7 @@ public class CalcIslandLevel {
});
}
- private void scanChunk(ChunkSnapshot chunk) {
+ private void scanChunk(ChunkSnapshot chunk, Chunk physicalChunk) {
World chunkWorld = Bukkit.getWorld(chunk.getWorldName());
if (chunkWorld == null) return;
int maxHeight = chunkWorld.getMaxHeight();
@@ -155,23 +159,37 @@ public class CalcIslandLevel {
if (Tag.SLABS.isTagged(blockData.getMaterial())) {
Slab slab = (Slab)blockData;
if (slab.getType().equals(Slab.Type.DOUBLE)) {
- checkBlock(blockData, belowSeaLevel);
+ checkBlock(blockData.getMaterial(), belowSeaLevel);
}
}
- checkBlock(blockData, belowSeaLevel);
+
+ // Hook for Wild Stackers (Blocks Only)
+ if (stackersEnabled && blockData.getMaterial() == Material.CAULDRON) {
+ Block cauldronBlock = physicalChunk.getBlock(x, y, z);
+ if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
+ StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
+ int barrelAmt = WildStackerAPI.getBarrelAmount(cauldronBlock);
+ for (int _x = 0; _x < barrelAmt; _x++) {
+ checkBlock(barrel.getType(), belowSeaLevel);
+ }
+ }
+ }
+
+ checkBlock(blockData.getMaterial(), belowSeaLevel);
}
}
}
}
- private void checkBlock(BlockData bd, boolean belowSeaLevel) {
- int count = limitCount(bd.getMaterial());
+ // Didnt see a reason to pass BlockData when all that's used was the material
+ private void checkBlock(Material mat, boolean belowSeaLevel) {
+ int count = limitCount(mat);
if (belowSeaLevel) {
result.underWaterBlockCount.addAndGet(count);
- result.uwCount.add(bd.getMaterial());
+ result.uwCount.add(mat);
} else {
result.rawBlockCount.addAndGet(count);
- result.mdCount.add(bd.getMaterial());
+ result.mdCount.add(mat);
}
}