From 0c341788c0a56647274a32dc03aaeeb509935659 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Tue, 7 May 2024 20:52:13 +0100 Subject: [PATCH] Second Implementation --- build.gradle.kts | 2 +- .../managers/IslandManager.java | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8ae41674c..562525e8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,7 +23,7 @@ dependencies { implementation("org.jetbrains:annotations:24.1.0") implementation("com.j256.ormlite:ormlite-core:6.1") implementation("com.j256.ormlite:ormlite-jdbc:6.1") - implementation("com.iridium:IridiumTeams:2.4.3") + implementation("com.iridium:IridiumTeams:2.4.3-dev2") // Other dependencies that are not required or already available at runtime compileOnly("org.projectlombok:lombok:1.18.32") diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 6512d9f33..051dbd6ac 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -25,6 +25,7 @@ import com.iridium.iridiumteams.missions.Mission; import com.iridium.iridiumteams.missions.MissionData; import com.iridium.iridiumteams.missions.MissionType; +import com.iridium.iridiumteams.support.StackerSupport; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -40,7 +41,6 @@ import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.IOException; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -464,6 +464,27 @@ public synchronized TeamEnhancement getTeamEnhancement(Island island, String enh } } + private HashMap getBlockStacks(Chunk chunk, Island island) { + HashMap hashMap = new HashMap<>(); + + for (StackerSupport stackerSupport : IridiumSkyblock.getInstance().getSupportManager().getStackerSupport()) { + stackerSupport.getBlocksStacked(chunk, island).forEach((key, value) -> hashMap.put(key, hashMap.getOrDefault(key, 0) + value)); + } + + return hashMap; + } + + private CompletableFuture getSpawnerStackAmount(CreatureSpawner creatureSpawner) { + CompletableFuture completableFuture = new CompletableFuture<>(); + Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { + completableFuture.complete(IridiumSkyblock.getInstance().getSupportManager().getSpawnerSupport().stream() + .mapToInt(stackerSupport -> stackerSupport.getStackAmount(creatureSpawner)) + .max() + .orElse(1)); + }); + return completableFuture; + } + @Override public CompletableFuture recalculateTeam(Island island) { Map teamBlocks = new HashMap<>(); @@ -478,22 +499,17 @@ public CompletableFuture recalculateTeam(Island island) { for (int y = 0; y <= maxy; y++) { if (island.isInIsland(x + (chunkSnapshot.getX() * 16), z + (chunkSnapshot.getZ() * 16))) { XMaterial material = XMaterial.matchXMaterial(chunkSnapshot.getBlockType(x, y, z)); - Block block = chunk.getBlock(x, y, z); - int amount = IridiumSkyblock.getInstance().getSupportManager().getStackerSupport().stream() - .mapToInt(stackerSupport -> stackerSupport.getStackAmount(block)) - .max() - .orElse(1); - teamBlocks.put(material, teamBlocks.getOrDefault(material, 0) + amount); + teamBlocks.put(material, teamBlocks.getOrDefault(material, 0) + 1); } } } } - getSpawners(chunk, island).join().forEach(creatureSpawner -> { - int amount = IridiumSkyblock.getInstance().getSupportManager().getSpawnerSupport().stream() - .mapToInt(stackerSupport -> stackerSupport.getStackAmount(creatureSpawner)) - .max() - .orElse(1); + getBlockStacks(chunk, island).forEach((key, value) -> { + teamBlocks.put(key, teamBlocks.getOrDefault(key, 0) + value); + }); + getSpawners(chunk, island).join().forEach(creatureSpawner -> { + int amount = getSpawnerStackAmount(creatureSpawner).join(); teamSpawners.put(creatureSpawner.getSpawnedType(), teamSpawners.getOrDefault(creatureSpawner.getSpawnedType(), 0) + amount); }); }