diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/CommandManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/CommandManager.kt index 0eb06fd..61f65c9 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/CommandManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/CommandManager.kt @@ -1,6 +1,7 @@ package de.moritzruth.spigot_ttt import de.moritzruth.spigot_ttt.game.AbortCommand +import de.moritzruth.spigot_ttt.game.InfoCommand import de.moritzruth.spigot_ttt.game.ReviveCommand import de.moritzruth.spigot_ttt.game.StartCommand import de.moritzruth.spigot_ttt.game.items.AddItemSpawnCommand @@ -13,5 +14,6 @@ object CommandManager { ReviveCommand() ResourcepackCommand() ReloadTTTConfigCommand() + InfoCommand() } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt index d305d0e..56facfa 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt @@ -26,7 +26,7 @@ import org.bukkit.event.player.* import java.util.* object GameListener : Listener { - private val BLOCKED_COMMANDS = setOf("me", "tell") + private val BLOCKED_COMMANDS = setOf("me", "tell", "msg") @EventHandler fun onPlayerJoin(event: PlayerJoinEvent) = PlayerManager.onPlayerJoin(event.player) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/InfoCommand.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/InfoCommand.kt new file mode 100644 index 0000000..53ce92a --- /dev/null +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/InfoCommand.kt @@ -0,0 +1,75 @@ +package de.moritzruth.spigot_ttt.game + +import de.moritzruth.spigot_ttt.COMMAND_RESPONSE_PREFIX +import de.moritzruth.spigot_ttt.game.players.PlayerManager +import de.moritzruth.spigot_ttt.game.players.TTTPlayer +import de.moritzruth.spigot_ttt.plugin +import de.moritzruth.spigot_ttt.utils.createTabCompleter +import org.bukkit.ChatColor +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender + +class InfoCommand: CommandExecutor { + init { + val command = plugin.getCommand("info")!! + command.tabCompleter = createTabCompleter { _, index -> + if (index == 1) PlayerManager.tttPlayers.map { it.player.name } + else null + } + command.setExecutor(this) + } + + private fun getStatus(tttPlayer: TTTPlayer) = + if (tttPlayer.alive) "${ChatColor.GREEN}Lebend" else "${ChatColor.RED}Tot" + + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (GameManager.phase === null) { + sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Zurzeit läuft kein Spiel.") + return true + } + + val lines = mutableListOf() + + if (args.count() == 1) { + val playerName = args[0] + val player = plugin.server.getPlayer(playerName) + + if (player == null) { + lines.add("$playerName ${ChatColor.RED}existiert nicht oder ist nicht online.") + } else { + val tttPlayer = TTTPlayer.of(player) + + if (tttPlayer == null) { + lines.add("$COMMAND_RESPONSE_PREFIX${ChatColor.WHITE}${player.name} ${ChatColor.RED}spielt nicht mit.") + } else { + lines.add("===== ${ChatColor.BOLD}Spielerinfo: ${player.name}${ChatColor.RESET} =====") + lines.add(" ") + lines.add("Rolle: ${tttPlayer.role.coloredDisplayName}") + lines.add("Klasse: ${tttPlayer.tttClass.coloredDisplayName}") + lines.add("Status: ${getStatus(tttPlayer)}") + lines.add(" ") + } + } + } else { + lines.add("=========== ${ChatColor.BOLD}Spielinfo${ChatColor.RESET} ===========") + lines.add(" ") + lines.add("${ChatColor.GRAY}Rolle - Klasse - Status") + + for (tttPlayer in PlayerManager.tttPlayers) { + val values = listOf( + tttPlayer.role.coloredDisplayName, + tttPlayer.tttClass.coloredDisplayName, + getStatus(tttPlayer) + ) + + lines.add("${tttPlayer.player.name}: ${values.joinToString("${ChatColor.RESET} - ")}") + } + + lines.add(" ") + } + + sender.sendMessage(lines.joinToString("\n${ChatColor.RESET}")) + return true + } +} diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClass.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClass.kt index 18708a0..6cbf5a6 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClass.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClass.kt @@ -10,9 +10,14 @@ abstract class TTTClass( val chatColor: ChatColor, val defaultItems: Set = emptySet() ) { - val coloredDisplayName = "$chatColor${ChatColor.BOLD}$displayName" + val coloredDisplayName = "$chatColor$displayName" open val listener: Listener? = null open fun onInit(tttPlayer: TTTPlayer) {} + + object None: TTTClass( + "Keine", + ChatColor.GRAY + ) } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClassManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClassManager.kt index fc57b96..d23f6fa 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClassManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/TTTClassManager.kt @@ -14,13 +14,11 @@ object TTTClassManager { val listeners = TTT_CLASSES.mapNotNull { it.listener } - fun createClassesIterator(count: Int): Iterator { - val set: MutableSet = TTT_CLASSES.toMutableSet() + fun createClassesIterator(count: Int): Iterator { + val set: MutableSet = TTT_CLASSES.toMutableSet() val playersWithoutClass = count - TTT_CLASSES.size - if (playersWithoutClass > 0) { - set.addAll(Collections.nCopies(playersWithoutClass, null)) - } + if (playersWithoutClass > 0) set.addAll(Collections.nCopies(playersWithoutClass, TTTClass.None)) return set.shuffled().iterator() } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt index fda20ac..27f34fa 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt @@ -17,7 +17,7 @@ import org.bukkit.* import org.bukkit.entity.Player import kotlin.properties.Delegates -class TTTPlayer(player: Player, role: Role, val tttClass: TTTClass?) { +class TTTPlayer(player: Player, role: Role, val tttClass: TTTClass = TTTClass.None) { var alive = true var player by Delegates.observable(player) { _, _, _ -> adjustPlayer() } @@ -50,7 +50,7 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClass?) { init { adjustPlayer() scoreboard.initialize() - tttClass?.onInit(this) + tttClass.onInit(this) } private fun onItemInHandChanged(oldItem: TTTItem?, newItem: TTTItem?) { @@ -248,7 +248,7 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClass?) { updateItemInHand() } - fun addDefaultClassItems() = tttClass?.defaultItems?.forEach { addItem(it) } + fun addDefaultClassItems() = tttClass.defaultItems.forEach { addItem(it) } override fun toString() = "TTTPlayer(${player.name} is $role)" diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt index 1452d85..666cbcb 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt @@ -3,6 +3,7 @@ package de.moritzruth.spigot_ttt.game.players import de.moritzruth.spigot_ttt.game.GameManager import de.moritzruth.spigot_ttt.game.GamePhase import de.moritzruth.spigot_ttt.game.Timers +import de.moritzruth.spigot_ttt.game.classes.TTTClass import de.moritzruth.spigot_ttt.plugin import org.bukkit.ChatColor import org.bukkit.scoreboard.DisplaySlot @@ -53,10 +54,10 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) { } scoreboard.registerNewObjective( - ACTIVE_WITH_CREDITS_OBJECTIVE, - "dummy", - "${ChatColor.GOLD}TTT", - RenderType.INTEGER + ACTIVE_WITH_CREDITS_OBJECTIVE, + "dummy", + "${ChatColor.GOLD}TTT", + RenderType.INTEGER ).apply { val lines = mutableListOf( " ".repeat(20), @@ -85,7 +86,11 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) { setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER) } - setValue(ValueTeam.CLASS, "Klasse: ${tttPlayer.tttClass?.coloredDisplayName ?: "${ChatColor.GRAY}Keine"}") + val classDisplayName = + if (tttPlayer.tttClass == TTTClass.None) TTTClass.None.coloredDisplayName + else "${tttPlayer.tttClass.chatColor}${ChatColor.BOLD}${tttPlayer.tttClass.displayName}" + + setValue(ValueTeam.CLASS, "Klasse: $classDisplayName") updateEverything() showCorrectSidebarScoreboard() diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3238dee..ba44b18 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,11 @@ commands: permission: ttt.revive description: Revive yourself or another player at the world spawn or at your location + info: + usage: /info [player] + permission: ttt.info + description: Show information about all players or a specific player + resourcepack: usage: /rp description: Start the download of the TTT resourcepack, required for sounds