<commit_before>package com.freundtech.minecraft.oneslotserver.handler.event

import com.freundtech.minecraft.oneslotserver.OneSlotServer
import com.freundtech.minecraft.oneslotserver.extension.*
import com.freundtech.minecraft.oneslotserver.util.*

import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.*
import org.bukkit.event.player.PlayerLoginEvent.Result

class PlayerListener(private val plugin: OneSlotServer) : Listener {
    @EventHandler
    fun onPlayerLogin(event: PlayerLoginEvent) {
        val now = currentTime()
        val playerInfo = event.player.oneSlotServer
        val activePlayer = plugin.activePlayer

        event.player.oneSlotServer.join()

        if (!playerInfo.hasTimeRemaining()) {
            val waitLeft = plugin.waitTime - (now - playerInfo.firstJoin)

            if (!event.player.hasPermission(PERMISSION_SPECTATE)) {
                event.disallow(Result.KICK_OTHER,
                        "You have no time left on this server. Please wait ${waitLeft.format()}.")
            }
        } else if (activePlayer != null) {
            val waitLeft = activePlayer.oneSlotServer.timeLeft

            if (!event.player.hasPermission(PERMISSION_SPECTATE)) {
                event.disallow(Result.KICK_FULL,
                        "A person is already playing. Please wait ${waitLeft.format()}.")
            }
        }
        if (event.result == Result.ALLOWED) {
            plugin.activePlayer = event.player
            event.player.loadFromSharedData()

        }
    }

    @EventHandler
    fun onPlayerJoin(event: PlayerJoinEvent) {
        event.joinMessage = ""

        if (plugin.activePlayer?.uniqueId == event.player.uniqueId) {
            event.player.isSleepingIgnored = false

            if (!event.player.hasPermission(PERMISSION_SEE_SPECTATORS)) {
                plugin.server.onlinePlayers.filter {
                    event.player.uniqueId != it.uniqueId
                }.forEach {
                    event.player.hidePlayer(plugin, it)
                }
            }

            event.player.apply {
                sendMessage(arrayOf(
                        "Welcome to the one slot server.",
                        "You have ${oneSlotServer.timeLeft.format()} left to play."
                ))
            }
        } else if (event.player.hasPermission(PERMISSION_SPECTATE)) {
            event.player.setSpectator()
            if (plugin.activePlayer?.hasPermission(PERMISSION_SEE_SPECTATORS) == false) {
                plugin.activePlayer?.hidePlayer(plugin, event.player)
            }
        }
    }

    @EventHandler
    fun onPlayerQuit(event: PlayerQuitEvent) {
        event.quitMessage = ""

        if (plugin.activePlayer?.uniqueId == event.player.uniqueId) {
            event.player.saveToSharedData()
            plugin.activePlayer = null
        }
        event.player.oneSlotServer.save()
    }
}
<commit_msg>Fixed broken spectator mode after last commit<commit_after>package com.freundtech.minecraft.oneslotserver.handler.event

import com.freundtech.minecraft.oneslotserver.OneSlotServer
import com.freundtech.minecraft.oneslotserver.extension.*
import com.freundtech.minecraft.oneslotserver.util.*

import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.*
import org.bukkit.event.player.PlayerLoginEvent.Result

class PlayerListener(private val plugin: OneSlotServer) : Listener {
    @EventHandler
    fun onPlayerLogin(event: PlayerLoginEvent) {
        val now = currentTime()
        val playerInfo = event.player.oneSlotServer
        val activePlayer = plugin.activePlayer

        event.player.oneSlotServer.join()

        if (!playerInfo.hasTimeRemaining()) {
            val waitLeft = plugin.waitTime - (now - playerInfo.firstJoin)

            if (!event.player.hasPermission(PERMISSION_SPECTATE)) {
                event.disallow(Result.KICK_OTHER,
                        "You have no time left on this server. Please wait ${waitLeft.format()}.")
            }
        } else if (activePlayer != null) {
            val waitLeft = activePlayer.oneSlotServer.timeLeft

            if (!event.player.hasPermission(PERMISSION_SPECTATE)) {
                event.disallow(Result.KICK_FULL,
                        "A person is already playing. Please wait ${waitLeft.format()}.")
            }
        }
        else if (event.result == Result.ALLOWED) {
            plugin.activePlayer = event.player
            event.player.loadFromSharedData()

        }
    }

    @EventHandler
    fun onPlayerJoin(event: PlayerJoinEvent) {
        event.joinMessage = ""

        if (plugin.activePlayer?.uniqueId == event.player.uniqueId) {
            event.player.isSleepingIgnored = false

            if (!event.player.hasPermission(PERMISSION_SEE_SPECTATORS)) {
                plugin.server.onlinePlayers.filter {
                    event.player.uniqueId != it.uniqueId
                }.forEach {
                    event.player.hidePlayer(plugin, it)
                }
            }

            event.player.apply {
                sendMessage(arrayOf(
                        "Welcome to the one slot server.",
                        "You have ${oneSlotServer.timeLeft.format()} left to play."
                ))
            }
        } else if (event.player.hasPermission(PERMISSION_SPECTATE)) {
            event.player.setSpectator()
            if (plugin.activePlayer?.hasPermission(PERMISSION_SEE_SPECTATORS) == false) {
                plugin.activePlayer?.hidePlayer(plugin, event.player)
            }
        }
    }

    @EventHandler
    fun onPlayerQuit(event: PlayerQuitEvent) {
        event.quitMessage = ""

        if (plugin.activePlayer?.uniqueId == event.player.uniqueId) {
            event.player.saveToSharedData()
            plugin.activePlayer = null
        }
        event.player.oneSlotServer.save()
    }
}

{'fraction_non_alphanumeric': 0.09651925340507819, 'fraction_numerical': 0.0, 'mean_word_length': 2.065979381443299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '683874', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1582, 'n_words': 275}