Skip to content

Commit

Permalink
Fixed clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
ToberoCat committed Jul 7, 2024
1 parent 0ba360f commit 3d794fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.toberocat.improvedfactions.claims.clustering.detector

import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin
import io.github.toberocat.improvedfactions.claims.FactionClaim
import io.github.toberocat.improvedfactions.claims.FactionClaims
import io.github.toberocat.improvedfactions.claims.clustering.ClusterType
import io.github.toberocat.improvedfactions.claims.clustering.cluster.Cluster
import io.github.toberocat.improvedfactions.claims.clustering.cluster.FactionCluster
Expand All @@ -11,6 +12,7 @@ import io.github.toberocat.improvedfactions.database.DatabaseManager.loggedTrans
import io.github.toberocat.improvedfactions.factions.Faction
import io.github.toberocat.improvedfactions.factions.FactionHandler
import io.github.toberocat.improvedfactions.modules.dynmap.DynmapModule
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*
import kotlin.concurrent.thread
Expand All @@ -24,17 +26,17 @@ class ClaimClusterDetector(

fun detectClusters() {
ImprovedFactionsPlugin.instance.logger.info("[detector] Detecting clusters...")

val job = thread {
queryProvider.allFactionPositions()
.forEach { (position, factionId) -> insertFactionPosition(position, factionId) }
ImprovedFactionsPlugin.instance.logger.info("[detector] Finished loading faction positions.")
if (transaction { FactionClaim.count(FactionClaims.clusterId eq null) == 0L }) {
ImprovedFactionsPlugin.instance.logger.info("[detector] No Faction claimed detected that have missing clusters...")
return
}

queryProvider.allFactionPositions()
.forEach { (position, factionId) -> insertFactionPosition(position, factionId) }
ImprovedFactionsPlugin.instance.logger.info("[detector] Finished loading faction positions.")
queryProvider.allZonePositions()
.forEach { (position, zoneType) -> insertZonePosition(position, zoneType) }
ImprovedFactionsPlugin.instance.logger.info("[detector] Finished loading zone positions.")
job.join()
ImprovedFactionsPlugin.instance.logger.info("[detector] All done!")
}

Expand Down Expand Up @@ -168,8 +170,12 @@ class ClaimClusterDetector(
neighboursProvider: () -> List<UUID>,
generator: (UUID, Set<FactionClaim>) -> Unit
) {
if (claim.claimCluster != null)
throw IllegalArgumentException("Position already exists in the cluster map")
if (claim.claimCluster != null) {
ImprovedFactionsPlugin.instance.logger.warning("Chunk at X: ${claim.chunkX}, Y: ${claim.chunkZ}, " +
"World: ${claim.world} for faction ${claim.factionId} was not able to get clustered.")
return
}


val neighborClusters = neighboursProvider()
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.toberocat.improvedfactions.modules.claimparticle.handles
import io.github.toberocat.improvedfactions.claims.clustering.cluster.Cluster
import io.github.toberocat.improvedfactions.claims.clustering.getCurrentClusters
import io.github.toberocat.improvedfactions.claims.clustering.position.WorldPosition
import io.github.toberocat.improvedfactions.database.DatabaseManager.loggedTransaction
import io.github.toberocat.improvedfactions.modules.claimparticle.config.ClaimParticleModuleConfig
import io.github.toberocat.toberocore.util.MathUtils
import org.bukkit.Bukkit
Expand All @@ -15,8 +16,10 @@ import org.bukkit.scheduler.BukkitRunnable
class RenderParticlesTask(private val config: ClaimParticleModuleConfig) : BukkitRunnable() {
override fun run() {
LineHandler.clearCache()
Bukkit.getOnlinePlayers().forEach { player ->
player.getCurrentClusters(config.chunkRenderDistance).forEach { player.renderClusterParticles(it) }
loggedTransaction {
Bukkit.getOnlinePlayers().forEach { player ->
player.getCurrentClusters(config.chunkRenderDistance).forEach { player.renderClusterParticles(it) }
}
}
}

Expand Down

0 comments on commit 3d794fd

Please sign in to comment.