|
|
|
@ -1,16 +1,17 @@
|
|
|
|
|
package net.trivernis.chunkmaster
|
|
|
|
|
|
|
|
|
|
import net.trivernis.chunkmaster.lib.generation.GenerationTaskPaper
|
|
|
|
|
import org.bukkit.Server
|
|
|
|
|
import org.bukkit.event.EventHandler
|
|
|
|
|
import org.bukkit.event.Listener
|
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent
|
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent
|
|
|
|
|
import org.bukkit.event.world.WorldSaveEvent
|
|
|
|
|
|
|
|
|
|
class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server: Server) : Listener {
|
|
|
|
|
|
|
|
|
|
private val pauseOnJoin = chunkmaster.config.getBoolean("generation.pause-on-join")
|
|
|
|
|
private val pauseOnPlayerCount: Int
|
|
|
|
|
get () {
|
|
|
|
|
return chunkmaster.config.getInt("generation.pause-on-player-count")
|
|
|
|
|
}
|
|
|
|
|
private var playerPaused = false
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -18,21 +19,15 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
*/
|
|
|
|
|
@EventHandler
|
|
|
|
|
fun onPlayerQuit(event: PlayerQuitEvent) {
|
|
|
|
|
if (pauseOnJoin) {
|
|
|
|
|
if (server.onlinePlayers.size == 1 && server.onlinePlayers.contains(event.player) ||
|
|
|
|
|
server.onlinePlayers.isEmpty()
|
|
|
|
|
) {
|
|
|
|
|
if (!playerPaused) {
|
|
|
|
|
if (chunkmaster.generationManager.pausedTasks.isNotEmpty()) {
|
|
|
|
|
chunkmaster.logger.info("Server is empty. Resuming chunk generation tasks.")
|
|
|
|
|
}
|
|
|
|
|
chunkmaster.generationManager.resumeAll()
|
|
|
|
|
} else if (chunkmaster.generationManager.paused){
|
|
|
|
|
chunkmaster.logger.info("Generation was manually paused. Not resuming automatically.")
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
} else {
|
|
|
|
|
chunkmaster.logger.info("Generation tasks are already running.")
|
|
|
|
|
if (server.onlinePlayers.size == pauseOnPlayerCount) {
|
|
|
|
|
if (!playerPaused) {
|
|
|
|
|
if (chunkmaster.generationManager.pausedTasks.isNotEmpty()) {
|
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("RESUME_PLAYER_LEAVE"))
|
|
|
|
|
}
|
|
|
|
|
chunkmaster.generationManager.resumeAll()
|
|
|
|
|
} else if (chunkmaster.generationManager.paused){
|
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("PAUSE_MANUALLY"))
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -42,14 +37,12 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
*/
|
|
|
|
|
@EventHandler
|
|
|
|
|
fun onPlayerJoin(event: PlayerJoinEvent) {
|
|
|
|
|
if (pauseOnJoin) {
|
|
|
|
|
if (server.onlinePlayers.size == 1 || server.onlinePlayers.isEmpty()) {
|
|
|
|
|
if (chunkmaster.generationManager.tasks.isNotEmpty()) {
|
|
|
|
|
chunkmaster.logger.info("Pausing generation tasks because of player join.")
|
|
|
|
|
}
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
chunkmaster.generationManager.pauseAll()
|
|
|
|
|
if (server.onlinePlayers.size >= pauseOnPlayerCount) {
|
|
|
|
|
if (chunkmaster.generationManager.tasks.isNotEmpty()) {
|
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("PAUSE_PLAYER_JOIN"))
|
|
|
|
|
}
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
chunkmaster.generationManager.pauseAll()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|