Restructure config.yml and add central Settings.kt
This commit is contained in:
parent
18be6263db
commit
ce133148f7
14 changed files with 123 additions and 69 deletions
|
@ -12,5 +12,6 @@ object CommandManager {
|
|||
AddItemSpawnCommand()
|
||||
ReviveCommand()
|
||||
ResourcepackCommand()
|
||||
ReloadTTTConfigCommand()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package de.moritzruth.spigot_ttt
|
||||
|
||||
import de.moritzruth.spigot_ttt.utils.EmptyTabCompleter
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class ReloadTTTConfigCommand: CommandExecutor {
|
||||
init {
|
||||
val command = plugin.getCommand("reloadtttconfig")!!
|
||||
command.tabCompleter = EmptyTabCompleter
|
||||
command.setExecutor(this)
|
||||
}
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
plugin.reloadConfig()
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.GREEN}Die Konfiguration wurde neu geladen.")
|
||||
return true
|
||||
}
|
||||
}
|
18
src/main/kotlin/de/moritzruth/spigot_ttt/Settings.kt
Normal file
18
src/main/kotlin/de/moritzruth/spigot_ttt/Settings.kt
Normal file
|
@ -0,0 +1,18 @@
|
|||
package de.moritzruth.spigot_ttt
|
||||
|
||||
enum class JackalMode {
|
||||
ALWAYS,
|
||||
HALF_TIME,
|
||||
NEVER
|
||||
}
|
||||
|
||||
object Settings {
|
||||
val jackalMode get() = JackalMode.valueOf(plugin.config.getString("roles.jackal.mode", JackalMode.HALF_TIME.toString())!!)
|
||||
val minPlayers get() = plugin.config.getInt("min-players", 4)
|
||||
val detectiveEnabled get() = plugin.config.getBoolean("roles.detective.enabled", true)
|
||||
val preparingPhaseDuration get() = plugin.config.getInt("duration.preparing", 20)
|
||||
val combatPhaseDuration get() = plugin.config.getInt("duration.combat", 480) // 8 minutes
|
||||
val overPhaseDuration get() = plugin.config.getInt("duration.over", 10)
|
||||
val initialCredits get() = plugin.config.getInt("initial-credits", 2)
|
||||
val creditsPerKill get() = plugin.config.getInt("credits-per-kill", 1)
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package de.moritzruth.spigot_ttt
|
||||
|
||||
import de.moritzruth.spigot_ttt.game.players.PlayerManager
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.utils.isLeftClick
|
||||
import de.moritzruth.spigot_ttt.utils.isRightClick
|
||||
import org.bukkit.entity.Player
|
||||
|
@ -31,8 +30,13 @@ open class TTTItemListener(private val tttItem: TTTItem, private val cancelDamag
|
|||
else if (event.action.isLeftClick) onLeftClick(data)
|
||||
}
|
||||
|
||||
open fun onRightClick(data: ClickEventData) {}
|
||||
open fun onLeftClick(data: ClickEventData) {}
|
||||
open fun onRightClick(data: ClickEventData) {
|
||||
data.event.isCancelled = false
|
||||
}
|
||||
|
||||
open fun onLeftClick(data: ClickEventData) {
|
||||
data.event.isCancelled = false
|
||||
}
|
||||
|
||||
protected fun handle(event: PlayerInteractEvent, handler: (tttPlayer: TTTPlayer) -> Unit) {
|
||||
if (event.item?.type == tttItem.itemStack.type) {
|
||||
|
|
|
@ -3,11 +3,14 @@ package de.moritzruth.spigot_ttt
|
|||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.Action
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.block.BlockPlaceEvent
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerQuitEvent
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent
|
||||
|
@ -27,6 +30,15 @@ object TTTListener: Listener {
|
|||
if (event.player.gameMode !== GameMode.CREATIVE) event.isCancelled = true
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockBreak(event: PlayerInteractEvent) {
|
||||
if (
|
||||
event.player.gameMode != GameMode.CREATIVE &&
|
||||
event.action == Action.PHYSICAL &&
|
||||
event.clickedBlock?.type == Material.FARMLAND
|
||||
) event.isCancelled = true
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerJoin(event: PlayerJoinEvent) {
|
||||
val player = event.player
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.game
|
||||
|
||||
import de.moritzruth.spigot_ttt.Settings
|
||||
import de.moritzruth.spigot_ttt.game.corpses.CorpseListener
|
||||
import de.moritzruth.spigot_ttt.game.corpses.CorpseManager
|
||||
import de.moritzruth.spigot_ttt.game.items.ItemManager
|
||||
|
@ -36,14 +37,13 @@ object GameManager {
|
|||
GameMessenger.win(role)
|
||||
phase = GamePhase.OVER
|
||||
Timers.cancelCurrentTask()
|
||||
Shop.stopCreditsTimer()
|
||||
ScoreboardHelper.forEveryScoreboard { it.updateTeams() }
|
||||
|
||||
PlayerManager.tttPlayers.forEach {
|
||||
Shop.clear(it)
|
||||
}
|
||||
|
||||
Timers.startOverPhaseTimer(plugin.config.getInt("duration.over", 10)) {
|
||||
Timers.startOverPhaseTimer {
|
||||
GameEndEvent(false).call()
|
||||
|
||||
phase = null
|
||||
|
@ -95,7 +95,6 @@ object GameManager {
|
|||
Timers.cancelCurrentTask()
|
||||
resetWorld()
|
||||
PlayerManager.resetAfterGame()
|
||||
Shop.stopCreditsTimer()
|
||||
|
||||
if (broadcast) {
|
||||
GameMessenger.aborted()
|
||||
|
@ -105,7 +104,7 @@ object GameManager {
|
|||
fun startPreparingPhase() {
|
||||
ensurePhase(null)
|
||||
|
||||
if (PlayerManager.availablePlayers.count() < plugin.config.getInt("min-players", 4)) {
|
||||
if (PlayerManager.availablePlayers.count() < Settings.minPlayers) {
|
||||
throw NotEnoughPlayersException()
|
||||
}
|
||||
|
||||
|
@ -129,7 +128,7 @@ object GameManager {
|
|||
Timers.playTimerSound()
|
||||
ItemSpawner.spawnWeapons()
|
||||
|
||||
Timers.startPreparingPhaseTimer(plugin.config.getInt("duration.preparing", 20)) {
|
||||
Timers.startPreparingPhaseTimer {
|
||||
startCombatPhase()
|
||||
}
|
||||
}
|
||||
|
@ -140,12 +139,11 @@ object GameManager {
|
|||
phase = GamePhase.COMBAT
|
||||
PlayerManager.tttPlayers.forEach { Shop.setItems(it) }
|
||||
ScoreboardHelper.forEveryScoreboard { it.updateTeams() }
|
||||
Shop.startCreditsTimer()
|
||||
|
||||
Timers.playTimerSound()
|
||||
GameMessenger.combatPhaseStarted()
|
||||
|
||||
Timers.startCombatPhaseTimer(plugin.config.getInt("duration.combat", 480)) {
|
||||
Timers.startCombatPhaseTimer {
|
||||
if (PlayerManager.stillLivingRoles.contains(Role.INNOCENT)) {
|
||||
letRoleWin(Role.INNOCENT)
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.game
|
||||
|
||||
import de.moritzruth.spigot_ttt.Settings
|
||||
import de.moritzruth.spigot_ttt.game.players.PlayerManager
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.secondsToTicks
|
||||
|
@ -17,8 +18,8 @@ object Timers {
|
|||
bukkitTask = null
|
||||
}
|
||||
|
||||
fun startPreparingPhaseTimer(duration: Int, onFinished: () -> Unit) {
|
||||
runCountdown(duration, onFinished) { remainingSeconds ->
|
||||
fun startPreparingPhaseTimer(onFinished: () -> Unit) {
|
||||
runCountdown(Settings.preparingPhaseDuration, onFinished) { remainingSeconds ->
|
||||
when (remainingSeconds) {
|
||||
in 1..5, 10, 30 -> {
|
||||
playTimerSound()
|
||||
|
@ -28,8 +29,8 @@ object Timers {
|
|||
}
|
||||
}
|
||||
|
||||
fun startCombatPhaseTimer(duration: Int, onFinished: () -> Unit) {
|
||||
runCountdown(duration, onFinished) { remainingSeconds ->
|
||||
fun startCombatPhaseTimer(onFinished: () -> Unit) {
|
||||
runCountdown(Settings.combatPhaseDuration, onFinished) { remainingSeconds ->
|
||||
if (remainingSeconds % 60 == 0) {
|
||||
playTimerSound()
|
||||
GameMessenger.remainingRoundTime(remainingSeconds / 60)
|
||||
|
@ -37,8 +38,8 @@ object Timers {
|
|||
}
|
||||
}
|
||||
|
||||
fun startOverPhaseTimer(duration: Int, onFinished: () -> Unit) {
|
||||
runCountdown(duration, onFinished) {}
|
||||
fun startOverPhaseTimer(onFinished: () -> Unit) {
|
||||
runCountdown(Settings.overPhaseDuration, onFinished) {}
|
||||
}
|
||||
|
||||
fun playTimerSound() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.game.items
|
||||
|
||||
import de.moritzruth.spigot_ttt.COMMAND_RESPONSE_PREFIX
|
||||
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.EmptyTabCompleter
|
||||
import org.bukkit.ChatColor
|
||||
|
@ -25,7 +24,7 @@ class AddItemSpawnCommand: CommandExecutor {
|
|||
}
|
||||
|
||||
ItemSpawner.addItemSpawnLocation(sender.location)
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${TTTPlugin.prefix}${ChatColor.GREEN}Ein Waffenspawn wurde an deiner Position hinzugefügt.")
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.GREEN}Ein Waffenspawn wurde an deiner Position hinzugefügt.")
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package de.moritzruth.spigot_ttt.game.items.shop
|
||||
|
||||
import com.connorlinfoot.actionbarapi.ActionBarAPI
|
||||
import de.moritzruth.spigot_ttt.game.players.PlayerManager
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.items.Buyable
|
||||
import de.moritzruth.spigot_ttt.game.items.ItemManager
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.utils.applyMeta
|
||||
import de.moritzruth.spigot_ttt.utils.secondsToTicks
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
|
||||
object Shop {
|
||||
val SHOP_SLOTS = (9..35).toMutableList().apply {
|
||||
|
@ -21,8 +16,6 @@ object Shop {
|
|||
}.toList()
|
||||
private val ITEMS_PER_PAGE = SHOP_SLOTS.count()
|
||||
|
||||
private var creditsTimer: BukkitTask? = null
|
||||
|
||||
private fun getBuyableItems(tttPlayer: TTTPlayer) = ItemManager.ITEMS.filter { it is Buyable && it.buyableBy.contains(tttPlayer.role) }.toSet()
|
||||
|
||||
fun setItems(tttPlayer: TTTPlayer) {
|
||||
|
@ -49,22 +42,6 @@ object Shop {
|
|||
for(index in 9..35) tttPlayer.player.inventory.clear(index) // All slots except the hotbar and armor
|
||||
}
|
||||
|
||||
fun startCreditsTimer() {
|
||||
val firstCreditsAfter = plugin.config.getInt("first-credits-after")
|
||||
val interval = plugin.config.getInt("credits-interval")
|
||||
|
||||
creditsTimer = plugin.server.scheduler.runTaskTimer(plugin, fun() {
|
||||
PlayerManager.tttPlayers.filter { it.alive && it.role.canOwnCredits }.forEach {
|
||||
it.credits += 1
|
||||
ActionBarAPI.sendActionBar(it.player, "${ChatColor.GREEN}Du hast einen Credit erhalten")
|
||||
}
|
||||
}, secondsToTicks(firstCreditsAfter).toLong(), secondsToTicks(interval).toLong())
|
||||
}
|
||||
|
||||
fun stopCreditsTimer() {
|
||||
creditsTimer?.cancel()
|
||||
}
|
||||
|
||||
fun isOutOfStock(tttPlayer: TTTPlayer, tttItem: TTTItem): Boolean {
|
||||
if (tttItem !is Buyable) throw Error("Item is not buyable")
|
||||
return tttItem.buyLimit != null && tttPlayer.boughtItems.filter { it == tttItem }.count() >= tttItem.buyLimit!!
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package de.moritzruth.spigot_ttt.game.items.shop
|
||||
|
||||
import com.connorlinfoot.actionbarapi.ActionBarAPI
|
||||
import de.moritzruth.spigot_ttt.Settings
|
||||
import de.moritzruth.spigot_ttt.game.items.Buyable
|
||||
import de.moritzruth.spigot_ttt.game.items.ItemManager
|
||||
import de.moritzruth.spigot_ttt.game.players.PlayerManager
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayerDeathEvent
|
||||
import de.moritzruth.spigot_ttt.game.items.Buyable
|
||||
import de.moritzruth.spigot_ttt.game.items.ItemManager
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.entity.Player
|
||||
|
@ -69,8 +70,8 @@ object ShopListener: Listener {
|
|||
PlayerManager.tttPlayers
|
||||
.filter { it.role.canOwnCredits && it.role.group == killer.role.group }
|
||||
.forEach {
|
||||
it.credits += 1
|
||||
ActionBarAPI.sendActionBar(it.player, "${ChatColor.GREEN}Du hast einen Credit erhalten")
|
||||
it.credits += Settings.creditsPerKill
|
||||
ActionBarAPI.sendActionBar(it.player, "${ChatColor.GREEN}Du hast ${Settings.creditsPerKill} Credit(s) erhalten")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.moritzruth.spigot_ttt.game.players
|
||||
|
||||
import de.moritzruth.spigot_ttt.JackalMode
|
||||
import de.moritzruth.spigot_ttt.Settings
|
||||
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.GameMessenger
|
||||
|
@ -11,6 +13,7 @@ import de.moritzruth.spigot_ttt.utils.teleportPlayerToWorldSpawn
|
|||
import org.bukkit.ChatColor
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.random.Random
|
||||
|
||||
object PlayerManager {
|
||||
val tttPlayers= mutableListOf<TTTPlayer>()
|
||||
|
@ -91,26 +94,33 @@ object PlayerManager {
|
|||
|
||||
fun createTTTPlayers() {
|
||||
val playersWithoutRole = availablePlayers.toMutableSet()
|
||||
|
||||
val playerCount = playersWithoutRole.count()
|
||||
val traitorCount: Int = if (playerCount <= 4) 1 else playerCount / 4
|
||||
|
||||
if (playerCount >= plugin.config.getInt("min-players-for.detective", 5)) {
|
||||
val player = playersWithoutRole.random()
|
||||
tttPlayers.add(TTTPlayer(player, Role.DETECTIVE))
|
||||
playersWithoutRole.remove(player)
|
||||
}
|
||||
|
||||
if (playerCount >= plugin.config.getInt("min-players-for.jackal", 6)) {
|
||||
val player = playersWithoutRole.random()
|
||||
tttPlayers.add(TTTPlayer(player, Role.JACKAL))
|
||||
playersWithoutRole.remove(player)
|
||||
}
|
||||
var playersWithoutRoleCount = playersWithoutRole.count()
|
||||
val traitorCount: Int = if (playersWithoutRoleCount <= 4) 1 else playersWithoutRoleCount / 4
|
||||
|
||||
for (index in 1..traitorCount) {
|
||||
val player = playersWithoutRole.random()
|
||||
tttPlayers.add(TTTPlayer(player, Role.TRAITOR))
|
||||
playersWithoutRole.remove(player)
|
||||
playersWithoutRoleCount--
|
||||
}
|
||||
|
||||
if (playersWithoutRoleCount < 1 && Settings.detectiveEnabled) {
|
||||
val player = playersWithoutRole.random()
|
||||
tttPlayers.add(TTTPlayer(player, Role.DETECTIVE))
|
||||
playersWithoutRole.remove(player)
|
||||
playersWithoutRoleCount--
|
||||
}
|
||||
|
||||
if (playersWithoutRoleCount < 1 && when (Settings.jackalMode) {
|
||||
JackalMode.ALWAYS -> true
|
||||
JackalMode.HALF_TIME -> Random.Default.nextBoolean()
|
||||
JackalMode.NEVER -> false
|
||||
}) {
|
||||
val player = playersWithoutRole.random()
|
||||
tttPlayers.add(TTTPlayer(player, Role.JACKAL))
|
||||
playersWithoutRole.remove(player)
|
||||
@Suppress("UNUSED_CHANGED_VALUE")
|
||||
playersWithoutRoleCount--
|
||||
}
|
||||
|
||||
playersWithoutRole.forEach { tttPlayers.add(TTTPlayer(it, Role.INNOCENT)) }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.moritzruth.spigot_ttt.game.players
|
||||
|
||||
import de.moritzruth.spigot_ttt.Resourcepack
|
||||
import de.moritzruth.spigot_ttt.Settings
|
||||
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.game.GamePhase
|
||||
|
@ -36,7 +37,7 @@ class TTTPlayer(player: Player, role: Role) {
|
|||
var itemInHand by Delegates.observable<TTTItem?>(null) { _, oldItem, newItem ->
|
||||
if (oldItem !== newItem) onItemInHandChanged(oldItem, newItem)
|
||||
}
|
||||
var credits by Delegates.observable(10) { _, _, _ -> scoreboard.updateCredits() }
|
||||
var credits by Delegates.observable(Settings.initialCredits) { _, _, _ -> scoreboard.updateCredits() }
|
||||
val boughtItems = mutableListOf<TTTItem>()
|
||||
|
||||
var invisible by Delegates.observable(false) { _, _, value ->
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
min-players: 4
|
||||
min-players-for:
|
||||
detective: 5
|
||||
jackal: 6
|
||||
|
||||
roles:
|
||||
jackal:
|
||||
mode: HALF_TIME
|
||||
|
||||
detective:
|
||||
enabled: true
|
||||
|
||||
duration:
|
||||
preparing: 20
|
||||
combat: 480
|
||||
over: 10
|
||||
|
||||
first-credits-after: 5
|
||||
credits-interval: 10
|
||||
initial-credits: 2
|
||||
credits-per-kill: 1
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
name: TTT
|
||||
version: 1.0.0
|
||||
author: Moritz Ruth
|
||||
api-version: "1.14"
|
||||
main: de.moritzruth.spigot_ttt.TTTPlugin
|
||||
depend:
|
||||
|
@ -23,7 +24,7 @@ commands:
|
|||
description: Add an item spawn
|
||||
|
||||
revive:
|
||||
usage: /revive [Player] [here]
|
||||
usage: /revive [player] ['here']
|
||||
permission: ttt.revive
|
||||
description: Revive yourself or another player at the world spawn or at your location
|
||||
|
||||
|
@ -34,3 +35,9 @@ commands:
|
|||
- rp
|
||||
- resources
|
||||
|
||||
reloadtttconfig:
|
||||
usage: /rt
|
||||
description: Reload the configuration of TTT
|
||||
permission: ttt.reload
|
||||
aliases:
|
||||
- rt
|
||||
|
|
Reference in a new issue