|
|
@ -1,16 +1,17 @@
|
|
|
|
package net.trivernis.chunkmaster
|
|
|
|
package net.trivernis.chunkmaster
|
|
|
|
|
|
|
|
|
|
|
|
import net.trivernis.chunkmaster.lib.generation.GenerationTaskPaper
|
|
|
|
|
|
|
|
import org.bukkit.Server
|
|
|
|
import org.bukkit.Server
|
|
|
|
import org.bukkit.event.EventHandler
|
|
|
|
import org.bukkit.event.EventHandler
|
|
|
|
import org.bukkit.event.Listener
|
|
|
|
import org.bukkit.event.Listener
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent
|
|
|
|
import org.bukkit.event.world.WorldSaveEvent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server: Server) : Listener {
|
|
|
|
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
|
|
|
|
private var playerPaused = false
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -18,21 +19,15 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@EventHandler
|
|
|
|
@EventHandler
|
|
|
|
fun onPlayerQuit(event: PlayerQuitEvent) {
|
|
|
|
fun onPlayerQuit(event: PlayerQuitEvent) {
|
|
|
|
if (pauseOnJoin) {
|
|
|
|
if (server.onlinePlayers.size == pauseOnPlayerCount) {
|
|
|
|
if (server.onlinePlayers.size == 1 && server.onlinePlayers.contains(event.player) ||
|
|
|
|
if (!playerPaused) {
|
|
|
|
server.onlinePlayers.isEmpty()
|
|
|
|
if (chunkmaster.generationManager.pausedTasks.isNotEmpty()) {
|
|
|
|
) {
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("RESUME_PLAYER_LEAVE"))
|
|
|
|
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.")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
@EventHandler
|
|
|
|
fun onPlayerJoin(event: PlayerJoinEvent) {
|
|
|
|
fun onPlayerJoin(event: PlayerJoinEvent) {
|
|
|
|
if (pauseOnJoin) {
|
|
|
|
if (server.onlinePlayers.size >= pauseOnPlayerCount) {
|
|
|
|
if (server.onlinePlayers.size == 1 || server.onlinePlayers.isEmpty()) {
|
|
|
|
if (chunkmaster.generationManager.tasks.isNotEmpty()) {
|
|
|
|
if (chunkmaster.generationManager.tasks.isNotEmpty()) {
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("PAUSE_PLAYER_JOIN"))
|
|
|
|
chunkmaster.logger.info("Pausing generation tasks because of player join.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
|
|
|
chunkmaster.generationManager.pauseAll()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
playerPaused = chunkmaster.generationManager.paused
|
|
|
|
|
|
|
|
chunkmaster.generationManager.pauseAll()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|