Skip to content

Commit

Permalink
Second Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed May 7, 2024
1 parent b6181e8 commit 0c34178
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -464,6 +464,27 @@ public synchronized TeamEnhancement getTeamEnhancement(Island island, String enh
}
}

private HashMap<XMaterial, Integer> getBlockStacks(Chunk chunk, Island island) {
HashMap<XMaterial, Integer> hashMap = new HashMap<>();

for (StackerSupport<Island> stackerSupport : IridiumSkyblock.getInstance().getSupportManager().getStackerSupport()) {
stackerSupport.getBlocksStacked(chunk, island).forEach((key, value) -> hashMap.put(key, hashMap.getOrDefault(key, 0) + value));
}

return hashMap;
}

private CompletableFuture<Integer> getSpawnerStackAmount(CreatureSpawner creatureSpawner) {
CompletableFuture<Integer> 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<Void> recalculateTeam(Island island) {
Map<XMaterial, Integer> teamBlocks = new HashMap<>();
Expand All @@ -478,22 +499,17 @@ public CompletableFuture<Void> 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);
});
}
Expand Down

0 comments on commit 0c34178

Please sign in to comment.