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

View File

@ -57,6 +57,7 @@ public class Level extends Addon implements Listener {
private LevelsManager manager; private LevelsManager manager;
private boolean stackersEnabled; private boolean stackersEnabled;
private boolean advChestEnabled; private boolean advChestEnabled;
private boolean roseStackersEnabled;
private final List<GameModeAddon> registeredGameModes = new ArrayList<>(); private final List<GameModeAddon> registeredGameModes = new ArrayList<>();
@Override @Override
@ -106,7 +107,7 @@ public class Level extends Addon implements Listener {
// Check if WildStackers is enabled on the server // Check if WildStackers is enabled on the server
// I only added support for counting blocks into the island level // I only added support for counting blocks into the island level
// Someone else can PR if they want spawners added to the Leveling system :) // 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) { if (stackersEnabled) {
log("Hooked into WildStackers."); log("Hooked into WildStackers.");
} }
@ -122,6 +123,11 @@ public class Level extends Addon implements Listener {
advChestEnabled = false; 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 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; 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.block.data.type.Slab;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import com.bgsoftware.wildstacker.api.WildStackerAPI; 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.Multiset.Entry;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
import dev.rosewood.rosestacker.api.RoseStackerAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI; import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest; import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest;
import us.lynuxcraft.deadsilenceiv.advancedchests.chest.gui.page.ChestPage; import us.lynuxcraft.deadsilenceiv.advancedchests.chest.gui.page.ChestPage;
@ -151,6 +154,8 @@ public class IslandLevelCalculator {
private final Results results; private final Results results;
private long duration; private long duration;
private final boolean zeroIsland; 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 * Constructor to get the level for an island
@ -170,6 +175,24 @@ public class IslandLevelCalculator {
this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits()); this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits());
// Get the initial island level // Get the initial island level
results.initialLevel.set(addon.getInitialIslandLevel(island)); 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 * Get a chunk async
* @param world - the world where the chunk is
* @param env - the environment * @param env - the environment
* @param x - chunk x coordinate * @param x - chunk x coordinate
* @param z - chunk z 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 * @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) { private CompletableFuture<Chunk> getWorldChunk(Environment env, int x, int z) {
switch (env) { if (worlds.containsKey(env)) {
case NETHER: CompletableFuture<Chunk> r2 = new CompletableFuture<>();
if (addon.getSettings().isNether()) { // Get the chunk, and then coincidentally check the RoseStacker
World nether = addon.getPlugin().getIWM().getNetherWorld(island.getWorld()); Util.getChunkAtAsync(worlds.get(env), x, z, true).thenAccept(chunk -> roseStackerCheck(r2, chunk));
if (nether != null) { return r2;
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);
} }
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 * @param chunkSnapshot - the chunk to scan
*/ */
private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSnapshot, Chunk chunk) { private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSnapshot, Chunk chunk) {
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
List<Vector> stackedBlocks = new ArrayList<>(); List<Vector> stackedBlocks = new ArrayList<>();
for (int x = 0; x< 16; x++) { for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't count it // 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 // Set up the result
CompletableFuture<Boolean> result = new CompletableFuture<>(); CompletableFuture<Boolean> result = new CompletableFuture<>();
// Get chunks and scan // 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 -> 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 -> 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 -> scanChunk(normalChunk).thenAccept(b3 ->
// Complete the result now that all chunks have been scanned // Complete the result now that all chunks have been scanned
result.complete(!chunksToCheck.isEmpty())))) result.complete(!chunksToCheck.isEmpty()))))