From 3d794fd6ad4af2f079f172d23b63747ed655a0f4 Mon Sep 17 00:00:00 2001 From: tobias Date: Sun, 7 Jul 2024 21:34:21 +0200 Subject: [PATCH] Fixed clustering --- .../detector/ClaimClusterDetector.kt | 22 ++++++++++++------- .../handles/RenderParticlesTask.kt | 7 ++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/claims/clustering/detector/ClaimClusterDetector.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/claims/clustering/detector/ClaimClusterDetector.kt index db933364..8da53f5f 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/claims/clustering/detector/ClaimClusterDetector.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/claims/clustering/detector/ClaimClusterDetector.kt @@ -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 @@ -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 @@ -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!") } @@ -168,8 +170,12 @@ class ClaimClusterDetector( neighboursProvider: () -> List, generator: (UUID, Set) -> 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 { diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/modules/claimparticle/handles/RenderParticlesTask.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/modules/claimparticle/handles/RenderParticlesTask.kt index 27f29c8d..3d11fec1 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/modules/claimparticle/handles/RenderParticlesTask.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/modules/claimparticle/handles/RenderParticlesTask.kt @@ -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 @@ -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) } + } } }