Block /msg and add info command
This commit is contained in:
parent
e4d8aaa2bc
commit
9b0544fc09
8 changed files with 105 additions and 15 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
75
src/main/kotlin/de/moritzruth/spigot_ttt/game/InfoCommand.kt
Normal file
75
src/main/kotlin/de/moritzruth/spigot_ttt/game/InfoCommand.kt
Normal file
|
@ -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<out String>): Boolean {
|
||||
if (GameManager.phase === null) {
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Zurzeit läuft kein Spiel.")
|
||||
return true
|
||||
}
|
||||
|
||||
val lines = mutableListOf<String>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -10,9 +10,14 @@ abstract class TTTClass(
|
|||
val chatColor: ChatColor,
|
||||
val defaultItems: Set<TTTItem> = 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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,13 +14,11 @@ object TTTClassManager {
|
|||
|
||||
val listeners = TTT_CLASSES.mapNotNull { it.listener }
|
||||
|
||||
fun createClassesIterator(count: Int): Iterator<TTTClass?> {
|
||||
val set: MutableSet<TTTClass?> = TTT_CLASSES.toMutableSet()
|
||||
fun createClassesIterator(count: Int): Iterator<TTTClass> {
|
||||
val set: MutableSet<TTTClass> = 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()
|
||||
}
|
||||
|
|
|
@ -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)"
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue