Skip to content

Commit

Permalink
Merge pull request #200 from ToberoCat/faster-clustering
Browse files Browse the repository at this point in the history
Faster clustering
  • Loading branch information
ToberoCat authored Jul 7, 2024
2 parents cd2c120 + d16bf3d commit db22324
Show file tree
Hide file tree
Showing 46 changed files with 753 additions and 515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.jeff_media.updatechecker.UpdateCheckSource
import com.jeff_media.updatechecker.UpdateChecker
import com.jeff_media.updatechecker.UserAgentBuilder
import io.github.toberocat.improvedfactions.claims.FactionClaims
import io.github.toberocat.improvedfactions.claims.clustering.ClaimClusterDetector
import io.github.toberocat.improvedfactions.claims.clustering.DatabaseClaimQueryProvider
import io.github.toberocat.improvedfactions.claims.clustering.detector.ClaimClusterDetector
import io.github.toberocat.improvedfactions.claims.clustering.query.DatabaseClaimQueryProvider
import io.github.toberocat.improvedfactions.commands.FactionCommandExecutor
import io.github.toberocat.improvedfactions.commands.claim.FactionMap
import io.github.toberocat.improvedfactions.config.ImprovedFactionsConfig
Expand All @@ -15,24 +15,16 @@ import io.github.toberocat.improvedfactions.invites.FactionInvites
import io.github.toberocat.improvedfactions.listeners.PlayerJoinListener
import io.github.toberocat.improvedfactions.listeners.move.MoveListener
import io.github.toberocat.improvedfactions.modules.ModuleManager
import io.github.toberocat.improvedfactions.modules.chat.ChatModule
import io.github.toberocat.improvedfactions.modules.dynmap.DynmapModule
import io.github.toberocat.improvedfactions.modules.gui.GuiModule
import io.github.toberocat.improvedfactions.modules.home.HomeModule
import io.github.toberocat.improvedfactions.modules.power.PowerRaidsModule
import io.github.toberocat.improvedfactions.modules.wilderness.WildernessModule
import io.github.toberocat.improvedfactions.papi.PapiExpansion
import io.github.toberocat.improvedfactions.ranks.FactionRankHandler
import io.github.toberocat.improvedfactions.ranks.FactionRanks
import io.github.toberocat.improvedfactions.translation.updateLanguages
import io.github.toberocat.improvedfactions.utils.BStatsCollector
import io.github.toberocat.improvedfactions.utils.FileUtils
import io.github.toberocat.improvedfactions.utils.arguments.ClaimRadiusArgument
import io.github.toberocat.improvedfactions.utils.options.PlayerNameOption
import io.github.toberocat.improvedfactions.utils.particles.ParticleAnimation
import io.github.toberocat.improvedfactions.utils.threadPool
import io.github.toberocat.improvedfactions.zone.ZoneHandler
import io.github.toberocat.toberocore.command.CommandExecutor
import me.clip.placeholderapi.PlaceholderAPI
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import org.bukkit.Bukkit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.toberocat.improvedfactions.claims

import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin
import io.github.toberocat.improvedfactions.claims.clustering.FactionCluster
import io.github.toberocat.improvedfactions.claims.clustering.ChunkPosition
import io.github.toberocat.improvedfactions.claims.clustering.cluster.Cluster
import io.github.toberocat.improvedfactions.claims.clustering.cluster.FactionCluster
import io.github.toberocat.improvedfactions.claims.clustering.position.ChunkPosition
import io.github.toberocat.improvedfactions.claims.overclaim.ClaimSiegeManager
import io.github.toberocat.improvedfactions.factions.Faction
import io.github.toberocat.improvedfactions.user.noFactionId
Expand All @@ -24,6 +25,7 @@ class FactionClaim(id: EntityID<Int>) : IntEntity(id) {
var chunkZ by FactionClaims.chunkZ
var factionId by FactionClaims.factionId
var zoneType by FactionClaims.zoneType
var claimCluster by Cluster optionalReferencedOn FactionClaims.clusterId

fun faction(): Faction? = Faction.findById(factionId)

Expand All @@ -43,7 +45,11 @@ class FactionClaim(id: EntityID<Int>) : IntEntity(id) {
fun chunk() = Bukkit.getWorld(world)?.getChunkAt(chunkX, chunkZ)
fun toPosition() = ChunkPosition(chunkX, chunkZ, world)

private fun getCluster() = ImprovedFactionsPlugin.instance.claimChunkClusters.getCluster(toPosition())
private fun getCluster() = ImprovedFactionsPlugin.instance.claimChunkClusters.getCluster(this)

fun isRaidable() = (getCluster()?.findAdditionalType() as? FactionCluster)?.isUnprotected(chunkX, chunkZ, world)
override fun toString(): String {
return "FactionClaim(world='$world', chunkX=$chunkX, chunkZ=$chunkZ, factionId=$factionId, zoneType='$zoneType', claimCluster=${claimCluster?.id?.value})"
}

fun isRaidable() = (getCluster() as? FactionCluster)?.isUnprotected(chunkX, chunkZ, world)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.toberocat.improvedfactions.claims

import io.github.toberocat.improvedfactions.claims.clustering.cluster.Clusters
import io.github.toberocat.improvedfactions.zone.ZoneHandler
import org.jetbrains.exposed.dao.id.IntIdTable

Expand All @@ -13,4 +14,5 @@ object FactionClaims : IntIdTable("faction_claims") {
val factionId = integer("faction_id")
val world = varchar("world", MAX_WORLD_NAME_LENGTH).default("world")
val zoneType = varchar("zone_type", MAX_ZONE_NAME_LENGTH).default(ZoneHandler.FACTION_ZONE_TYPE)
val clusterId = reference("cluster_id", Clusters).nullable()
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.toberocat.improvedfactions.claims.clustering

import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin
import io.github.toberocat.improvedfactions.claims.clustering.position.ChunkPosition
import org.bukkit.entity.Player

object ClusterExtension {
fun Player.getCurrentClusters(chunkRenderDistance: Int) = location.world?.name?.let { world ->
ChunkPosition(location.chunk.x, location.chunk.z, world)
.getNeighbours(chunkRenderDistance)
.mapNotNull { ImprovedFactionsPlugin.instance.claimChunkClusters.getCluster(it) }
} ?: emptyList()
}
fun Player.getCurrentClusters(chunkRenderDistance: Int) = location.world?.name?.let { world ->
ChunkPosition(location.chunk.x, location.chunk.z, world)
.getNeighbours(chunkRenderDistance)
.mapNotNull { it.getFactionClaim() }
.mapNotNull { ImprovedFactionsPlugin.instance.claimChunkClusters.getCluster(it) }
} ?: emptyList()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.toberocat.improvedfactions.claims.clustering

enum class ClusterType {
FACTION,
ZONE
}
Loading

0 comments on commit db22324

Please sign in to comment.