Skip to content

Commit cae0c73

Browse files
authored
fix: ensure spread spawning doesn't run in other worlds (#85)
* fix: spread spawning in other worlds
1 parent 0336e67 commit cae0c73

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/SpawningFeature.kt

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,27 @@ class SpawningFeature(context: FeatureContext) : Feature(context) {
6767
}
6868

6969
override fun enable() {
70+
// -- Spread Spawn logic --
71+
val spreadConfig by config(
72+
"spread_config", plugin.dataPath,
73+
SpreadEntityTypesConfig(),
74+
mergeUpdates = false,
75+
formats = ConfigFormats(
76+
listOf(
77+
Format(
78+
"yml", Yaml(
79+
serializersModule = gearyPaper.worldManager.global.getAddon(SerializableComponents).serializers.module,
80+
configuration = YamlConfiguration(strictMode = false)
81+
)
82+
)
83+
)
84+
)
85+
)
86+
val mainWorld = Bukkit.getWorld(spreadConfig.worldName) ?: error("World ${spreadConfig.worldName} not found, cannot initialize spread spawning")
87+
7088
// -- Database logic --
7189
val db = plugin.sqliteDatabase(Path("spawns.db")) {
72-
val world = Bukkit.getWorlds().firstOrNull() ?: error("No worlds found, cannot initialize spawning database")
73-
SpawningSchema(listOf(world)).init()
90+
SpawningSchema(listOf(mainWorld)).init()
7491
}
7592
database = db
7693

@@ -100,24 +117,6 @@ class SpawningFeature(context: FeatureContext) : Feature(context) {
100117
spawnAttempts = config.maxSpawnAttemptsPerPlayer,
101118
mobSpawner = mobSpawner,
102119
)
103-
104-
// -- Spread Spawn logic --
105-
val spreadConfig by config(
106-
"spread_config", plugin.dataPath,
107-
SpreadEntityTypesConfig(),
108-
mergeUpdates = false,
109-
formats = ConfigFormats(
110-
listOf(
111-
Format(
112-
"yml", Yaml(
113-
serializersModule = gearyPaper.worldManager.global.getAddon(SerializableComponents).serializers.module,
114-
configuration = YamlConfiguration(strictMode = false)
115-
)
116-
)
117-
)
118-
)
119-
)
120-
val mainWorld = Bukkit.getWorld(spreadConfig.worldName) ?: error("World ${spreadConfig.worldName} not found, cannot initialize spread spawning")
121120
val posChooser = InChunkLocationChooser(mobSpawner, mainWorld)
122121
val dao = SpawnLocationsDAO()
123122
val chunkChooser = SpreadChunkChooser(logger, mainWorld, db, dao)
@@ -133,7 +132,7 @@ class SpawningFeature(context: FeatureContext) : Feature(context) {
133132
)
134133

135134
listeners(
136-
ListSpawnListener(spreadSpawner, db, dao, plugin),
135+
ListSpawnListener(spreadSpawner, db, dao, plugin, mainWorld),
137136
SpreadEntityDeathListener(
138137
spreadSpawner, db, plugin, mainWorld
139138
)

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/listeners/SpreadEntitySpawnListener.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
88
import me.dvyy.sqlite.Database
99
import org.bukkit.Chunk
1010
import org.bukkit.Location
11+
import org.bukkit.World
1112
import org.bukkit.event.EventHandler
1213
import org.bukkit.event.Listener
1314
import org.bukkit.event.world.ChunkLoadEvent
@@ -19,11 +20,13 @@ class ListSpawnListener(
1920
private val spawner: SpreadSpawner,
2021
private val db: Database,
2122
private val dao: SpawnLocationsDAO,
22-
private val plugin: Plugin
23+
private val plugin: Plugin,
24+
private val mainWorld: World,
2325
) : Listener {
2426

2527
@EventHandler
2628
fun ChunkLoadEvent.onChunkLoad() {
29+
if (chunk.world != mainWorld) return
2730
plugin.launch {
2831
triggerSpawn(chunk)
2932
}

0 commit comments

Comments
 (0)