Rosestacker (#232)

* Add support for RoseStacker 1.3.0
This commit is contained in:
tastybento 2021-08-09 20:00:55 -07:00 committed by GitHub
parent d55f66f868
commit bd6c264f4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 30 deletions

13
pom.xml
View File

@ -131,6 +131,11 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<!-- RoseStacker repo -->
<repository>
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
</repositories>
<dependencies>
@ -171,6 +176,7 @@
<groupId>com.github.OmerBenGera</groupId>
<artifactId>WildStackerAPI</artifactId>
<version>b18</version>
<scope>provided</scope>
</dependency>
<!-- Static analysis -->
<!-- We are using Eclipse's annotations. If you're using IDEA, update
@ -185,6 +191,13 @@
<groupId>com.github.DeadSilenceIV</groupId>
<artifactId>AdvancedChestsAPI</artifactId>
<version>1.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.rosewood</groupId>
<artifactId>rosestacker</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -57,6 +57,7 @@ public class Level extends Addon implements Listener {
private LevelsManager manager;
private boolean stackersEnabled;
private boolean advChestEnabled;
private boolean roseStackersEnabled;
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();
@Override
@ -106,7 +107,7 @@ public class Level extends Addon implements Listener {
// Check if WildStackers is enabled on the server
// I only added support for counting blocks into the island level
// Someone else can PR if they want spawners added to the Leveling system :)
stackersEnabled = Bukkit.getPluginManager().getPlugin("WildStacker") != null;
stackersEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
if (stackersEnabled) {
log("Hooked into WildStackers.");
}
@ -122,6 +123,11 @@ public class Level extends Addon implements Listener {
advChestEnabled = false;
}
}
// Check if RoseStackers is enabled
roseStackersEnabled = Bukkit.getPluginManager().isPluginEnabled("RoseStacker");
if (roseStackersEnabled) {
log("Hooked into RoseStackers.");
}
}
/**
@ -445,4 +451,11 @@ public class Level extends Addon implements Listener {
return registeredGameModes.stream().map(GameModeAddon::getOverWorld).anyMatch(w -> Util.sameWorld(world, w));
}
/**
* @return the roseStackersEnabled
*/
public boolean isRoseStackersEnabled() {
return roseStackersEnabled;
}
}

View File

@ -2,9 +2,12 @@ package world.bentobox.level.calculators;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@ -24,7 +27,6 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import com.bgsoftware.wildstacker.api.WildStackerAPI;
@ -33,6 +35,7 @@ import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Multisets;
import dev.rosewood.rosestacker.api.RoseStackerAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest;
import us.lynuxcraft.deadsilenceiv.advancedchests.chest.gui.page.ChestPage;
@ -151,6 +154,8 @@ public class IslandLevelCalculator {
private final Results results;
private long duration;
private final boolean zeroIsland;
private final Map<Environment, World> worlds = new EnumMap<>(Environment.class);
private final int seaHeight;
/**
* Constructor to get the level for an island
@ -170,6 +175,24 @@ public class IslandLevelCalculator {
this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits());
// Get the initial island level
results.initialLevel.set(addon.getInitialIslandLevel(island));
// Set up the worlds
worlds.put(Environment.NORMAL, Util.getWorld(island.getWorld()));
// Nether
if (addon.getSettings().isNether()) {
World nether = addon.getPlugin().getIWM().getNetherWorld(island.getWorld());
if (nether != null) {
worlds.put(Environment.NETHER, nether);
}
}
// End
if (addon.getSettings().isEnd()) {
World end = addon.getPlugin().getIWM().getEndWorld(island.getWorld());
if (end != null) {
worlds.put(Environment.THE_END, end);
}
}
// Sea Height
seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
}
/**
@ -311,36 +334,33 @@ public class IslandLevelCalculator {
/**
* Get a chunk async
* @param world - the world where the chunk is
* @param env - the environment
* @param x - chunk x coordinate
* @param z - chunk z coordinate
* @return a future chunk or future null if there is no chunk to load, e.g., there is no island nether
*/
private CompletableFuture<Chunk> getWorldChunk(@NonNull World world, Environment env, int x, int z) {
switch (env) {
case NETHER:
if (addon.getSettings().isNether()) {
World nether = addon.getPlugin().getIWM().getNetherWorld(island.getWorld());
if (nether != null) {
return Util.getChunkAtAsync(nether, x, z, true);
}
}
// There is no chunk to scan, so return a null chunk
return CompletableFuture.completedFuture(null);
case THE_END:
if (addon.getSettings().isEnd()) {
World end = addon.getPlugin().getIWM().getEndWorld(island.getWorld());
if (end != null) {
return Util.getChunkAtAsync(end, x, z, true);
}
}
// There is no chunk to scan, so return a null chunk
return CompletableFuture.completedFuture(null);
default:
return Util.getChunkAtAsync(world, x, z, true);
private CompletableFuture<Chunk> getWorldChunk(Environment env, int x, int z) {
if (worlds.containsKey(env)) {
CompletableFuture<Chunk> r2 = new CompletableFuture<>();
// Get the chunk, and then coincidentally check the RoseStacker
Util.getChunkAtAsync(worlds.get(env), x, z, true).thenAccept(chunk -> roseStackerCheck(r2, chunk));
return r2;
}
return CompletableFuture.completedFuture(null);
}
private void roseStackerCheck(CompletableFuture<Chunk> r2, Chunk chunk) {
if (addon.isRoseStackersEnabled()) {
RoseStackerAPI.getInstance().getStackedBlocks(Collections.singletonList(chunk)).forEach(e -> {
// Blocks below sea level can be scored differently
boolean belowSeaLevel = seaHeight > 0 && e.getLocation().getY() <= seaHeight;
// Check block once because the base block will be counted in the chunk snapshot
for (int _x = 0; _x < e.getStackSize() - 1; _x++) {
checkBlock(e.getBlock().getType(), belowSeaLevel);
}
});
}
r2.complete(chunk);
}
/**
@ -369,7 +389,6 @@ public class IslandLevelCalculator {
* @param chunkSnapshot - the chunk to scan
*/
private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSnapshot, Chunk chunk) {
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
List<Vector> stackedBlocks = new ArrayList<>();
for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
@ -486,11 +505,11 @@ public class IslandLevelCalculator {
// Set up the result
CompletableFuture<Boolean> result = new CompletableFuture<>();
// Get chunks and scan
getWorldChunk(island.getWorld(), Environment.THE_END, p.x, p.z).thenAccept(endChunk ->
getWorldChunk(Environment.THE_END, p.x, p.z).thenAccept(endChunk ->
scanChunk(endChunk).thenAccept(b ->
getWorldChunk(island.getWorld(), Environment.NETHER, p.x, p.z).thenAccept(netherChunk ->
getWorldChunk(Environment.NETHER, p.x, p.z).thenAccept(netherChunk ->
scanChunk(netherChunk).thenAccept(b2 ->
getWorldChunk(island.getWorld(), Environment.NORMAL, p.x, p.z).thenAccept(normalChunk ->
getWorldChunk(Environment.NORMAL, p.x, p.z).thenAccept(normalChunk ->
scanChunk(normalChunk).thenAccept(b3 ->
// Complete the result now that all chunks have been scanned
result.complete(!chunksToCheck.isEmpty()))))