forked from SteamWar/SteamWar
Fixes, changes and Refactors
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.tntleague.util
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
|
||||
class Area(loc1: Location, loc2: Location) {
|
||||
|
||||
val min: Location
|
||||
val max: Location
|
||||
|
||||
init {
|
||||
require(loc1.world == loc2.world) { "Locations must be in the same world" }
|
||||
this.min = loc1 min loc2
|
||||
this.max = loc1 max loc2
|
||||
}
|
||||
|
||||
operator fun contains(loc: Location): Boolean {
|
||||
return loc.world == min.world && loc.x >= min.x && loc.x <= max.x && loc.y >= min.y && loc.y <= max.y && loc.z >= min.z && loc.z <= max.z
|
||||
}
|
||||
|
||||
val blocks: Sequence<Block>
|
||||
inline get() = sequence {
|
||||
for (x in locations) {
|
||||
yield(x.block)
|
||||
}
|
||||
}
|
||||
|
||||
val locations: Sequence<Location>
|
||||
inline get() = sequence {
|
||||
for (x in min.blockX..max.blockX) {
|
||||
for (y in min.blockY..max.blockY) {
|
||||
for (z in min.blockZ..max.blockZ) {
|
||||
yield(Location(min.world, x.toDouble(), y.toDouble(), z.toDouble()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
infix fun Location.max(other: Location): Location {
|
||||
return Location(world, x.coerceAtLeast(other.x), y.coerceAtLeast(other.y), z.coerceAtLeast(other.z))
|
||||
}
|
||||
|
||||
infix fun Location.min(other: Location): Location {
|
||||
return Location(world, x.coerceAtMost(other.x), y.coerceAtMost(other.y), z.coerceAtMost(other.z))
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.tntleague.util
|
||||
|
||||
import de.steamwar.tntleague.game.TNTLeagueTeam
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.ComponentLike
|
||||
import net.kyori.adventure.text.TranslatableComponent
|
||||
import net.kyori.adventure.text.format.NamedTextColor
|
||||
import net.kyori.adventure.text.format.Style
|
||||
import net.kyori.adventure.text.format.TextDecoration
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||
import net.kyori.adventure.translation.GlobalTranslator
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.Locale
|
||||
|
||||
val prefix = Component.text("Steam").yellow()
|
||||
.append(Component.text("War").darkGray())
|
||||
.appendSpace()
|
||||
|
||||
val tntLeaguePrefix = Component.text("TNT").color(NamedTextColor.DARK_RED)
|
||||
.append(Component.text("League").color(NamedTextColor.GOLD))
|
||||
|
||||
val tntLeagueChatPrefix: Component = tntLeaguePrefix
|
||||
.append(Component.text("»").darkGray())
|
||||
.appendSpace()
|
||||
|
||||
fun TranslatableComponent.basic(): Component = tntLeagueChatPrefix.append(this.gray())
|
||||
|
||||
fun TranslatableComponent.error(): Component = tntLeagueChatPrefix.append(this.red())
|
||||
|
||||
fun TranslatableComponent.success(): Component = tntLeagueChatPrefix.append(this.green())
|
||||
|
||||
fun String.component(): Component = Component.text(this)
|
||||
|
||||
fun Component.bold(): Component = this.decorate(TextDecoration.BOLD)
|
||||
|
||||
fun String.bold(): Component = this.component().bold()
|
||||
|
||||
fun Component.yellow(): Component = this.color(NamedTextColor.YELLOW)
|
||||
|
||||
fun String.yellow(): Component = this.component().yellow()
|
||||
|
||||
fun Component.red(): Component = this.color(NamedTextColor.RED)
|
||||
|
||||
fun String.red(): Component = this.component().red()
|
||||
|
||||
fun Component.green(): Component = this.color(NamedTextColor.GREEN)
|
||||
|
||||
fun String.green(): Component = this.component().green()
|
||||
|
||||
fun Component.gray(): Component = this.color(NamedTextColor.GRAY)
|
||||
|
||||
fun String.gray(): Component = this.component().gray()
|
||||
|
||||
fun Component.darkGray(): Component = this.color(NamedTextColor.DARK_GRAY)
|
||||
|
||||
fun String.darkGray(): Component = this.component().darkGray()
|
||||
|
||||
fun Component.gold(): Component = this.color(NamedTextColor.GOLD)
|
||||
|
||||
fun translate(key: String, vararg args: ComponentLike): TranslatableComponent = Component.translatable(key, *args).decoration(TextDecoration.ITALIC, false)
|
||||
|
||||
fun Component.reset(): Component = this.style(Style.empty())
|
||||
|
||||
fun Component.colorByTeam(team: TNTLeagueTeam?) = when (team) {
|
||||
null -> this.gray()
|
||||
else -> this.color(team.color)
|
||||
}
|
||||
|
||||
fun Component.translate(locale: Locale): Component = GlobalTranslator.render(this, locale)
|
||||
|
||||
fun Component.translate(p: Player): Component = this.translate(p.locale())
|
||||
|
||||
fun Component.toLegacy(): String = LegacyComponentSerializer.legacySection().serialize(this)
|
||||
@@ -19,10 +19,13 @@
|
||||
|
||||
package de.steamwar.tntleague.util
|
||||
|
||||
import de.steamwar.kotlin.message.*
|
||||
import de.steamwar.scoreboard.ScoreboardCallback
|
||||
import de.steamwar.tntleague.colorByTeam
|
||||
import de.steamwar.tntleague.config.targetedBlocks
|
||||
import de.steamwar.tntleague.game.TNTLeagueGame
|
||||
import de.steamwar.tntleague.game.TNTLeagueTeam
|
||||
import de.steamwar.tntleague.tntLeaguePrefix
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.collections.HashMap
|
||||
@@ -43,7 +46,8 @@ data class TNTLeagueScoreboard(val p: Player): ScoreboardCallback {
|
||||
|
||||
when (val team = TNTLeagueGame.getTeam(p)) {
|
||||
is TNTLeagueTeam -> lines.add(translate("scoreboardCoins", team.coins.toString().yellow()).gray())
|
||||
else -> lines.add(translate("scoreboardCoins",
|
||||
else -> lines.add(
|
||||
translate("scoreboardCoins",
|
||||
Component.text(TNTLeagueGame.blueTeam.coins.toString()).colorByTeam(TNTLeagueGame.blueTeam)
|
||||
.append(Component.text("/").darkGray())
|
||||
.append(Component.text(TNTLeagueGame.redTeam.coins.toString()).colorByTeam(TNTLeagueGame.redTeam))
|
||||
|
||||
Reference in New Issue
Block a user