From 055e44c802c1941a59d55dfcaa4881e6073e5ce7 Mon Sep 17 00:00:00 2001 From: Trilleo Date: Fri, 18 Sep 2026 12:47:20 +0800 Subject: [PATCH 1/4] Feature: Add price line to most related menu icons --- CHANGELOG.md | 39 +++++++ CLAUDE.md | 4 +- README.md | 3 +- docs/DEVELOPER_GUIDE.md | 10 +- docs/UTILITY_GUIDE.md | 38 +++++++ .../plugins/townymenu/guis/common/Pickers.kt | 7 +- .../plugins/townymenu/guis/framework/Menu.kt | 15 +++ .../townymenu/guis/nation/NationInfoMenu.kt | 8 +- .../townymenu/guis/nation/NationMenu.kt | 8 +- .../guis/nation/NationSettingsMenu.kt | 11 +- .../townymenu/guis/nation/NoNationMenu.kt | 5 +- .../plugins/townymenu/guis/plot/PlotMenu.kt | 20 ++-- .../townymenu/guis/resident/ResidentMenu.kt | 6 +- .../plugins/townymenu/guis/town/NoTownMenu.kt | 10 +- .../townymenu/guis/town/OutpostsMenu.kt | 8 +- .../townymenu/guis/town/TownClaimsMenu.kt | 47 ++++++-- .../townymenu/guis/town/TownInfoMenu.kt | 13 +-- .../plugins/townymenu/guis/town/TownMenu.kt | 20 ++-- .../townymenu/guis/town/TownSettingsMenu.kt | 10 +- .../mc/plugins/townymenu/utils/Prices.kt | 105 ++++++++++++++++++ src/main/resources/lang/en_US.yml | 3 +- src/main/resources/lang/zh_CN.yml | 3 +- 22 files changed, 327 insertions(+), 66 deletions(-) create mode 100644 src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/Prices.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5745726..1d94ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,45 @@ ## Unreleased +### Improvements + +#### Town Menu + ++ Claiming, unclaiming, filling gaps, and taking over a claim now show what this server charges — or refunds — per + chunk, and Claim Outpost shows the outpost price. ++ Go to Spawn and Outposts show what the trip costs you, and each outpost in the outpost list shows it too. ++ Reclaiming ruins no longer shows a cost line on servers where reclaiming is free. ++ Renaming a town and changing its map colour show their cost. ++ Visiting another town shows what it will actually charge you, which depends on whether you are a resident, a nation + member, an ally, or an outsider. Merging another town into yours shows what the merge costs. + +#### Nation Menu + ++ Go to Spawn and visiting another nation show what the trip costs you. ++ Renaming a nation, changing its map colour, and moving the capital show their cost. + +#### Plot Menu + ++ Claiming the wilderness you stand in shows the claim price, and Claim as Outpost shows the outpost price. ++ Change Plot Type now shows what each type costs, multiplied across the group when the plot is in one. + +#### Resident Menu + ++ Go to Spawn shows what the trip costs you. + +#### Misc + ++ Prices are hidden on servers with no economy, and free actions no longer carry an empty cost line. + +### Technical Details + +#### Misc + ++ Added a `Prices` utility that works out what a menu action costs — claims, outposts, spawn travel, plot types, town + merges — from Towny's config and the town or nation involved, and `Menu.costLine` / `Menu.priceLine` to turn an + amount into lore. ++ `Pickers.option` takes a `lines` lambda for per-option lore. + ## Version 1.0.0 ### New Features diff --git a/CLAUDE.md b/CLAUDE.md index ba518d3..20dce09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -77,7 +77,7 @@ src/main/kotlin/net/trilleo/mc/plugins/townymenu/ │ └── MainMenu.kt, MapMenu.kt, InvitesMenu.kt ├── listeners/ # Event listeners (auto-registered) ├── registration/ # Auto-registration engine (do not modify lightly) -└── utils/ # itemStack DSL, Lang, TownyUtil, TownyConfig, DialogUtil, MessageUtil, LoreUtil +└── utils/ # itemStack DSL, Lang, TownyUtil, Prices, TownyConfig, DialogUtil, MessageUtil, LoreUtil src/main/resources/ ├── config.yml plugin.yml └── lang/ # en_US.yml, zh_CN.yml — every player-facing string @@ -115,6 +115,8 @@ Extend `Menu` (or `PagedMenu` for lists) and implement `build()`, which runs on - **Keep the tutorial in sync** — a new or changed Towny feature updates its lesson in `guis/tutorial/Tutorial.kt`, and a new feature menu gets a `tutorialButton` for its chapter. - **Keep `PagedMenu` entries lazy** — pass the icon as a lambda to `MenuEntry` so off-page icons are never built. +- **Show what a button costs** — a button that spends money takes its amount from `Prices` and turns it into lore with + `costLine(...)` / `priceLine(...)`, so the figure is this server's and not a guess. ## Translations diff --git a/README.md b/README.md index 7b7fc2b..8685cc3 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ - **Status pages** — Click your town or nation to see its level, what the next level needs, its limits, the daily upkeep, and warnings for debt, ruins, conquest, and overclaiming. - **Leaderboards and prices** — Rank towns, nations, and players by residents, land, and money, and see every price on - the server with a countdown to the next Towny day. + the server with a countdown to the next Towny day. Buttons that spend money show their own price too, so you know + what a claim, a teleport, or a plot costs before you click it. - **Directories** — Browse and rank every town and nation by residents, claims, bank balance, distance, and more; visit, join, donate, buy a town that is for sale, or propose alliances. - **Invites** — Accept or decline town invites, nation invites for your town, and alliance requests in one place, or diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index 3e359da..4c23ae6 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -281,6 +281,9 @@ permissions, bank, ranks, pickers) in `guis/common`, and feature menus in `guis/ can't intercept the command. - **Grey out what the player can't do.** Use `guarded(slot, PermissionNodes.X, item) { … }` (or `Layout.add(node, …)`) with the same node Towny's command checks. +- **Say what a button costs.** A button that spends money shows its price in its lore: take the amount from + [`Prices`](UTILITY_GUIDE.md#prices) and turn it into a line with `costLine` / `priceLine`, so the figure is the + server's own and not a guess. - **Keep an empty row above the bottom row.** The back button, tutorial button, and page controls sit in the bottom row; leave the row above it empty so they stand apart from the menu's content. Only grids that need every row, such as the chunk map and the 4×4 permission grid, skip it. @@ -305,6 +308,8 @@ open inventory's holder — there is no registry and nothing to clean up when a | `layout(vararg slots)` | Fills slots in order, for optional buttons; extra buttons are logged, skipped. | | `backButton(slot)` | Back arrow to `back`, or a close button when `back` is `null`. | | `tutorialButton(slot, chapter)` | Help button opening the tutorial `Chapter` that explains this menu. | +| `costLine(amount)` | A `Cost: …` lore line, or `null` without an economy or when the action is free. | +| `priceLine(amount)` | A `Price: …` lore line for something on sale; a price of zero is still shown. | | `run(command, probe?, returnTo?, delay)` | Runs a Towny command as the player (see below). | | `runAndClose(command)` | Closes the menu, then runs the command (teleports, books, chat output). | | `prompt(title, label, …) { text -> }` | Shows a text-input dialog; Cancel or empty input reopens the menu. | @@ -355,7 +360,7 @@ override fun entries(): List = | `PermissionMenu` | 4×4 build/destroy/switch/item-use grid for any `set perm` command. Pass `overrides` to add a Player Overrides button (used for plots). | | `BankMenu` | Deposit, withdraw, and bank history for a town or nation. | | `RankMenu` | Grants or revokes town or nation ranks, checking the per-rank permission node. | -| `Pickers` | Selection menus for online residents, towns, nations, and fixed options. | +| `Pickers` | Selection menus for online residents, towns, nations, and fixed options. `option` takes a `lines` lambda for per-option lore, such as what picking that option costs. | ### Tutorial (`guis/tutorial`) @@ -1066,7 +1071,8 @@ player.sendPlayerListHeaderAndFooter(Component.empty(), Component.empty()) ## Utilities The `utils` package (`net.trilleo.mc.plugins.townymenu.utils`) contains the `itemStack` DSL, `LoreUtil`, `MessageUtil`, -`TownyUtil`, `TownyConfig`, and `DialogUtil`. See the [Utility Guide](UTILITY_GUIDE.md) for full documentation. +`TownyUtil`, `Prices`, `TownyConfig`, and `DialogUtil`. See the [Utility Guide](UTILITY_GUIDE.md) for full +documentation. --- diff --git a/docs/UTILITY_GUIDE.md b/docs/UTILITY_GUIDE.md index 9b8db7f..fd7277a 100644 --- a/docs/UTILITY_GUIDE.md +++ b/docs/UTILITY_GUIDE.md @@ -7,6 +7,7 @@ This guide covers the utility helpers provided in `net.trilleo.mc.plugins.townym | `itemStack` | DSL builder for menu icons | | `Lang` | Translations: per-player language files and the `tr()` helper | | `TownyUtil` | Safe formatting of Towny data, money and dates, permission checks, input args | +| `Prices` | What Towny charges for a menu action: claims, outposts, spawn travel, merges | | `TownyConfig` | Towny's `config.yml` as a browsable, editable tree of sections and settings | | `DialogUtil` | Native text-input and confirmation dialogs (Paper Dialog API) | | `MessageUtil` | Prefix-decorated message sender for players | @@ -107,6 +108,43 @@ prompt(tr("bank.deposit-title"), tr("common.amount")) { amount -> --- +## Prices + +`Prices` answers "what will this button cost?" so an icon can say so before the player clicks. Every amount is read +from Towny's config and from the town or nation involved — never a fixed default — so it matches what the command +would actually take, and everything returns `0` without an economy. + +| Method | Description | +|:--------------------------------------|:--------------------------------------------------------------------------------------| +| `claim(Town, count)` | What claiming `count` chunks costs the town, at its current rising claim price | +| `outpost()` | What claiming an outpost costs | +| `unclaimRefund()` | What a town gets back per unclaimed chunk; negative when unclaiming costs instead | +| `plotType(String, count)` | What setting `count` plots to a plot type costs (`reset` prices the default type) | +| `merge(remaining, succumbing)` | What merging the second town into the first costs, before any debt it takes on | +| `townSpawn(Player, Town, outpost)` | What travelling to a town's spawn or outpost costs this player | +| `nationSpawn(Player, Nation)` | What travelling to a nation's spawn costs this player | +| `residentSpawn(Player)` | What `/resident spawn` costs — Towny prices it as a trip home | + +Spawn travel is not a single config value: Towny prices it by the traveller's relationship to the destination (own +town, nation member, ally, outsider) and caps it at the server's price for that relationship, so a visitor and a +resident see different numbers. `Prices` mirrors that, including the free-spawn admin permissions. + +Turn an amount into lore with `Menu.costLine` / `Menu.priceLine` rather than formatting it by hand: + +```kotlin +grid.add( + PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_TOWN, + Icons.icon( + Material.GRASS_BLOCK, tr("claims.claim"), tr("claims.claim-description"), + *listOfNotNull(costLine(Prices.claim(town))).toTypedArray() + ) +) { + run("towny:town claim", claims, delayTicks = CLAIM_DELAY) +} +``` + +--- + ## DialogUtil `DialogUtil` shows native Minecraft dialogs through Paper's Dialog API, so players never type into chat. Showing a diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt index e43ea05..2111667 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt @@ -72,13 +72,17 @@ object Pickers { } } - /** Picks one of [options] (id to MiniMessage label), marking [current] as selected. */ + /** + * Picks one of [options] (id to MiniMessage label), marking [current] as selected. + * [lines] adds lore to a single option, for per-option detail such as what picking it costs. + */ fun option( back: Menu, title: String, options: List>, current: String?, material: Material, + lines: (String) -> List = { emptyList() }, onPick: (String) -> Unit ): Menu = ListMenu(back.player, title, back) { @@ -87,6 +91,7 @@ object Pickers { val icon = { itemStack(material) { name(label) + lore(lines(id)) lore(back.tr(if (selected) "picker.current" else "picker.select")) glow(selected) } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Menu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Menu.kt index 59f4f68..9aaa011 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Menu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Menu.kt @@ -128,6 +128,21 @@ abstract class Menu( } } + /** + * A `Cost: …` lore line for a button that charges [amount], or `null` when the server has no + * economy or the action is free. Splat it into an icon with + * `*listOfNotNull(costLine(x)).toTypedArray()`; see [net.trilleo.mc.plugins.townymenu.utils.Prices]. + */ + fun costLine(amount: Double): String? = + if (TownyUtil.economy && amount > 0) tr("common.cost", "cost" to TownyUtil.money(amount)) else null + + /** + * A `Price: …` lore line for something on sale at [amount], or `null` without an economy. + * Unlike [costLine] a price of zero is still shown, because a free plot is an offer, not a missing fee. + */ + fun priceLine(amount: Double): String? = + if (TownyUtil.economy) tr("common.price", "price" to TownyUtil.money(amount)) else null + /** Places a help button opening the tutorial [chapter] that explains this menu. */ protected fun tutorialButton(slot: Int, chapter: Chapter) { button( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationInfoMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationInfoMenu.kt index f40da26..e798305 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationInfoMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationInfoMenu.kt @@ -4,6 +4,7 @@ import com.palmergames.bukkit.towny.`object`.Nation import com.palmergames.bukkit.towny.permissions.PermissionNodes import net.trilleo.mc.plugins.townymenu.guis.framework.Icons import net.trilleo.mc.plugins.townymenu.guis.framework.Menu +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import org.bukkit.Material import org.bukkit.entity.Player @@ -37,12 +38,7 @@ class NationInfoMenu(player: Player, private val nation: Nation, back: Menu) : grid.add( Icons.icon( Material.ENDER_PEARL, tr("town-info.visit"), tr("nation-info.visit-description"), - *listOfNotNull( - if (TownyUtil.economy && nation.spawnCost > 0) tr( - "common.cost", - "cost" to TownyUtil.money(nation.spawnCost) - ) else null - ).toTypedArray() + *listOfNotNull(costLine(Prices.nationSpawn(player, nation))).toTypedArray() ) ) { runAndClose("towny:nation spawn ${nation.name}") diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt index 83be11a..9b04fce 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt @@ -13,6 +13,7 @@ import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.framework.MenuEntry import net.trilleo.mc.plugins.townymenu.guis.resident.ResidentProfileMenu import net.trilleo.mc.plugins.townymenu.guis.tutorial.Tutorial +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material @@ -89,7 +90,12 @@ class NationMenu(player: Player, back: Menu?) : Menu(player, player.tr("nation.t grid.add(Icons.icon(Material.WRITABLE_BOOK, tr("nation.details"), tr("nation.details-description"))) { NationSettingsMenu(player, this).open() } - grid.add(Icons.icon(Material.ENDER_PEARL, tr("nation.spawn"), tr("nation.spawn-description"))) { + grid.add( + Icons.icon( + Material.ENDER_PEARL, tr("nation.spawn"), tr("nation.spawn-description"), + *listOfNotNull(costLine(Prices.nationSpawn(player, nation))).toTypedArray() + ) + ) { runAndClose("towny:nation spawn") } grid.add( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt index aa52bdf..54f6c8f 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt @@ -30,7 +30,8 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n Material.NAME_TAG, tr("nation-details.rename"), null, - tr("common.current", "value" to TownyUtil.name(nation.name)) + tr("common.current", "value" to TownyUtil.name(nation.name)), + *listOfNotNull(costLine(TownySettings.getNationRenameCost())).toTypedArray() ) ) { prompt(tr("nation-details.rename-title"), tr("common.new-name"), initial = nation.name) { name -> @@ -73,7 +74,8 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n Icons.icon( Material.LIGHT_BLUE_DYE, tr("nation-details.map-color"), - tr("nation-details.map-color-description") + tr("nation-details.map-color-description"), + *listOfNotNull(costLine(TownySettings.getNationSetMapColourCost())).toTypedArray() ) ) { val colors = TownySettings.getNationColorsMap().keys.sorted().map { it to "${TownyUtil.name(it)}" } @@ -85,7 +87,10 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n PermissionNodes.TOWNY_COMMAND_NATION_SET_CAPITAL, Icons.icon( Material.GOLDEN_HELMET, tr("nation-details.capital"), null, - tr("common.current", "value" to (nation.capital?.let { TownyUtil.name(it.name) } ?: "-")))) { + tr("common.current", "value" to (nation.capital?.let { TownyUtil.name(it.name) } ?: "-")), + *listOfNotNull(costLine(TownySettings.getNationCapitalChangeCost())).toTypedArray() + ) + ) { ListMenu(player, tr("nation-details.capital-title"), this) { nation.towns.filter { !nation.isCapital(it) }.sortedBy { it.name.lowercase() }.map { town -> MenuEntry({ Icons.town(player, town, "", tr("nation-details.capital-click")) }) { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NoNationMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NoNationMenu.kt index b1930de..d01c78f 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NoNationMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NoNationMenu.kt @@ -16,10 +16,7 @@ import org.bukkit.entity.Player class NoNationMenu(player: Player, back: Menu) : Menu(player, player.tr("no-nation.title"), 4, back) { override fun build() { - val price = if (TownyUtil.economy) tr( - "common.cost", - "cost" to TownyUtil.money(TownySettings.getNewNationPrice()) - ) else null + val price = costLine(TownySettings.getNewNationPrice()) guarded( 11, PermissionNodes.TOWNY_COMMAND_NATION_NEW, Icons.icon( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt index c7853f4..718a079 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt @@ -16,6 +16,7 @@ import net.trilleo.mc.plugins.townymenu.guis.framework.Icons import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.town.TownInfoMenu import net.trilleo.mc.plugins.townymenu.guis.tutorial.Tutorial +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material @@ -67,14 +68,18 @@ class PlotMenu(player: Player, back: Menu?) : Menu(player, player.tr("plot.title Icons.icon( Material.GRASS_BLOCK, tr("plot.claim", "town" to TownyUtil.name(town.name)), - tr("plot.claim-description") + tr("plot.claim-description"), + *listOfNotNull(costLine(Prices.claim(town))).toTypedArray() ) ) { run("towny:town claim", { town.numTownBlocks }, delayTicks = 20) } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_OUTPOST, - Icons.icon(Material.COMPASS, tr("plot.claim-outpost"), tr("plot.claim-outpost-description")) + Icons.icon( + Material.COMPASS, tr("plot.claim-outpost"), tr("plot.claim-outpost-description"), + *outpostCost().toTypedArray() + ) ) { run("towny:town claim outpost", { town.numTownBlocks }, delayTicks = 20) } @@ -145,7 +150,7 @@ class PlotMenu(player: Player, back: Menu?) : Menu(player, player.tr("plot.title grid.add( PermissionNodes.TOWNY_COMMAND_PLOT_CLAIM, Icons.icon( Material.EMERALD, tr("plot.buy"), tr("plot.buy-description"), - tr("common.price", "price" to TownyUtil.money(price)), + *listOfNotNull(priceLine(price)).toTypedArray() ) ) { run("towny:plot claim", ownerProbe) } } @@ -214,12 +219,14 @@ class PlotMenu(player: Player, back: Menu?) : Menu(player, player.tr("plot.title .filter { it != "default" && (group == null || it != "jail") } .sorted() .map { it to "${TownyUtil.plotType(player, it)}" } + val plots = group?.townBlocks?.size ?: 1 Pickers.option( this, tr("plot.type-title"), types, plot.type.name.takeIf { it != "default" } ?: "reset", - Material.OAK_SIGN) { type -> + Material.OAK_SIGN, + { type -> listOfNotNull(costLine(Prices.plotType(type, plots))) }) { type -> run("$scope set $type", { plot.type.name }, returnTo = this) }.open() } @@ -332,10 +339,7 @@ class PlotMenu(player: Player, back: Menu?) : Menu(player, player.tr("plot.title } } - private fun outpostCost(): List = - if (TownyUtil.economy && TownySettings.getOutpostCost() > 0) { - listOf(tr("common.cost", "cost" to TownyUtil.money(TownySettings.getOutpostCost()))) - } else emptyList() + private fun outpostCost(): List = listOfNotNull(costLine(Prices.outpost())) /** The join-day limits Towny places on buying [plot], or on every plot of its [group]. */ private fun joinDayLines(plot: TownBlock, group: PlotGroup?): List { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt index 0c9a035..2fe95e9 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt @@ -13,6 +13,7 @@ import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.framework.MenuEntry import net.trilleo.mc.plugins.townymenu.guis.town.TownInfoMenu import net.trilleo.mc.plugins.townymenu.guis.tutorial.Tutorial +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material @@ -83,7 +84,10 @@ class ResidentMenu(player: Player, back: Menu?) : Menu(player, player.tr("profil } row.add( PermissionNodes.TOWNY_COMMAND_RESIDENT_SPAWN, - Icons.icon(Material.RED_BED, tr("profile.spawn"), tr("profile.spawn-description")) + Icons.icon( + Material.RED_BED, tr("profile.spawn"), tr("profile.spawn-description"), + *listOfNotNull(costLine(Prices.residentSpawn(player))).toTypedArray() + ) ) { runAndClose("towny:resident spawn") } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/NoTownMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/NoTownMenu.kt index 4e4db35..af8ed1e 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/NoTownMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/NoTownMenu.kt @@ -19,11 +19,7 @@ class NoTownMenu(player: Player, back: Menu) : Menu(player, player.tr("no-town.t val reclaimable = TownySettings.getTownRuinsReclaimEnabled() && TownySettings.canRuinsBeReclaimedByTownlessPlayers() val row = if (reclaimable) layout(10, 12, 14, 16) else layout(11, 13, 15) - val price = - if (TownyUtil.economy) tr( - "common.cost", - "cost" to TownyUtil.money(TownySettings.getNewTownPrice()) - ) else null + val price = costLine(TownySettings.getNewTownPrice()) row.add( PermissionNodes.TOWNY_COMMAND_TOWN_NEW, Icons.icon( @@ -56,9 +52,7 @@ class NoTownMenu(player: Player, back: Menu) : Menu(player, player.tr("no-town.t InvitesMenu(player, this).open() } if (reclaimable) { - val cost = if (TownyUtil.economy) { - tr("common.cost", "cost" to TownyUtil.money(TownySettings.getEcoPriceReclaimTown())) - } else null + val cost = costLine(TownySettings.getEcoPriceReclaimTown()) row.add( PermissionNodes.TOWNY_COMMAND_TOWN_RECLAIM, Icons.icon( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt index 61c753c..b38c41b 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt @@ -5,6 +5,7 @@ import net.trilleo.mc.plugins.townymenu.guis.framework.Icons import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.framework.MenuEntry import net.trilleo.mc.plugins.townymenu.guis.framework.PagedMenu +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material import org.bukkit.entity.Player @@ -13,16 +14,19 @@ import org.bukkit.entity.Player class OutpostsMenu(player: Player, private val town: Town, back: Menu) : PagedMenu(player, player.tr("outposts.title"), back) { - override fun entries(): List = - town.allOutpostSpawns.mapIndexed { index, location -> + override fun entries(): List { + val cost = costLine(Prices.townSpawn(player, town, outpost = true)) + return town.allOutpostSpawns.mapIndexed { index, location -> val icon = { Icons.icon( Material.COMPASS, tr("outposts.outpost", "number" to index + 1), null, tr("outposts.world", "world" to (location.world?.name ?: "-")), tr("outposts.location", "x" to location.blockX, "y" to location.blockY, "z" to location.blockZ), + *listOfNotNull(cost).toTypedArray(), "", tr("common.click-teleport"), ) } MenuEntry(icon) { runAndClose("towny:town outpost ${index + 1}") } } + } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownClaimsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownClaimsMenu.kt index a806e69..4daa5ed 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownClaimsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownClaimsMenu.kt @@ -8,6 +8,7 @@ import net.trilleo.mc.plugins.townymenu.guis.common.Pickers import net.trilleo.mc.plugins.townymenu.guis.framework.Icons import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.tutorial.Tutorial +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material @@ -40,13 +41,19 @@ class TownClaimsMenu(player: Player, back: Menu) : Menu(player, player.tr("claim grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_TOWN, - Icons.icon(Material.GRASS_BLOCK, tr("claims.claim"), tr("claims.claim-description")) + Icons.icon( + Material.GRASS_BLOCK, tr("claims.claim"), tr("claims.claim-description"), + *listOfNotNull(costLine(Prices.claim(town))).toTypedArray() + ) ) { run("towny:town claim", claims, delayTicks = CLAIM_DELAY) } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_TOWN_MULTIPLE, - Icons.icon(Material.MOSS_BLOCK, tr("claims.claim-area"), tr("claims.claim-area-description")) + Icons.icon( + Material.MOSS_BLOCK, tr("claims.claim-area"), tr("claims.claim-area-description"), + *perClaim(town) + ) ) { prompt( tr("claims.claim-area-title"), @@ -60,27 +67,30 @@ class TownClaimsMenu(player: Player, back: Menu) : Menu(player, player.tr("claim } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_FILL, - Icons.icon(Material.BONE_MEAL, tr("claims.fill"), tr("claims.fill-description")) + Icons.icon(Material.BONE_MEAL, tr("claims.fill"), tr("claims.fill-description"), *perClaim(town)) ) { run("towny:town claim fill", claims, delayTicks = CLAIM_DELAY) } if (TownySettings.isAllowingOutposts()) { grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_OUTPOST, - Icons.icon(Material.COMPASS, tr("claims.outpost"), tr("claims.outpost-description")) + Icons.icon( + Material.COMPASS, tr("claims.outpost"), tr("claims.outpost-description"), + *listOfNotNull(costLine(Prices.outpost())).toTypedArray() + ) ) { run("towny:town claim outpost", claims, delayTicks = CLAIM_DELAY) } } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_UNCLAIM, - Icons.icon(Material.COARSE_DIRT, tr("claims.unclaim"), tr("claims.unclaim-description")) + Icons.icon(Material.COARSE_DIRT, tr("claims.unclaim"), tr("claims.unclaim-description"), *perUnclaim()) ) { run("towny:town unclaim", claims, delayTicks = CLAIM_DELAY) } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_UNCLAIM, - Icons.icon(Material.DIRT, tr("claims.unclaim-area"), tr("claims.unclaim-area-description")) + Icons.icon(Material.DIRT, tr("claims.unclaim-area"), tr("claims.unclaim-area-description"), *perUnclaim()) ) { prompt(tr("claims.unclaim-area-title"), tr("claims.radius"), initial = "1", maxLength = 3) { radius -> run("towny:town unclaim rect ${TownyUtil.argument(radius)}", claims, delayTicks = CLAIM_DELAY) @@ -88,7 +98,9 @@ class TownClaimsMenu(player: Player, back: Menu) : Menu(player, player.tr("claim } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_UNCLAIM_ALL, - Icons.icon(Material.LAVA_BUCKET, tr("claims.unclaim-all"), tr("claims.unclaim-all-description")) + Icons.icon( + Material.LAVA_BUCKET, tr("claims.unclaim-all"), tr("claims.unclaim-all-description"), *perUnclaim() + ) ) { run("towny:town unclaim all", claims, delayTicks = CLAIM_DELAY) } @@ -121,7 +133,10 @@ class TownClaimsMenu(player: Player, back: Menu) : Menu(player, player.tr("claim if (TownySettings.isOverClaimingAllowingStolenLand()) { grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_TAKEOVERCLAIM, - Icons.icon(Material.IRON_SWORD, tr("claims.takeover"), tr("claims.takeover-description")) + Icons.icon( + Material.IRON_SWORD, tr("claims.takeover"), tr("claims.takeover-description"), + *listOfNotNull(costLine(TownySettings.getTakeoverClaimPrice())).toTypedArray() + ) ) { run("towny:town takeoverclaim", claims, delayTicks = CLAIM_DELAY) } @@ -147,6 +162,22 @@ class TownClaimsMenu(player: Player, back: Menu) : Menu(player, player.tr("claim backButton(49) } + /** What each chunk of a multi-chunk claim costs [town], for buttons whose size the player picks. */ + private fun perClaim(town: Town): Array { + val price = Prices.claim(town) + if (!TownyUtil.economy || price <= 0) return emptyArray() + return arrayOf(tr("claims.price-each", "price" to TownyUtil.money(price))) + } + + /** What the town gets back per unclaimed chunk, or pays when the server charges for unclaiming. */ + private fun perUnclaim(): Array { + val refund = Prices.unclaimRefund() + if (!TownyUtil.economy || refund == 0.0) return emptyArray() + val line = if (refund > 0) tr("claims.refund-each", "refund" to TownyUtil.money(refund)) + else tr("claims.price-each", "price" to TownyUtil.money(-refund)) + return arrayOf(line) + } + private companion object { const val CLAIM_DELAY = 20L } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownInfoMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownInfoMenu.kt index 4ed88e3..53aa13c 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownInfoMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownInfoMenu.kt @@ -6,6 +6,7 @@ import net.trilleo.mc.plugins.townymenu.guis.MainMenu import net.trilleo.mc.plugins.townymenu.guis.framework.Icons import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.nation.NationInfoMenu +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import org.bukkit.Material import org.bukkit.entity.Player @@ -32,12 +33,7 @@ class TownInfoMenu(player: Player, private val town: Town, back: Menu) : grid.add( Icons.icon( Material.ENDER_PEARL, tr("town-info.visit"), tr("town-info.visit-description"), - *listOfNotNull( - if (TownyUtil.economy && town.spawnCost > 0) tr( - "common.cost", - "cost" to TownyUtil.money(town.spawnCost) - ) else null - ).toTypedArray() + *listOfNotNull(costLine(Prices.townSpawn(player, town))).toTypedArray() ) ) { runAndClose("towny:town spawn ${town.name}") @@ -90,7 +86,7 @@ class TownInfoMenu(player: Player, private val town: Town, back: Menu) : grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_BUYTOWN, Icons.icon( Material.GOLD_BLOCK, tr("town-info.buy"), tr("town-info.buy-description"), - tr("common.price", "price" to TownyUtil.money(town.forSalePrice)), + *listOfNotNull(priceLine(town.forSalePrice)).toTypedArray() ) ) { run("towny:town buytown ${town.name}", { town.mayor }, returnTo = MainMenu(player)) } } @@ -104,7 +100,8 @@ class TownInfoMenu(player: Player, private val town: Town, back: Menu) : "town-info.merge-description", "town" to TownyUtil.name(town.name), "own" to TownyUtil.name(viewerTown.name) - ) + ), + *listOfNotNull(costLine(Prices.merge(viewerTown, town))).toTypedArray() ) ) { run("towny:town merge ${town.name}") diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt index ff6b23a..fbd4633 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt @@ -15,6 +15,7 @@ import net.trilleo.mc.plugins.townymenu.guis.framework.Menu import net.trilleo.mc.plugins.townymenu.guis.nation.NationMenu import net.trilleo.mc.plugins.townymenu.guis.nation.NoNationMenu import net.trilleo.mc.plugins.townymenu.guis.tutorial.Tutorial +import net.trilleo.mc.plugins.townymenu.utils.Prices import net.trilleo.mc.plugins.townymenu.utils.TownyUtil import net.trilleo.mc.plugins.townymenu.utils.tr import org.bukkit.Material @@ -153,7 +154,12 @@ class TownMenu(player: Player, back: Menu?) : Menu(player, player.tr("town.title TownJailMenu(player, town, this).open() } } - grid.add(Icons.icon(Material.ENDER_PEARL, tr("town.spawn"), tr("town.spawn-description"))) { + grid.add( + Icons.icon( + Material.ENDER_PEARL, tr("town.spawn"), tr("town.spawn-description"), + *listOfNotNull(costLine(Prices.townSpawn(player, town))).toTypedArray() + ) + ) { runAndClose("towny:town spawn") } if (town.hasOutpostSpawn()) { @@ -161,7 +167,8 @@ class TownMenu(player: Player, back: Menu?) : Menu(player, player.tr("town.title Icons.icon( Material.COMPASS, tr("town.outpost-teleport"), - tr("town.outpost-teleport-description") + tr("town.outpost-teleport-description"), + *listOfNotNull(costLine(Prices.townSpawn(player, town, outpost = true))).toTypedArray() ) ) { OutpostsMenu(player, town, this).open() @@ -201,11 +208,10 @@ class TownMenu(player: Player, back: Menu?) : Menu(player, player.tr("town.title } /** The cost and waiting time Towny applies before a ruined town can be reclaimed. */ - private fun reclaimLines(): List = buildList { - if (TownyUtil.economy) add(tr("common.cost", "cost" to TownyUtil.money(TownySettings.getEcoPriceReclaimTown()))) - TownySettings.getTownRuinsMinDurationHours().takeIf { it > 0 } - ?.let { add(tr("town.reclaim-wait", "hours" to it)) } - } + private fun reclaimLines(): List = listOfNotNull( + costLine(TownySettings.getEcoPriceReclaimTown()), + TownySettings.getTownRuinsMinDurationHours().takeIf { it > 0 }?.let { tr("town.reclaim-wait", "hours" to it) }, + ) fun permissions(): Menu = PermissionMenu( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt index b0684aa..cb3b41c 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt @@ -28,7 +28,8 @@ class TownSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("tow Material.NAME_TAG, tr("town-details.rename"), null, - tr("common.current", "value" to TownyUtil.name(town.name)) + tr("common.current", "value" to TownyUtil.name(town.name)), + *listOfNotNull(costLine(TownySettings.getTownRenameCost())).toTypedArray() ) ) { prompt(tr("town-details.rename-title"), tr("common.new-name"), initial = town.name) { name -> @@ -68,7 +69,10 @@ class TownSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("tow } grid.add( PermissionNodes.TOWNY_COMMAND_TOWN_SET_MAPCOLOR, - Icons.icon(Material.LIME_DYE, tr("common.map-color"), tr("town-details.map-color-description")) + Icons.icon( + Material.LIME_DYE, tr("common.map-color"), tr("town-details.map-color-description"), + *listOfNotNull(costLine(TownySettings.getTownSetMapColourCost())).toTypedArray() + ) ) { val colors = TownySettings.getTownColorsMap().keys.sorted().map { it to "${TownyUtil.name(it)}" } Pickers.option(this, tr("town-details.map-color-title"), colors, null, Material.LIME_DYE) { color -> @@ -183,7 +187,7 @@ class TownSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("tow Material.RED_BANNER, tr("town-details.not-for-sale"), null, - tr("common.price", "price" to TownyUtil.money(town.forSalePrice)) + *listOfNotNull(priceLine(town.forSalePrice)).toTypedArray() ) ) { run("towny:town notforsale", { town.isForSale }) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/Prices.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/Prices.kt new file mode 100644 index 0000000..e996c3e --- /dev/null +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/Prices.kt @@ -0,0 +1,105 @@ +package net.trilleo.mc.plugins.townymenu.utils + +import com.palmergames.bukkit.towny.TownyAPI +import com.palmergames.bukkit.towny.TownySettings +import com.palmergames.bukkit.towny.`object`.Nation +import com.palmergames.bukkit.towny.`object`.Resident +import com.palmergames.bukkit.towny.`object`.Town +import com.palmergames.bukkit.towny.`object`.TownBlockTypeHandler +import com.palmergames.bukkit.towny.`object`.spawnlevel.NationSpawnLevel +import com.palmergames.bukkit.towny.`object`.spawnlevel.TownSpawnLevel +import com.palmergames.bukkit.towny.permissions.PermissionNodes +import org.bukkit.entity.Player + +/** + * What this server charges for the actions the menus run, so a button can show its price before + * the player commits to it. + * + * Amounts come from Towny's config and from the town or nation involved, never from a fixed + * default, so they match what the command would actually take. Everything returns `0` without an + * economy; menus turn an amount into lore with [net.trilleo.mc.plugins.townymenu.guis.framework.Menu.costLine]. + */ +object Prices { + + /** What claiming [count] chunks costs [town]. */ + fun claim(town: Town, count: Int = 1): Double = + if (count <= 1) town.townBlockCost else runCatching { town.getTownBlockCostN(count) }.getOrDefault(0.0) + + /** What claiming an outpost costs, whatever the town already owns. */ + fun outpost(): Double = TownySettings.getOutpostCost() + + /** What a town gets back per unclaimed chunk. Negative when the server charges for unclaiming instead. */ + fun unclaimRefund(): Double = TownySettings.getClaimRefundPrice() + + /** What setting a plot to [type] costs, for [count] plots at once. Towny's `reset` is the default type. */ + fun plotType(type: String, count: Int = 1): Double { + val name = if (type.equals("reset", ignoreCase = true)) "default" else type + return (TownBlockTypeHandler.getType(name)?.cost ?: 0.0) * count + } + + /** What merging [succumbing] into [remaining] costs the remaining town, before any debt it takes on. */ + fun merge(remaining: Town, succumbing: Town): Double { + val plots = runCatching { remaining.getTownBlockCostN(succumbing.numTownBlocks) }.getOrDefault(0.0) + return TownySettings.getBaseCostForTownMerge() + plots * TownySettings.getPercentageCostPerPlot() * 0.01 + } + + /** + * What travelling to [town]'s spawn — or to one of its outposts — costs [player]. + * + * Towny prices a spawn by the traveller's relationship to the town and caps it at the server's + * own price for that relationship, so a visitor and a resident see different numbers. + */ + fun townSpawn(player: Player, town: Town, outpost: Boolean = false): Double { + if (!TownyUtil.economy || spawnsFree(player)) return 0.0 + val level = townSpawnLevel(TownyAPI.getInstance().getResident(player), town, outpost) + if (level == TownSpawnLevel.UNAFFILIATED && !TownySettings.isPublicSpawnCostAffectedByTownSpawncost()) { + return TownySettings.getSpawnTravelCost() + } + return minOf(level.getCost(town), level.getCost()) + } + + /** What travelling to [nation]'s spawn costs [player]. See [townSpawn]. */ + fun nationSpawn(player: Player, nation: Nation): Double { + if (!TownyUtil.economy || spawnsFree(player)) return 0.0 + val level = nationSpawnLevel(TownyAPI.getInstance().getResident(player), nation) + if (level == NationSpawnLevel.UNAFFILIATED && !TownySettings.isPublicSpawnCostAffectedByTownSpawncost()) { + return TownySettings.getSpawnTravelCost() + } + return minOf(level.getCost(nation), level.getCost()) + } + + /** What `/resident spawn` costs [player], which Towny prices as a trip home to their own town. */ + fun residentSpawn(player: Player): Double = + TownyAPI.getInstance().getResident(player)?.townOrNull?.let { townSpawn(player, it) } ?: 0.0 + + private fun spawnsFree(player: Player): Boolean = + TownyUtil.can(player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN_SPAWN_FREECHARGE) || + TownyUtil.can(player, PermissionNodes.TOWNY_SPAWN_ADMIN_NOCHARGE) + + private fun townSpawnLevel(resident: Resident?, town: Town, outpost: Boolean): TownSpawnLevel { + if (resident == null) return TownSpawnLevel.UNAFFILIATED + if (TownySettings.trustedResidentsGetToSpawnToTown() && + (town.hasTrustedResident(resident) || resident.townOrNull?.let { town.hasTrustedTown(it) } == true) + ) return TownSpawnLevel.TOWN_RESIDENT + val own = resident.townOrNull ?: return TownSpawnLevel.UNAFFILIATED + if (own == town) return if (outpost) TownSpawnLevel.TOWN_RESIDENT_OUTPOST else TownSpawnLevel.TOWN_RESIDENT + val ownNation = resident.nationOrNull ?: return TownSpawnLevel.UNAFFILIATED + val townNation = town.nationOrNull ?: return TownSpawnLevel.UNAFFILIATED + return when { + ownNation == townNation -> TownSpawnLevel.PART_OF_NATION + // Towny only lets an enemy in when the town is peaceful, and then charges them as a resident. + townNation.hasEnemy(ownNation) -> TownSpawnLevel.TOWN_RESIDENT + townNation.hasAlly(ownNation) -> TownSpawnLevel.NATION_ALLY + else -> TownSpawnLevel.UNAFFILIATED + } + } + + private fun nationSpawnLevel(resident: Resident?, nation: Nation): NationSpawnLevel { + val ownNation = resident?.nationOrNull ?: return NationSpawnLevel.UNAFFILIATED + return when { + ownNation == nation -> NationSpawnLevel.PART_OF_NATION + nation.hasAlly(ownNation) -> NationSpawnLevel.NATION_ALLY + else -> NationSpawnLevel.UNAFFILIATED + } + } +} diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index 327f681..57ea3f2 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -385,6 +385,7 @@ claims: buy-bonus-title: "Buy Bonus Claims" buy-bonus-description: "Buy extra claim slots." price-each: "Price each: {price}" + refund-each: "Refund each: {refund}" bonus-amount: "Number of claims" auto-claim: "Auto Claim" auto-claim-description: "Claim every chunk you walk into." @@ -1576,7 +1577,7 @@ tutorial: bankruptcy: "Debt and Bankruptcy" bankruptcy-body: "When bankruptcy is on, a town that can't pay its upkeep goes into debt instead of being lost. A bankrupt town can't claim land or recruit until the debt is paid. Otherwise the town falls into ruin or is deleted. Either way TownyMenu warns the mayor in chat." prices: "Prices and the Next Day" - prices-body: "Prices & New Day, on the main menu, counts down to the next Towny day and lists what this server charges for founding, claiming, upkeep, plots, and taxes." + prices-body: "Prices & New Day, on the main menu, counts down to the next Towny day and lists what this server charges for founding, claiming, upkeep, plots, and taxes. Buttons that cost money also show their own price, so you can see what a claim, a teleport, or a plot takes before you click it." profile: title: "Your Profile" diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 92dcc2c..bf4d0cf 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -385,6 +385,7 @@ claims: buy-bonus-title: "购买额外领地" buy-bonus-description: "购买额外的领地名额。" price-each: "单价: {price}" + refund-each: "每块返还: {refund}" bonus-amount: "领地数量" auto-claim: "自动占领" auto-claim-description: "自动占领你走进的每个区块。" @@ -1576,7 +1577,7 @@ tutorial: bankruptcy: "债务与破产" bankruptcy-body: "启用破产时,无法支付维护费的城镇会负债,而不会直接失去。破产的城镇在还清债务前无法占领土地或招募居民。未启用时,城镇会沦为废墟或被删除。无论哪种情况,TownyMenu 都会在聊天中提醒镇长。" prices: "价格与下一天" - prices-body: "主菜单中的“价格与新的一天”会倒计时下一个 Towny 日,并列出本服务器在建立、占领、维护、地块和税款方面的收费。" + prices-body: "主菜单中的“价格与新的一天”会倒计时下一个 Towny 日,并列出本服务器在建立、占领、维护、地块和税款方面的收费。需要花钱的按钮也会显示各自的价格,因此你在点击前就能看到占领、传送或购买地块要花多少。" profile: title: "个人资料" From 741e1bee2961201805a1adbbff0898414d59ae5e Mon Sep 17 00:00:00 2001 From: Trilleo Date: Fri, 18 Sep 2026 12:53:19 +0800 Subject: [PATCH 2/4] Fix: Remove condition check in jar cleanup logic --- CHANGELOG.md | 6 ++++++ CLAUDE.md | 6 ++++-- README.md | 3 ++- build.gradle.kts | 15 +++++++++++---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d94ddc..6eb0b6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,12 @@ ### Technical Details +#### Build + ++ `copyPlugin` now deletes older `TownyMenu-*.jar` files from `run/plugins/` before copying the new build, so bumping + the version no longer leaves the test server with two copies of the plugin. The same cleanup for Towny's own jar now + runs even when Gradle considers the copy up to date. + #### Misc + Added a `Prices` utility that works out what a menu action costs — claims, outposts, spawn travel, plot types, town diff --git a/CLAUDE.md b/CLAUDE.md index 20dce09..f71653a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -51,11 +51,13 @@ Before finishing any task that changes the plugin, do all of the following: ```powershell ./gradlew build # Builds build/libs/TownyMenu-.jar -./gradlew copyPlugin # Copies the jar and Towny (towny_version) into run/plugins/ +./gradlew copyPlugin # Copies the jar and Towny (towny_version) into run/plugins/, clearing older copies ./gradlew startServer # Runs copyPlugin, then launches the paper-*.jar in run/ ``` -The local test server lives in `run/` (gitignored). `copyPlugin` puts the matching Towny jar in `run/plugins/`, but the +The local test server lives in `run/` (gitignored). `copyPlugin` deletes every `TownyMenu-*.jar` and `towny-*.jar` +already in `run/plugins/` before copying, so a version bump never leaves two copies for Bukkit to load. It puts the +matching Towny jar there too, but the Paper 26.2 jar (`run/paper-*.jar`) must be downloaded by hand from https://papermc.io/downloads/paper, and `eula.txt` accepted, before `startServer` works. The server console reads commands from the terminal running Gradle. diff --git a/README.md b/README.md index 8685cc3..9e21846 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,8 @@ TownyMenu is an addon: Towny must be installed on the server, or TownyMenu will ``` The compiled JAR is placed in `build/libs/`. Run `./gradlew copyPlugin` to copy it, along with the matching Towny jar, -into `run/plugins/` for the local test server, or `./gradlew startServer` to copy them and start the server. Before the +into `run/plugins/` for the local test server — any older copy of either is deleted first — or `./gradlew startServer` +to copy them and start the server. Before the first start, download a Paper 26.2 jar from [papermc.io](https://papermc.io/downloads/paper) into `run/`, then accept the EULA in `run/eula.txt` after the first launch. diff --git a/build.gradle.kts b/build.gradle.kts index 63e3b31..8ea73f2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -65,18 +65,25 @@ tasks.jar { } } +val serverPluginsDir = layout.projectDirectory.dir("run/plugins") + // Copies Towny into the test server, replacing any other Towny version left behind by a version bump. tasks.register("copyServerPlugins") { - val pluginsDir = layout.projectDirectory.dir("run/plugins") - doFirst { delete(fileTree(pluginsDir) { include("towny-*.jar") }) } + // The copy alone can be up to date while an old jar still sits beside it, and Bukkit would load both. + outputs.upToDateWhen { false } + doFirst { delete(fileTree(serverPluginsDir) { include("towny-*.jar") }) } from(serverPlugins) - into(pluginsDir) + into(serverPluginsDir) } +// Copies the plugin into the test server, replacing any older TownyMenu build left behind by a version bump. tasks.register("copyPlugin") { dependsOn("jar", "copyServerPlugins") + val stale = "${tasks.jar.get().archiveBaseName.get()}-*.jar" + outputs.upToDateWhen { false } + doFirst { delete(fileTree(serverPluginsDir) { include(stale) }) } from(tasks.jar.get().archiveFile) - into(layout.projectDirectory.dir("run/plugins")) + into(serverPluginsDir) } tasks.register("startServer") { From 1ce17c1d056a4098fc0d94c5971bd8acc524f572 Mon Sep 17 00:00:00 2001 From: Trilleo Date: Fri, 18 Sep 2026 13:22:25 +0800 Subject: [PATCH 3/4] Improvement: Adjust spacing and layout of lores for clearer view --- CHANGELOG.md | 12 ++ CLAUDE.md | 8 ++ docs/DEVELOPER_GUIDE.md | 50 ++++++++- docs/UTILITY_GUIDE.md | 37 +++++- .../mc/plugins/townymenu/guis/InvitesMenu.kt | 17 ++- .../plugins/townymenu/guis/LeaderboardMenu.kt | 22 ++-- .../mc/plugins/townymenu/guis/MainMenu.kt | 8 +- .../mc/plugins/townymenu/guis/MapMenu.kt | 11 +- .../plugins/townymenu/guis/admin/AdminMenu.kt | 5 +- .../townymenu/guis/admin/AdminNamesMenu.kt | 5 +- .../townymenu/guis/admin/AdminNationMenu.kt | 9 +- .../guis/admin/AdminNationToolsMenu.kt | 2 +- .../guis/admin/AdminPermGroupMenu.kt | 2 +- .../townymenu/guis/admin/AdminPermsMenu.kt | 6 +- .../townymenu/guis/admin/AdminRanksMenu.kt | 7 +- .../guis/admin/AdminResidentListMenu.kt | 2 +- .../townymenu/guis/admin/AdminResidentMenu.kt | 2 +- .../townymenu/guis/admin/AdminServerMenu.kt | 5 +- .../townymenu/guis/admin/AdminTownMenu.kt | 6 +- .../guis/admin/AdminTownToolsMenu.kt | 4 +- .../guis/admin/PluginSettingsMenu.kt | 5 +- .../townymenu/guis/admin/TownyConfigMenu.kt | 19 ++-- .../townymenu/guis/common/PermissionMenu.kt | 10 +- .../plugins/townymenu/guis/common/Pickers.kt | 28 ++--- .../plugins/townymenu/guis/common/RankMenu.kt | 11 +- .../plugins/townymenu/guis/framework/Icons.kt | 96 ++++++++++++---- .../townymenu/guis/nation/NationListMenu.kt | 9 +- .../townymenu/guis/nation/NationMenu.kt | 11 +- .../guis/nation/NationRelationsMenu.kt | 10 +- .../guis/nation/NationSanctionsMenu.kt | 5 +- .../guis/nation/NationSettingsMenu.kt | 11 +- .../townymenu/guis/nation/NationTownsMenu.kt | 17 ++- .../townymenu/guis/plot/PlotAreaMenu.kt | 4 +- .../plugins/townymenu/guis/plot/PlotMenu.kt | 4 +- .../townymenu/guis/plot/PlotOverridesMenu.kt | 9 +- .../townymenu/guis/plot/PlotTrustMenu.kt | 2 +- .../townymenu/guis/resident/FriendsMenu.kt | 7 +- .../townymenu/guis/resident/ResidentMenu.kt | 2 +- .../guis/resident/ResidentPlotsMenu.kt | 7 +- .../townymenu/guis/town/JailSentenceMenu.kt | 4 +- .../townymenu/guis/town/OutlawsMenu.kt | 6 +- .../townymenu/guis/town/OutpostsMenu.kt | 2 +- .../townymenu/guis/town/TownJailMenu.kt | 5 +- .../townymenu/guis/town/TownListMenu.kt | 8 +- .../townymenu/guis/town/TownMembersMenu.kt | 11 +- .../plugins/townymenu/guis/town/TownMenu.kt | 4 +- .../townymenu/guis/town/TownSettingsMenu.kt | 2 +- .../townymenu/guis/town/TownTrustMenu.kt | 12 +- .../guis/tutorial/TutorialChapterMenu.kt | 25 +++-- .../townymenu/guis/tutorial/TutorialMenu.kt | 7 +- .../plugins/townymenu/utils/ItemStackDSL.kt | 35 ++++-- .../mc/plugins/townymenu/utils/LoreBlocks.kt | 90 +++++++++++++++ .../mc/plugins/townymenu/utils/LoreUtil.kt | 6 + src/main/resources/lang/en_US.yml | 14 +-- src/main/resources/lang/zh_CN.yml | 14 +-- .../plugins/townymenu/utils/LoreBlocksTest.kt | 106 ++++++++++++++++++ 56 files changed, 602 insertions(+), 236 deletions(-) create mode 100644 src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocks.kt create mode 100644 src/test/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocksTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb0b6e..edf748d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,12 @@ #### Misc + Prices are hidden on servers with no economy, and free actions no longer carry an empty cost line. ++ Icon tooltips are easier to read: a blank line now sits under every icon's name, and its description, details, and + costs are separated into blocks instead of running together. ++ What a click does is now set off at the bottom of every tooltip by a divider line, so an icon's actions are easy to + spot without reading the whole tooltip. ++ Lines that pack two or three values together — Open and Public, PvP and Mobs, Allies and Enemies — now separate them + with a dot instead of a gap, so the pairs no longer blur into one another. ### Technical Details @@ -46,6 +52,12 @@ merges — from Towny's config and the town or nation involved, and `Menu.costLine` / `Menu.priceLine` to turn an amount into lore. + `Pickers.option` takes a `lines` lambda for per-option lore. ++ Added `LoreBlocks`, which lays an icon's lore out in blocks: a blank line under the display name, single separators + between blocks, a divider rule sized to the longest line above the actions, and no separator left dangling at either + end. The `itemStack` DSL exposes it as `loreBreak()` and `loreActions(...)`. ++ `Icons.icon`, `toggle`, `resident`, `town`, and `nation` take a named `actions` list for click hints and separate + their own lore blocks, so every menu spaces its icons the same way without repeating `""` separators at call sites. ++ `LoreUtil.columns` exposes the column width of a string, the measure `wrapLore` already wrapped on. ## Version 1.0.0 diff --git a/CLAUDE.md b/CLAUDE.md index f71653a..c71f4db 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -119,6 +119,14 @@ Extend `Menu` (or `PagedMenu` for lists) and implement `build()`, which runs on - **Keep `PagedMenu` entries lazy** — pass the icon as a lambda to `MenuEntry` so off-page icons are never built. - **Show what a button costs** — a button that spends money takes its amount from `Prices` and turns it into lore with `costLine(...)` / `priceLine(...)`, so the figure is this server's and not a guess. +- **Lay every icon's lore out in the same blocks** — a tooltip reads name → description → data → actions, and a new + icon follows that order or it looks out of place beside the others. With an `Icons` builder the description is the + `description` argument, the data and cost lines are the `extra` varargs, and everything about clicking is + `actions = listOf(...)`; with `itemStack { }` directly, use `loreWrapped(...)`, `loreBreak()` between data blocks, + and `loreActions(...)` to close. Never hand-roll the spacing: no `""` lore line to separate blocks, no divider drawn + by hand, no blank line under the name — `LoreBlocks` adds all three, collapses repeats, and trims a block that turns + out empty. The mistake to watch for is a click hint left among the data lines; it belongs in `actions`, which is what + puts it below the divider. See [The shape of an icon](docs/DEVELOPER_GUIDE.md#the-shape-of-an-icon). ## Translations diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index 4c23ae6..3b7dfe9 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -284,6 +284,9 @@ permissions, bank, ranks, pickers) in `guis/common`, and feature menus in `guis/ - **Say what a button costs.** A button that spends money shows its price in its lore: take the amount from [`Prices`](UTILITY_GUIDE.md#prices) and turn it into a line with `costLine` / `priceLine`, so the figure is the server's own and not a guess. +- **Lay every icon's lore out in the same blocks.** A tooltip reads name — description — data — actions. Everything + an icon says about clicking goes in the `actions` argument of an `Icons` builder (or `loreActions` in the `itemStack` + DSL), never among its data lines. Never hand-roll the spacing between blocks. See [Icons](#icons). - **Keep an empty row above the bottom row.** The back button, tutorial button, and page controls sit in the bottom row; leave the row above it empty so they stand apart from the menu's content. Only grids that need every row, such as the chunk map and the 4×4 permission grid, skip it. @@ -344,7 +347,7 @@ visible page are built: ```kotlin override fun entries(): List = town.residents.map { member -> - MenuEntry({ Icons.resident(player, member, "", tr("common.click-view")) }) { + MenuEntry({ Icons.resident(player, member, actions = listOf(tr("common.click-view"))) }) { ResidentProfileMenu(player, member, this).open() } } @@ -439,6 +442,51 @@ replaces. `toggle(player, …)` plus the summary icons `resident(player, …)`, `town(player, …)`, `nation(player, …)`, which add their own labels in `player`'s language and accept extra lore lines. +#### The shape of an icon + +Every icon in the plugin reads top to bottom in the same order, and a new one follows it so it does not look out of +place beside the others: + +| Block | Where it goes | What belongs there | +|:----------------|:------------------------|:---------------------------------------------------------------| +| **Name** | `name` | What the button is, one translated line. | +| **Description** | `description` (wrapped) | What it does, a sentence or two; `null` when the name says it. | +| **Data** | the `extra` varargs | Current values, counts, and the `costLine` / `priceLine` line. | +| **Actions** | `actions = listOf(...)` | What a left- or right-click does, and nothing else. | + +```kotlin +Icons.icon( + Material.ENDER_PEARL, tr("town.spawn"), tr("town.spawn-description"), + *listOfNotNull(costLine(Prices.townSpawn(player, town))).toTypedArray(), + actions = listOf(tr("common.click-teleport")) +) +``` + +```text +Go to Spawn + <- added for you +Teleport to your town's spawn point. <- description + <- added for you +Cost: $25 <- extra +------------------------------ <- added for you +Click to teleport <- actions +``` + +`toggle`, `resident`, `town`, and `nation` follow the same order and take the same `actions` argument; they fill the +data block themselves from Towny and put the caller's extra lines in a block of their own below it. + +Two rules keep new icons in line with the rest: + +- **A click hint goes in `actions`, never among the extra lines.** That is what sets it below the divider rule. This is + the easy one to get wrong, because an extra line accepts it happily. +- **Never hand-roll the spacing.** No `""` lore line to separate blocks, no divider drawn by hand, no blank line under + the name. [`LoreBlocks`](UTILITY_GUIDE.md#lore-blocks) adds all three, collapses repeated separators, and trims a + block that turns out to be empty — so a conditional block never leaves a hole behind. A `""` is still fine *inside* + the data lines to split one long list into two groups. + +When you build an icon with `itemStack { }` directly — a sort button, a config entry — reach for the same blocks +through `loreWrapped(...)`, `loreBreak()`, and `loreActions(...)`. + ### Example: A New Menu ```kotlin diff --git a/docs/UTILITY_GUIDE.md b/docs/UTILITY_GUIDE.md index fd7277a..8d32b0e 100644 --- a/docs/UTILITY_GUIDE.md +++ b/docs/UTILITY_GUIDE.md @@ -12,6 +12,7 @@ This guide covers the utility helpers provided in `net.trilleo.mc.plugins.townym | `DialogUtil` | Native text-input and confirmation dialogs (Paper Dialog API) | | `MessageUtil` | Prefix-decorated message sender for players | | `LoreUtil` | Word-aware text wrapping for item lore with style carry-over | +| `LoreBlocks` | Lays an icon's lore out in blocks: separators, the action divider, spacing | --- @@ -27,7 +28,9 @@ import net.trilleo.mc.plugins.townymenu.utils.itemStack val icon = itemStack(Material.EMERALD) { name("Deposit") loreWrapped("Move money from your balance into the town bank.") - lore("", "Click to deposit") + loreBreak() + lore("Balance: $120") + loreActions(listOf("Click to deposit")) glow(true) } ``` @@ -39,11 +42,39 @@ val icon = itemStack(Material.EMERALD) { | `name` | `name(String)` | Set the display name (MiniMessage) | | `lore` | `lore(vararg String)` / `lore(Iterable)` | Append lore lines (each parsed with MiniMessage) | | `loreWrapped` | `loreWrapped(String, maxWidth = 40)` | Append text word-wrapped by `LoreUtil` | +| `loreBreak` | `loreBreak()` | Start a new lore block, separated by a blank line | +| `loreActions` | `loreActions(Iterable)` | Append the closing hints block, set off by a divider rule | | `glow` | `glow(Boolean)` | Force the enchantment glint on or off | | `hideTooltip` | `hideTooltip(Boolean)` | Hide the whole tooltip (decorative filler) | | `head` | `head(OfflinePlayer)` | Show a player's skin on a `PLAYER_HEAD` | | `meta` | `meta(ItemMeta.() -> Unit)` | Escape hatch for direct `ItemMeta` manipulation, applied last | +### Lore Blocks + +Lore reads as blocks rather than one dense wall of text, and `LoreBlocks` lays them out so every icon in the plugin +spaces the same way: + +- A blank line always follows the display name, giving the title room to breathe. +- `loreBreak()` separates blocks with a blank line. A line with no visible text counts as a break too, so `lore("")` + between blocks still works, and repeated breaks collapse into one. +- `loreActions(lines)` closes the tooltip with what a click does, set off by a divider rule as wide as the longest lore + line. Passing no lines adds nothing. +- A break or divider left dangling at either end is dropped, so a block that turns out to be empty never leaves a hole. + +`LoreBlocks` is never used directly: menus build icons through [`Icons`](DEVELOPER_GUIDE.md#icons), or with the DSL +methods above, and those decide what goes in each block. Read +[The shape of an icon](DEVELOPER_GUIDE.md#the-shape-of-an-icon) before adding one. + +```text +Town Spawn + <- blank line under the title +Teleport to your town's spawn point. + <- loreBreak() +Cost: $25 +------------------------------ <- loreActions(...) +Click to teleport +``` + --- ## Lang @@ -303,7 +334,7 @@ import net.trilleo.mc.plugins.townymenu.utils.itemStack val item = itemStack(Material.BELL) { name("Town Settings") loreWrapped("PvP, mobs, fire, explosions, and whether the town is open to new residents.") - lore("", "Click to open") + loreActions(listOf("Click to open")) } ``` @@ -314,6 +345,8 @@ val item = itemStack(Material.BELL) { | `text` | `String` | — | MiniMessage-formatted input string | | `maxWidth` | `Int` | `40` | Maximum columns per line | +`LoreUtil.columns(text)` measures a string in the same columns, which is how `LoreBlocks` sizes its divider rule. + ### Behavior Details - **Word-aware**: Lines break at word boundaries (spaces). A word that exceeds `maxWidth` alone is force-broken diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/InvitesMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/InvitesMenu.kt index 2c9ba7e..4bf217c 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/InvitesMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/InvitesMenu.kt @@ -36,7 +36,8 @@ class InvitesMenu(player: Player, back: Menu?) : PagedMenu(player, player.tr("in val personal = viewer.receivedInvites.mapNotNull { invite -> val from = invite.sender as? Town ?: return@mapNotNull null entry( - invite, tr("invites.town", "town" to TownyUtil.name(from.name)), { Icons.town(player, from, *it) }, + invite, tr("invites.town", "town" to TownyUtil.name(from.name)), + { lines, actions -> Icons.town(player, from, *lines, actions = actions) }, "towny:invite $accept ${from.name}", "towny:invite $deny ${from.name}" ) { snapshot(viewer) } } @@ -46,7 +47,7 @@ class InvitesMenu(player: Player, back: Menu?) : PagedMenu(player, player.tr("in entry( invite, tr("invites.nation", "nation" to TownyUtil.name(from.name)), - { Icons.nation(player, from, *it) }, + { lines, actions -> Icons.nation(player, from, *lines, actions = actions) }, "towny:town invite accept ${from.name}", "towny:town invite deny ${from.name}" ) { snapshot(viewer) } @@ -60,7 +61,7 @@ class InvitesMenu(player: Player, back: Menu?) : PagedMenu(player, player.tr("in entry( invite, tr("invites.alliance", "nation" to TownyUtil.name(from.name)), - { Icons.nation(player, from, *it) }, + { lines, actions -> Icons.nation(player, from, *lines, actions = actions) }, "towny:nation ally accept ${from.name}", "towny:nation ally deny ${from.name}" ) { snapshot(viewer) } @@ -74,16 +75,14 @@ class InvitesMenu(player: Player, back: Menu?) : PagedMenu(player, player.tr("in private fun entry( invite: Invite, title: String, - icon: (Array) -> ItemStack, + icon: (lines: Array, actions: List) -> ItemStack, acceptCommand: String, denyCommand: String, probe: () -> Any?, ): MenuEntry { - val lines = arrayOf( - "", "$title", tr("invites.sender", "sender" to TownyUtil.name(invite.senderName)), - tr("invites.left-accept"), tr("invites.right-decline") - ) - return MenuEntry({ icon(lines) }) { click -> + val lines = arrayOf("$title", tr("invites.sender", "sender" to TownyUtil.name(invite.senderName))) + val actions = listOf(tr("invites.left-accept"), tr("invites.right-decline")) + return MenuEntry({ icon(lines, actions) }) { click -> run(if (click.isRightClick) denyCommand else acceptCommand, probe) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/LeaderboardMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/LeaderboardMenu.kt index dcd07ec..f546d22 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/LeaderboardMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/LeaderboardMenu.kt @@ -152,7 +152,12 @@ class LeaderboardMenu(player: Player, back: Menu) : Menu(player, player.tr("lead ListMenu(player, title, this) { menu -> towns.map { it to score(it) }.sortedByDescending { it.second.first }.take(topSize) .mapIndexed { index, (town, value) -> - MenuEntry({ Icons.town(player, town, "", rank(index), value.second, tr("common.click-details")) }) { + MenuEntry({ + Icons.town( + player, town, rank(index), value.second, + actions = listOf(tr("common.click-details")) + ) + }) { TownInfoMenu(player, town, menu).open() } } @@ -164,12 +169,8 @@ class LeaderboardMenu(player: Player, back: Menu) : Menu(player, player.tr("lead .mapIndexed { index, (nation, value) -> MenuEntry({ Icons.nation( - player, - nation, - "", - rank(index), - value.second, - tr("common.click-details") + player, nation, rank(index), value.second, + actions = listOf(tr("common.click-details")) ) }) { NationInfoMenu(player, nation, menu).open() @@ -193,7 +194,12 @@ class LeaderboardMenu(player: Player, back: Menu) : Menu(player, player.tr("lead residents.map { it to score(it) }.sortedByDescending { it.second.first } .let { if (limit) it.take(topSize) else it } .mapIndexed { index, (target, value) -> - MenuEntry({ Icons.resident(player, target, "", rank(index), value.second, tr("common.click-view")) }) { + MenuEntry({ + Icons.resident( + player, target, rank(index), value.second, + actions = listOf(tr("common.click-view")) + ) + }) { ResidentProfileMenu(player, target, menu).open() } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MainMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MainMenu.kt index 1cedcbc..71ca2fb 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MainMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MainMenu.kt @@ -30,12 +30,14 @@ class MainMenu(player: Player) : Menu(player, player.tr("main.title"), 6) { val town = resident.townOrNull val nation = resident.nationOrNull - button(4, Icons.resident(player, resident, "", tr("main.profile-click"))) { + button(4, Icons.resident(player, resident, actions = listOf(tr("main.profile-click")))) { ResidentMenu(player, this).open() } if (town != null) { - button(20, Icons.town(player, town, "", tr("main.town-click"))) { TownMenu(player, this).open() } + button(20, Icons.town(player, town, actions = listOf(tr("main.town-click")))) { + TownMenu(player, this).open() + } } else { button(20, Icons.icon(Material.BELL, tr("main.town"), tr("main.town-none"))) { NoTownMenu(player, this).open() @@ -43,7 +45,7 @@ class MainMenu(player: Player) : Menu(player, player.tr("main.title"), 6) { } when { - nation != null -> button(22, Icons.nation(player, nation, "", tr("main.nation-click"))) { + nation != null -> button(22, Icons.nation(player, nation, actions = listOf(tr("main.nation-click")))) { NationMenu( player, this diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MapMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MapMenu.kt index 437fe94..9a5d3a8 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MapMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/MapMenu.kt @@ -108,11 +108,16 @@ class MapMenu(player: Player, back: Menu?) : Menu(player, player.tr("map.title") if (plot.isHomeBlock) add(tr("map.home-block")) if (plot.isOutpost) add(tr("map.outpost")) if (plot.isForSale) add(tr("map.for-sale", "price" to TownyUtil.money(plot.plotPrice))) - add("") - add(tr("map.click-town")) - if (canBuy(plot, viewer)) add(tr("map.right-buy")) } }) + if (plot != null) { + loreActions( + listOfNotNull( + tr("map.click-town"), + if (canBuy(plot, viewer)) tr("map.right-buy") else null + ) + ) + } glow(plot?.isForSale == true) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminMenu.kt index c9e5aab..d2d7352 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminMenu.kt @@ -111,10 +111,9 @@ class AdminMenu(player: Player, back: Menu?) : Menu(player, player.tr("admin.tit name("${TownyUtil.text(world.name)}") lore( tr("admin-world.using-towny", "value" to TownyUtil.yesNo(player, world.isUsingTowny)), - tr("admin-world.towns", "count" to world.townsInWorld.size), - "", - tr("common.click-view"), + tr("admin-world.towns", "count" to world.townsInWorld.size) ) + loreActions(listOf(tr("common.click-view"))) glow(world.isUsingTowny) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNamesMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNamesMenu.kt index d8fccdd..f1fa223 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNamesMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNamesMenu.kt @@ -32,7 +32,10 @@ class AdminNamesMenu( override fun entries(): List = held().sortedBy { it.lowercase() }.map { name -> MenuEntry({ - Icons.icon(material, "${TownyUtil.name(name)}", null, tr("admin-tools.click-remove")) + Icons.icon( + material, "${TownyUtil.name(name)}", + actions = listOf(tr("admin-tools.click-remove")) + ) }) { run("$command remove $name", ::count) } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationMenu.kt index cd87cad..f5eb409 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationMenu.kt @@ -63,7 +63,12 @@ class AdminNationMenu(player: Player, private val nation: Nation, back: Menu) : ListMenu(player, tr("nation-details.leader-title"), this) { nation.capital?.residents.orEmpty().filter { !it.isKing }.sortedBy { it.name.lowercase() } .map { candidate -> - MenuEntry({ Icons.resident(player, candidate, "", tr("nation-details.leader-click")) }) { + MenuEntry({ + Icons.resident( + player, candidate, + actions = listOf(tr("nation-details.leader-click")) + ) + }) { run("$command set king ${candidate.name}", { nation.king }, returnTo = this) } } @@ -153,7 +158,7 @@ class AdminNationMenu(player: Player, private val nation: Nation, back: Menu) : private fun townList(title: String, hint: String, onPick: (Town) -> Unit) { ListMenu(player, title, this) { nation.towns.filter { !nation.isCapital(it) }.sortedBy { it.name.lowercase() }.map { town -> - MenuEntry({ Icons.town(player, town, "", hint) }) { onPick(town) } + MenuEntry({ Icons.town(player, town, actions = listOf(hint)) }) { onPick(town) } } }.open() } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationToolsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationToolsMenu.kt index eb86723..3cf59cf 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationToolsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminNationToolsMenu.kt @@ -98,7 +98,7 @@ class AdminNationToolsMenu(player: Player, private val nation: Nation, back: Men lateinit var list: Menu list = ListMenu(player, tr("admin-town-tools.ranks-title"), this) { menu -> nation.residents.sortedBy { it.name.lowercase() }.map { resident -> - MenuEntry({ Icons.resident(player, resident, "", tr("picker.select")) }) { + MenuEntry({ Icons.resident(player, resident, actions = listOf(tr("picker.select"))) }) { RankMenu.create(player, resident, nation = true, back = menu, admin = nation.name).open() } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermGroupMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermGroupMenu.kt index d98b0ec..8fa3f3f 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermGroupMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermGroupMenu.kt @@ -24,7 +24,7 @@ class AdminPermGroupMenu(player: Player, private val group: String, back: Menu) MenuEntry({ itemStack(Material.PAPER) { name("${TownyUtil.text(node)}") - lore(tr("admin-perms.click-remove")) + loreActions(listOf(tr("admin-perms.click-remove"))) } }) { run("$command removeperm $node", { nodes().size }) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermsMenu.kt index f1ac161..25e243c 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminPermsMenu.kt @@ -62,10 +62,8 @@ class AdminPermsMenu(player: Player, back: Menu) : Menu(player, player.tr("admin MenuEntry({ itemStack(Material.BOOKSHELF) { name("${TownyUtil.text(group)}") - lore( - tr("admin-perms.node-count", "count" to TownyPerms.getPermsOfGroup(group).size), - tr("common.click-details"), - ) + lore(tr("admin-perms.node-count", "count" to TownyPerms.getPermsOfGroup(group).size)) + loreActions(listOf(tr("common.click-details"))) } }) { AdminPermGroupMenu(player, group, menu).open() } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminRanksMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminRanksMenu.kt index ebab825..9b354db 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminRanksMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminRanksMenu.kt @@ -35,11 +35,8 @@ class AdminRanksMenu(player: Player, private val nation: Boolean, back: Menu) : MenuEntry({ itemStack(Material.NAME_TAG) { name("${TownyUtil.name(rank)}") - lore( - tr("admin-perms.node-count", "count" to nodes.size), - tr("common.left-details"), - tr("admin-perms.right-remove"), - ) + lore(tr("admin-perms.node-count", "count" to nodes.size)) + loreActions(listOf(tr("common.left-details"), tr("admin-perms.right-remove"))) } }) { click -> if (click.isRightClick) { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentListMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentListMenu.kt index fe0d5b8..bed0201 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentListMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentListMenu.kt @@ -20,7 +20,7 @@ class AdminResidentListMenu(player: Player, back: Menu) : PagedMenu(player, play .filter { it.name.contains(filter, ignoreCase = true) } .sortedWith(compareBy({ !it.isOnline }, { it.name.lowercase() })) .map { resident -> - MenuEntry({ Icons.resident(player, resident, "", tr("common.click-view")) }) { + MenuEntry({ Icons.resident(player, resident, actions = listOf(tr("common.click-view"))) }) { AdminResidentMenu(player, resident, this).open() } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentMenu.kt index 4ddefef..ea6ea56 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminResidentMenu.kt @@ -34,7 +34,7 @@ class AdminResidentMenu(player: Player, private val target: Resident, back: Menu val town = target.townOrNull if (town != null) { - grid.add(Icons.town(player, town, "", tr("common.click-view"))) { + grid.add(Icons.town(player, town, actions = listOf(tr("common.click-view")))) { AdminTownMenu(player, town, this).open() } if (!target.isMayor) { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminServerMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminServerMenu.kt index e0933c0..edb1569 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminServerMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminServerMenu.kt @@ -217,7 +217,10 @@ class AdminServerMenu(player: Player, back: Menu) : Menu(player, player.tr("admi guarded( slot, node, - Icons.icon(material, name, description, "", tr("admin-server.left-on"), tr("admin-server.right-off")) + Icons.icon( + material, name, description, + actions = listOf(tr("admin-server.left-on"), tr("admin-server.right-off")) + ) ) { click -> runAndClose("towny:townyadmin toggle $key ${if (click.isRightClick) "off" else "on"}") } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownMenu.kt index 5656d78..af9a666 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownMenu.kt @@ -158,7 +158,7 @@ class AdminTownMenu(player: Player, private val town: Town, back: Menu) : val nation = town.nationOrNull if (nation != null) { - grid.add(Icons.nation(player, nation, "", tr("common.click-view"))) { + grid.add(Icons.nation(player, nation, actions = listOf(tr("common.click-view")))) { AdminNationMenu(player, nation, this).open() } grid.add( @@ -195,7 +195,9 @@ class AdminTownMenu(player: Player, private val town: Town, back: Menu) : private fun residentList(title: String, filter: (Resident) -> Boolean, onPick: ListMenu.(Resident) -> Unit) { ListMenu(player, title, this) { list -> town.residents.filter(filter).sortedBy { it.name.lowercase() }.map { resident -> - MenuEntry({ Icons.resident(player, resident, "", tr("picker.select")) }) { list.onPick(resident) } + MenuEntry({ Icons.resident(player, resident, actions = listOf(tr("picker.select"))) }) { + list.onPick(resident) + } } }.open() } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownToolsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownToolsMenu.kt index 58824d2..fbbfe65 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownToolsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/AdminTownToolsMenu.kt @@ -159,7 +159,9 @@ class AdminTownToolsMenu(player: Player, private val town: Town, back: Menu) : lateinit var list: Menu list = ListMenu(player, tr("admin-town-tools.ranks-title"), this) { menu -> residents.sortedBy { it.name.lowercase() }.map { resident -> - MenuEntry({ Icons.resident(player, resident, "", tr("picker.select")) }) { onPick(resident, menu) } + MenuEntry({ Icons.resident(player, resident, actions = listOf(tr("picker.select"))) }) { + onPick(resident, menu) + } } } list.open() diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/PluginSettingsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/PluginSettingsMenu.kt index f586718..f657ed0 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/PluginSettingsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/PluginSettingsMenu.kt @@ -30,7 +30,7 @@ class PluginSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("a ) ) tr("admin-plugin.language-auto") else TownyUtil.text(language) ), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { val options = @@ -43,7 +43,8 @@ class PluginSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("a row.add( Icons.icon( Material.NAME_TAG, tr("admin-plugin.prefix"), tr("admin-plugin.prefix-description"), - tr("common.current", "value" to config.messagePrefix), tr("common.click-change") + tr("common.current", "value" to config.messagePrefix), + actions = listOf(tr("common.click-change")) ) ) { prompt( diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/TownyConfigMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/TownyConfigMenu.kt index 40b5a57..2bdb8b1 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/TownyConfigMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/admin/TownyConfigMenu.kt @@ -27,11 +27,9 @@ class TownyConfigMenu(player: Player, private val section: String, back: Menu) : itemStack(Material.BOOKSHELF) { name("${child.name}") if (child.description.isNotEmpty()) loreWrapped("${shorten(child.description)}") - lore( - "", - tr("admin-config.settings-count", "count" to TownyConfig.count(child.path)), - tr("common.click-view") - ) + loreBreak() + lore(tr("admin-config.settings-count", "count" to TownyConfig.count(child.path))) + loreActions(listOf(tr("common.click-view"))) } }) { TownyConfigMenu(player, child.path, this).open() } } + TownyConfig.settings(section).map { settingEntry(this, it) } @@ -81,15 +79,18 @@ class TownyConfigMenu(player: Player, private val section: String, back: Menu) : ) { name("${setting.name}") if (setting.description.isNotEmpty()) loreWrapped("${shorten(setting.description)}") + loreBreak() lore(buildList { - add("") add(menu.tr("admin-config.path", "path" to setting.path)) if (kind == Kind.READ_ONLY) { add(menu.tr("admin-config.read-only")) } else { add(menu.tr("common.current", "value" to display(player, kind, value))) add(menu.tr("admin-config.default", "value" to display(player, kind, setting.default))) - add("") + } + }) + if (kind != Kind.READ_ONLY) { + loreActions(buildList { add( menu.tr( when { @@ -100,8 +101,8 @@ class TownyConfigMenu(player: Player, private val section: String, back: Menu) : ) ) if (editable && value != setting.default) add(menu.tr("admin-config.right-reset")) - } - }) + }) + } glow(on) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/PermissionMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/PermissionMenu.kt index ba81a03..6fa0888 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/PermissionMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/PermissionMenu.kt @@ -44,7 +44,7 @@ class PermissionMenu( guarded(2 + column, node, itemStack(ACTION_ICONS.getValue(action)) { name("${actionName(action)}") loreWrapped("${actionDescription(action)}") - lore("", tr(if (allOn) "perm.everyone-off" else "perm.everyone-on")) + loreActions(listOf(tr(if (allOn) "perm.everyone-off" else "perm.everyone-on"))) }) { run("$command ${action.arg} ${if (allOn) "off" else "on"}", ::snapshot) } } @@ -52,17 +52,15 @@ class PermissionMenu( val allOn = ACTIONS.all { perms.getPerm(level, it) } guarded(10 + row * 9, node, itemStack(LEVEL_ICONS.getValue(level)) { name("${levelName(level)}") - lore(tr(if (allOn) "perm.every-action-off" else "perm.every-action-on")) + loreActions(listOf(tr(if (allOn) "perm.every-action-off" else "perm.every-action-on"))) }) { run("$command ${level.arg} ${if (allOn) "off" else "on"}", ::snapshot) } ACTIONS.forEachIndexed { column, action -> val allowed = perms.getPerm(level, action) val cell = itemStack(if (allowed) Material.LIME_CONCRETE else Material.RED_CONCRETE) { name("${if (allowed) "" else ""}${levelName(level)}: ${actionName(action)}") - lore( - tr("icon.currently", "value" to tr(if (allowed) "perm.allowed" else "perm.denied")), - tr("icon.click-toggle") - ) + lore(tr("icon.currently", "value" to tr(if (allowed) "perm.allowed" else "perm.denied"))) + loreActions(listOf(tr("icon.click-toggle"))) } guarded(11 + row * 9 + column, node, cell) { run("$command ${level.arg} ${action.arg} ${if (allowed) "off" else "on"}", ::snapshot) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt index 2111667..e4260fe 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/Pickers.kt @@ -26,12 +26,7 @@ object Pickers { .filter(filter) .map { resident -> MenuEntry({ - Icons.resident( - back.player, - resident, - "", - back.tr("picker.select") - ) + Icons.resident(back.player, resident, actions = listOf(back.tr("picker.select"))) }) { onPick(resident) } } } @@ -44,12 +39,7 @@ object Pickers { .sortedBy { it.name.lowercase() } .map { town -> MenuEntry({ - Icons.town( - back.player, - town, - "", - back.tr("picker.select") - ) + Icons.town(back.player, town, actions = listOf(back.tr("picker.select"))) }) { onPick(town) } } } @@ -62,12 +52,7 @@ object Pickers { .sortedBy { it.name.lowercase() } .map { nation -> MenuEntry({ - Icons.nation( - back.player, - nation, - "", - back.tr("picker.select") - ) + Icons.nation(back.player, nation, actions = listOf(back.tr("picker.select"))) }) { onPick(nation) } } } @@ -92,7 +77,12 @@ object Pickers { itemStack(material) { name(label) lore(lines(id)) - lore(back.tr(if (selected) "picker.current" else "picker.select")) + if (selected) { + loreBreak() + lore(back.tr("picker.current")) + } else { + loreActions(listOf(back.tr("picker.select"))) + } glow(selected) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/RankMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/RankMenu.kt index 82f1648..75d6da1 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/RankMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/common/RankMenu.kt @@ -37,9 +37,14 @@ object RankMenu { val icon = { itemStack(if (held) Material.NAME_TAG else Material.PAPER) { name("${if (held) "" else ""}${TownyUtil.name(rank)}") - lore( - menu.tr(if (held) "rank.assigned" else "rank.not-assigned"), - menu.tr(if (!allowed) "rank.not-allowed" else if (held) "rank.click-remove" else "rank.click-assign"), + lore(menu.tr(if (held) "rank.assigned" else "rank.not-assigned")) + loreActions( + listOf( + menu.tr( + if (!allowed) "rank.not-allowed" + else if (held) "rank.click-remove" else "rank.click-assign" + ) + ) ) glow(held) } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Icons.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Icons.kt index 9c4d374..66c8e27 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Icons.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/framework/Icons.kt @@ -11,15 +11,31 @@ import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -/** Icon builders shared by the Towny menus. Icons with built-in text take the [Player] whose language they use. */ +/** + * Icon builders shared by the Towny menus. Icons with built-in text take the [Player] whose language they use. + * + * Every builder lays its lore out in the same blocks — description, then data, + * then the extra lines the caller adds — and closes with [actions], the hints + * for what clicking does, which the item DSL sets off with a divider rule. + */ object Icons { /** A simple icon with a name and wrapped description. */ - fun icon(material: Material, name: String, description: String? = null, vararg extra: String): ItemStack = + fun icon( + material: Material, + name: String, + description: String? = null, + vararg extra: String, + actions: List = emptyList(), + ): ItemStack = itemStack(material) { name(name) description?.let { loreWrapped("$it") } - if (extra.isNotEmpty()) lore(extra.asList()) + if (extra.isNotEmpty()) { + loreBreak() + lore(extra.asList()) + } + loreActions(actions) } /** A toggle switch showing its current [value]; clicking should flip it. */ @@ -27,29 +43,33 @@ object Icons { itemStack(material) { name(name) loreWrapped("$description") - lore( - "", - player.tr("icon.currently", "value" to TownyUtil.onOff(player, value)), - player.tr("icon.click-toggle") - ) + loreBreak() + lore(player.tr("icon.currently", "value" to TownyUtil.onOff(player, value))) + loreActions(listOf(player.tr("icon.click-toggle"))) glow(value) } /** A player head for [resident], with extra lore [lines]. */ - fun resident(player: Player, resident: Resident, vararg lines: String): ItemStack = + fun resident( + player: Player, + resident: Resident, + vararg lines: String, + actions: List = emptyList(), + ): ItemStack = itemStack(Material.PLAYER_HEAD) { resident.uuid?.let { head(Bukkit.getOfflinePlayer(it)) } name((if (resident.isOnline) "" else "") + TownyUtil.name(resident.name)) val town = resident.townOrNull + if (resident.hasTitle() || resident.hasSurname()) { + val fullName = listOf( + TownyUtil.text(resident.title), + TownyUtil.name(resident.name), + TownyUtil.text(resident.surname) + ).filter { it.isNotBlank() } + lore("${fullName.joinToString(" ")}") + loreBreak() + } lore(buildList { - if (resident.hasTitle() || resident.hasSurname()) { - val fullName = listOf( - TownyUtil.text(resident.title), - TownyUtil.name(resident.name), - TownyUtil.text(resident.surname) - ).filter { it.isNotBlank() } - add("${fullName.joinToString(" ")}") - } add( player.tr( "icon.resident.town", @@ -66,16 +86,28 @@ object Icons { if (resident.isOnline) player.tr("icon.resident.online") else player.tr("icon.resident.last-online", "date" to TownyUtil.date(resident.lastOnline)) ) - addAll(lines) }) + if (lines.isNotEmpty()) { + loreBreak() + lore(lines.asList()) + } + loreActions(actions) } /** A summary icon for [town], with extra lore [lines]. */ - fun town(player: Player, town: Town, vararg lines: String): ItemStack = + fun town( + player: Player, + town: Town, + vararg lines: String, + actions: List = emptyList(), + ): ItemStack = itemStack(if (town.isCapital) Material.GOLDEN_HELMET else Material.BELL) { name("${TownyUtil.name(town.name)}") + TownyUtil.board(town)?.let { + lore("${TownyUtil.text(it).take(60)}") + loreBreak() + } lore(buildList { - TownyUtil.board(town)?.let { add("${TownyUtil.text(it).take(60)}") } add(player.tr("icon.town.mayor", "mayor" to (town.mayor?.let { TownyUtil.name(it.name) } ?: "-"))) add(player.tr("icon.town.residents", "count" to town.numResidents)) add(player.tr("icon.town.claims", "claims" to town.numTownBlocks, "max" to town.maxTownBlocksAsAString)) @@ -93,17 +125,29 @@ object Icons { ) if (town.isForSale) add(player.tr("icon.town.for-sale", "price" to TownyUtil.money(town.forSalePrice))) if (town.isRuined) add(player.tr("icon.town.ruined")) - addAll(lines) }) + if (lines.isNotEmpty()) { + loreBreak() + lore(lines.asList()) + } + loreActions(actions) glow(town.isOpen) } /** A summary icon for [nation], with extra lore [lines]. */ - fun nation(player: Player, nation: Nation, vararg lines: String): ItemStack = + fun nation( + player: Player, + nation: Nation, + vararg lines: String, + actions: List = emptyList(), + ): ItemStack = itemStack(Material.BEACON) { name("${TownyUtil.name(nation.name)}") + TownyUtil.board(nation)?.let { + lore("${TownyUtil.text(it).take(60)}") + loreBreak() + } lore(buildList { - TownyUtil.board(nation)?.let { add("${TownyUtil.text(it).take(60)}") } add(player.tr("icon.nation.leader", "leader" to (nation.king?.let { TownyUtil.name(it.name) } ?: "-"))) add( player.tr( @@ -126,7 +170,11 @@ object Icons { "peaceful" to TownyUtil.yesNo(player, nation.isNeutral) ) ) - addAll(lines) }) + if (lines.isNotEmpty()) { + loreBreak() + lore(lines.asList()) + } + loreActions(actions) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationListMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationListMenu.kt index 3d1103c..c4bfed3 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationListMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationListMenu.kt @@ -32,12 +32,7 @@ class NationListMenu(player: Player, back: Menu) : PagedMenu(player, player.tr(" .sortedWith(sort.comparator) .map { nation -> MenuEntry({ - Icons.nation( - player, - nation, - "", - tr("common.click-details") - ) + Icons.nation(player, nation, actions = listOf(tr("common.click-details"))) }) { NationInfoMenu(player, nation, this).open() } } @@ -47,7 +42,7 @@ class NationListMenu(player: Player, back: Menu) : PagedMenu(player, player.tr(" button(47, itemStack(Material.HOPPER) { name(tr("sort.current", "sort" to tr(sort.label))) lore(sorts.map { (if (it == sort) "▶ " else " ") + tr(it.label) }) - lore("", tr("common.click-change")) + loreActions(listOf(tr("common.click-change"))) }) { sort = sorts[(sorts.indexOf(sort) + 1) % sorts.size] render() diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt index 9b04fce..7a570a5 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationMenu.kt @@ -43,9 +43,7 @@ class NationMenu(player: Player, back: Menu?) : Menu(player, player.tr("nation.t ) ) } - add("") - add(tr("nation.click-status")) - }.toTypedArray())) { + }.toTypedArray(), actions = listOf(tr("nation.click-status")))) { NationStatusMenu(player, nation, this).open() } @@ -134,12 +132,7 @@ class NationMenu(player: Player, back: Menu?) : Menu(player, player.tr("nation.t .thenBy { it.name.lowercase() }) .map { member -> MenuEntry({ - Icons.resident( - player, - member, - "", - tr("common.click-view") - ) + Icons.resident(player, member, actions = listOf(tr("common.click-view"))) }) { ResidentProfileMenu(player, member, menu).open() } } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationRelationsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationRelationsMenu.kt index 7231213..a3c0c67 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationRelationsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationRelationsMenu.kt @@ -35,13 +35,11 @@ class NationRelationsMenu(player: Player, private val nation: Nation, back: Menu } private fun relation(other: Nation, label: String, canRemove: Boolean, removeCommand: String): MenuEntry { - val lines = listOfNotNull( - "", - label, + val actions = listOfNotNull( tr("common.left-details"), if (canRemove) tr("nation-relations.right-remove") else null ) - return MenuEntry({ Icons.nation(player, other, *lines.toTypedArray()) }) { click -> + return MenuEntry({ Icons.nation(player, other, label, actions = actions) }) { click -> if (click.isRightClick && canRemove) run(removeCommand, ::snapshot) else NationInfoMenu( player, other, @@ -87,8 +85,8 @@ class NationRelationsMenu(player: Player, private val nation: Nation, back: Menu button( 51, Icons.icon( Material.PAPER, tr("nation-relations.sent-requests"), null, - *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray(), - tr("common.pending", "count" to pending.size), + tr("common.pending", "count" to pending.size), "", + *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray() ) ) } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSanctionsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSanctionsMenu.kt index 8a48726..ef92c1e 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSanctionsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSanctionsMenu.kt @@ -29,12 +29,11 @@ class NationSanctionsMenu(player: Player, private val nation: Nation, back: Menu override fun entries(): List { val canEdit = canEdit return nation.sanctionedTowns.sortedBy { it.name.lowercase() }.map { town -> - val lines = listOfNotNull( - "", + val actions = listOfNotNull( tr("common.left-details"), if (canEdit) tr("nation-sanctions.right-lift") else null ) - MenuEntry({ Icons.town(player, town, *lines.toTypedArray()) }) { click -> + MenuEntry({ Icons.town(player, town, actions = actions) }) { click -> if (click.isRightClick && canEdit) { run("towny:nation sanctiontown remove ${town.name}", ::count) } else { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt index 54f6c8f..9c84cd5 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationSettingsMenu.kt @@ -93,7 +93,7 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n ) { ListMenu(player, tr("nation-details.capital-title"), this) { nation.towns.filter { !nation.isCapital(it) }.sortedBy { it.name.lowercase() }.map { town -> - MenuEntry({ Icons.town(player, town, "", tr("nation-details.capital-click")) }) { + MenuEntry({ Icons.town(player, town, actions = listOf(tr("nation-details.capital-click"))) }) { run("towny:nation set capital ${town.name}", { nation.capital }, returnTo = this) } } @@ -107,7 +107,12 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n ListMenu(player, tr("nation-details.leader-title"), this) { nation.capital?.residents.orEmpty().filter { !it.isKing }.sortedBy { it.name.lowercase() } .map { candidate -> - MenuEntry({ Icons.resident(player, candidate, "", tr("nation-details.leader-click")) }) { + MenuEntry({ + Icons.resident( + player, candidate, + actions = listOf(tr("nation-details.leader-click")) + ) + }) { run("towny:nation set king ${candidate.name}", { nation.king }, returnTo = this) } } @@ -166,7 +171,7 @@ class NationSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("n "$label", null, tr("common.current", "value" to current), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { prompt(label, tr("common.amount"), initial = read().toString()) { amount -> diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationTownsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationTownsMenu.kt index 110ab52..0bb9bd9 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationTownsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/nation/NationTownsMenu.kt @@ -27,13 +27,12 @@ class NationTownsMenu(player: Player, private val nation: Nation, back: Menu) : return nation.towns .sortedWith(compareByDescending { nation.isCapital(it) }.thenBy { it.name.lowercase() }) .map { town -> - val lines = buildList { - add("") - if (nation.isCapital(town)) add(tr("nation-towns.capital")) - add(tr("common.left-details")) - if (canKick && !nation.isCapital(town)) add(tr("nation-towns.right-remove")) - } - MenuEntry({ Icons.town(player, town, *lines.toTypedArray()) }) { click -> + val lines = listOfNotNull(if (nation.isCapital(town)) tr("nation-towns.capital") else null) + val actions = listOfNotNull( + tr("common.left-details"), + if (canKick && !nation.isCapital(town)) tr("nation-towns.right-remove") else null + ) + MenuEntry({ Icons.town(player, town, *lines.toTypedArray(), actions = actions) }) { click -> if (click.isRightClick && canKick && !nation.isCapital(town)) { run("towny:nation kick ${town.name}", { nation.numTowns }) } else { @@ -67,8 +66,8 @@ class NationTownsMenu(player: Player, private val nation: Nation, back: Menu) : button( 51, Icons.icon( Material.PAPER, tr("common.sent-invites"), null, - *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray(), - tr("common.pending", "count" to pending.size), + tr("common.pending", "count" to pending.size), "", + *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray() ) ) } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotAreaMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotAreaMenu.kt index 203f7d2..80c9649 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotAreaMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotAreaMenu.kt @@ -30,7 +30,7 @@ class PlotAreaMenu(player: Player, back: Menu) : Menu(player, player.tr("plot-ar 21, Icons.icon( if (circle) Material.SNOWBALL else Material.PAINTING, tr("plot-area.shape"), null, tr("common.current", "value" to tr(if (circle) "plot-area.circle" else "plot-area.square")), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { circle = !circle @@ -40,7 +40,7 @@ class PlotAreaMenu(player: Player, back: Menu) : Menu(player, player.tr("plot-ar 23, Icons.icon( Material.COMPASS, tr("plot-area.radius"), tr("plot-area.radius-description"), tr("common.current", "value" to radius), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { prompt(tr("plot-area.radius-title"), tr("claims.radius"), initial = radius, maxLength = 3) { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt index 718a079..db61244 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotMenu.kt @@ -135,8 +135,8 @@ class PlotMenu(player: Player, back: Menu?) : Menu(player, player.tr("plot.title ) ) add(tr("plot.claimed", "date" to TownyUtil.date(plot.claimedAt))) - if (canInfo) add(tr("plot.click-info")) - }.toTypedArray() + }.toTypedArray(), + actions = listOfNotNull(if (canInfo) tr("plot.click-info") else null) ) ) { if (canInfo) runAndClose("towny:plot info") diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotOverridesMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotOverridesMenu.kt index e266acb..0de8d89 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotOverridesMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotOverridesMenu.kt @@ -42,12 +42,9 @@ class PlotOverridesMenu(player: Player, private val plot: TownBlock, back: Menu) node(PermissionNodes.TOWNY_COMMAND_PLOT_GROUP_PERM, PermissionNodes.TOWNY_COMMAND_PLOT_PERM_REMOVE) ) return overrides().entries.sortedBy { it.key.name.lowercase() }.map { (target, data) -> - val lines = listOfNotNull( - "", - tr("plot-overrides.changed-by", "player" to TownyUtil.name(data.lastChangedBy ?: "-")), - if (canRemove) tr("plot-overrides.click-remove") else null, - ) - MenuEntry({ Icons.resident(player, target, *lines.toTypedArray()) }) { + val line = tr("plot-overrides.changed-by", "player" to TownyUtil.name(data.lastChangedBy ?: "-")) + val actions = listOfNotNull(if (canRemove) tr("plot-overrides.click-remove") else null) + MenuEntry({ Icons.resident(player, target, line, actions = actions) }) { if (canRemove) run("$command remove ${target.name}", ::snapshot) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotTrustMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotTrustMenu.kt index fa79e99..ffd1ae1 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotTrustMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/plot/PlotTrustMenu.kt @@ -37,7 +37,7 @@ class PlotTrustMenu(player: Player, private val plot: TownBlock, back: Menu) : override fun entries(): List = trusted().sortedBy { it.name.lowercase() }.map { trusted -> - MenuEntry({ Icons.resident(player, trusted, "", tr("common.click-untrust")) }) { + MenuEntry({ Icons.resident(player, trusted, actions = listOf(tr("common.click-untrust"))) }) { run("$command remove ${trusted.name}", ::count) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/FriendsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/FriendsMenu.kt index 93fffc9..48d6b83 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/FriendsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/FriendsMenu.kt @@ -20,11 +20,8 @@ class FriendsMenu(player: Player, back: Menu) : PagedMenu(player, player.tr("fri resident?.friends.orEmpty().sortedBy { it.name.lowercase() }.map { friend -> MenuEntry({ Icons.resident( - player, - friend, - "", - tr("friends.left-view"), - tr("friends.right-remove") + player, friend, + actions = listOf(tr("friends.left-view"), tr("friends.right-remove")) ) }) { click -> if (click.isRightClick) { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt index 2fe95e9..f3eb2ae 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentMenu.kt @@ -183,7 +183,7 @@ class ResidentMenu(player: Player, back: Menu?) : Menu(player, player.tr("profil TownyAPI.getInstance().getResident(player)?.let(source).orEmpty() .sortedBy { it.name.lowercase() } .map { town -> - MenuEntry({ Icons.town(player, town, "", tr("common.click-details")) }) { + MenuEntry({ Icons.town(player, town, actions = listOf(tr("common.click-details"))) }) { TownInfoMenu(player, town, menu).open() } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentPlotsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentPlotsMenu.kt index 0d0ba26..23748ba 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentPlotsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/resident/ResidentPlotsMenu.kt @@ -55,11 +55,8 @@ class ResidentPlotsMenu(player: Player, private val owner: Resident, back: Menu) ) ) } - if (town != null) { - add("") - add(tr("common.click-details")) - } - }.toTypedArray() + }.toTypedArray(), + actions = listOfNotNull(if (town != null) tr("common.click-details") else null) ) }) { town?.let { TownInfoMenu(player, it, this).open() } } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/JailSentenceMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/JailSentenceMenu.kt index 0ae5c6a..96e4e3f 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/JailSentenceMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/JailSentenceMenu.kt @@ -74,7 +74,7 @@ class JailSentenceMenu(player: Player, private val town: Town, private val targe Icons.icon( Material.IRON_BARS, tr("jail-sentence.jail"), null, tr("common.current", "value" to TownJailMenu.jailName(this, town, jail)), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { val options = jails.mapIndexed { index, option -> @@ -92,7 +92,7 @@ class JailSentenceMenu(player: Player, private val town: Town, private val targe Icons.icon( Material.IRON_CHAIN, tr("jail-sentence.cell"), null, tr("common.current", "value" to cell + 1), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { val options = (0 until jail.jailCellCount).map { diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutlawsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutlawsMenu.kt index 7c2e046..ed778aa 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutlawsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutlawsMenu.kt @@ -24,10 +24,8 @@ class OutlawsMenu(player: Player, private val town: Town, back: Menu) : return town.outlaws.sortedBy { it.name.lowercase() }.map { outlaw -> MenuEntry({ Icons.resident( - player, - outlaw, - "", - tr(if (canEdit) "outlaws.click-pardon" else "outlaws.outlaw") + player, outlaw, + actions = listOf(tr(if (canEdit) "outlaws.click-pardon" else "outlaws.outlaw")) ) }) { if (canEdit) run("towny:town outlaw remove ${outlaw.name}", ::count) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt index b38c41b..1d465de 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/OutpostsMenu.kt @@ -23,7 +23,7 @@ class OutpostsMenu(player: Player, private val town: Town, back: Menu) : tr("outposts.world", "world" to (location.world?.name ?: "-")), tr("outposts.location", "x" to location.blockX, "y" to location.blockY, "z" to location.blockZ), *listOfNotNull(cost).toTypedArray(), - "", tr("common.click-teleport"), + actions = listOf(tr("common.click-teleport")) ) } MenuEntry(icon) { runAndClose("towny:town outpost ${index + 1}") } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownJailMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownJailMenu.kt index 1860781..f210d84 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownJailMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownJailMenu.kt @@ -23,7 +23,6 @@ class TownJailMenu(player: Player, private val town: Town, back: Menu) : val canUnjail = TownyUtil.can(player, PermissionNodes.TOWNY_COMMAND_TOWN_UNJAIL) return town.jailedResidents.sortedBy { it.name.lowercase() }.map { prisoner -> val lines = buildList { - add("") add(tr("town-jail.hours-left", "hours" to prisoner.jailHours)) if (TownyUtil.economy && prisoner.jailBailCost > 0) { add(tr("town-jail.bail", "bail" to TownyUtil.money(prisoner.jailBailCost))) @@ -37,9 +36,9 @@ class TownJailMenu(player: Player, private val town: Town, back: Menu) : ) ) } - if (canUnjail) add(tr("town-jail.click-unjail")) } - MenuEntry({ Icons.resident(player, prisoner, *lines.toTypedArray()) }) { + val actions = listOfNotNull(if (canUnjail) tr("town-jail.click-unjail") else null) + MenuEntry({ Icons.resident(player, prisoner, *lines.toTypedArray(), actions = actions) }) { if (canUnjail) run("towny:town unjail ${prisoner.name}", ::count) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownListMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownListMenu.kt index 404dbe7..9cf9308 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownListMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownListMenu.kt @@ -34,12 +34,12 @@ class TownListMenu(player: Player, back: Menu) : PagedMenu(player, player.tr("to .sortedWith(sort.comparator(player)) .map { town -> val lines = listOfNotNull( - "", distance(player, town)?.takeIf { sort == Sort.NEARBY } ?.let { tr("town-list.distance", "blocks" to it.toLong()) }, - tr("common.click-details"), ) - MenuEntry({ Icons.town(player, town, *lines.toTypedArray()) }) { + MenuEntry({ + Icons.town(player, town, *lines.toTypedArray(), actions = listOf(tr("common.click-details"))) + }) { TownInfoMenu(player, town, this).open() } } @@ -53,7 +53,7 @@ class TownListMenu(player: Player, back: Menu) : PagedMenu(player, player.tr("to button(47, itemStack(Material.HOPPER) { name(tr("sort.current", "sort" to tr(sort.label))) lore(sorts.map { (if (it == sort) "▶ " else " ") + tr(it.label) }) - lore("", tr("common.click-change")) + loreActions(listOf(tr("common.click-change"))) }) { sort = sorts[(sorts.indexOf(sort) + 1) % sorts.size] render() diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMembersMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMembersMenu.kt index 014cd22..9d47593 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMembersMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMembersMenu.kt @@ -29,12 +29,7 @@ class TownMembersMenu(player: Player, private val town: Town, back: Menu) : .thenBy { it.name.lowercase() }) .map { member -> MenuEntry({ - Icons.resident( - player, - member, - "", - tr("common.click-view") - ) + Icons.resident(player, member, actions = listOf(tr("common.click-view"))) }) { ResidentProfileMenu(player, member, this).open() } } @@ -75,8 +70,8 @@ class TownMembersMenu(player: Player, private val town: Town, back: Menu) : guarded( 51, PermissionNodes.TOWNY_COMMAND_TOWN_INVITE_ADD, Icons.icon( Material.PAPER, tr("common.sent-invites"), tr("common.sent-invites-description"), - *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray(), - tr("common.pending", "count" to pending.size), + tr("common.pending", "count" to pending.size), "", + *pending.take(10).map { "- ${TownyUtil.name(it.receiver.name)}" }.toTypedArray() ) ) { click -> if (click.isRightClick) run("towny:town invite sent removeall", sent) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt index fbd4633..57ca396 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownMenu.kt @@ -66,9 +66,7 @@ class TownMenu(player: Player, back: Menu?) : Menu(player, player.tr("town.title add("") warnings.forEach { add(it.line) } } - add("") - add(tr("town.click-status")) - }.toTypedArray())) { + }.toTypedArray(), actions = listOf(tr("town.click-status")))) { TownStatusMenu(player, town, this).open() } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt index cb3b41c..c68659e 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownSettingsMenu.kt @@ -228,7 +228,7 @@ class TownSettingsMenu(player: Player, back: Menu) : Menu(player, player.tr("tow "$label", null, tr("common.current", "value" to current), - tr("common.click-change") + actions = listOf(tr("common.click-change")) ) ) { prompt(label, tr("common.amount"), initial = read().toString()) { amount -> diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownTrustMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownTrustMenu.kt index 5623697..3b02ddb 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownTrustMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/town/TownTrustMenu.kt @@ -25,10 +25,8 @@ class TownTrustMenu(player: Player, private val town: Town, back: Menu) : val residents = town.trustedResidents.sortedBy { it.name.lowercase() }.map { trusted -> MenuEntry({ Icons.resident( - player, - trusted, - "", - tr(if (canTrust) "common.click-untrust" else "town-trust.resident") + player, trusted, + actions = listOf(tr(if (canTrust) "common.click-untrust" else "town-trust.resident")) ) }) { if (canTrust) run("towny:town trust remove ${trusted.name}", ::snapshot) @@ -37,10 +35,8 @@ class TownTrustMenu(player: Player, private val town: Town, back: Menu) : val towns = town.trustedTowns.sortedBy { it.name.lowercase() }.map { trusted -> MenuEntry({ Icons.town( - player, - trusted, - "", - tr(if (canTrustTowns) "common.click-untrust" else "town-trust.town") + player, trusted, + actions = listOf(tr(if (canTrustTowns) "common.click-untrust" else "town-trust.town")) ) }) { if (canTrustTowns) run("towny:town trusttown remove ${trusted.name}", ::snapshot) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialChapterMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialChapterMenu.kt index 12129bb..6c7a2b3 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialChapterMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialChapterMenu.kt @@ -22,8 +22,9 @@ class TutorialChapterMenu(player: Player, private val chapter: Chapter, back: Me button(4, itemStack(chapter.material) { name(tr(chapter.title)) loreWrapped("${tr(chapter.description)}") - lore("", tr("tutorial.progress", "read" to read, "total" to lessons.size)) - chapter.link?.let { lore(linkLine(it)) } + loreBreak() + lore(tr("tutorial.progress", "read" to read, "total" to lessons.size)) + chapter.link?.let { loreActions(listOf(linkLine(it))) } glow(read == lessons.size) }) { if (chapter.link?.open(player, this) != true) render() } @@ -88,14 +89,24 @@ class TutorialChapterMenu(player: Player, private val chapter: Chapter, back: Me name(tr(if (read) "tutorial.lesson-read" else "tutorial.lesson-unread", "lesson" to tr(lesson.title))) loreWrapped("${tr(lesson.body)}") val facts = lesson.facts(player) - if (facts.isNotEmpty()) lore(listOf("") + facts) - lore("", tr(if (read) "tutorial.status-read" else "tutorial.status-unread")) + if (facts.isNotEmpty()) { + loreBreak() + lore(facts) + } + loreBreak() + lore(tr(if (read) "tutorial.status-read" else "tutorial.status-unread")) val link = lesson.link if (link != null && link.available(player)) { - lore(tr("tutorial.left-open"), tr(if (read) "tutorial.right-unread" else "tutorial.right-read")) + loreActions( + listOf(tr("tutorial.left-open"), tr(if (read) "tutorial.right-unread" else "tutorial.right-read")) + ) } else { - if (link != null) lore(linkLine(link)) - lore(tr(if (read) "tutorial.click-unread" else "tutorial.click-read")) + loreActions( + listOfNotNull( + link?.let { linkLine(it) }, + tr(if (read) "tutorial.click-unread" else "tutorial.click-read"), + ) + ) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialMenu.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialMenu.kt index 1de5541..55dc82c 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialMenu.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/guis/tutorial/TutorialMenu.kt @@ -19,7 +19,7 @@ class TutorialMenu(player: Player, back: Menu?) : Menu(player, player.tr("tutori button( 4, Icons.icon( - Material.KNOWLEDGE_BOOK, tr("tutorial.hub"), tr("tutorial.hub-description"), "", + Material.KNOWLEDGE_BOOK, tr("tutorial.hub"), tr("tutorial.hub-description"), tr("tutorial.progress", "read" to read, "total" to total), *listOfNotNull(if (read == total) tr("tutorial.all-read") else null).toTypedArray() ) @@ -61,9 +61,10 @@ class TutorialMenu(player: Player, back: Menu?) : Menu(player, player.tr("tutori val total = chapter.lessons.size name(tr(chapter.title)) loreWrapped("${tr(chapter.description)}") - lore("", tr("tutorial.progress", "read" to read, "total" to total)) + loreBreak() + lore(tr("tutorial.progress", "read" to read, "total" to total)) if (read == total) lore(tr("tutorial.chapter-complete")) - lore(tr("tutorial.click-chapter")) + loreActions(listOf(tr("tutorial.click-chapter"))) glow(read == total) } } diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/ItemStackDSL.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/ItemStackDSL.kt index bfd31e6..428968a 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/ItemStackDSL.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/ItemStackDSL.kt @@ -1,6 +1,5 @@ package net.trilleo.mc.plugins.townymenu.utils -import net.kyori.adventure.text.Component import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.Material import org.bukkit.OfflinePlayer @@ -19,11 +18,17 @@ import org.bukkit.inventory.meta.SkullMeta * ```kotlin * val icon = itemStack(Material.EMERALD) { * name("Deposit") - * lore("Add money to the town bank") - * glow(true) + * loreWrapped("Move money from your balance into the town bank.") + * loreBreak() + * lore("Balance: $120") + * loreActions(listOf("Click to deposit")) * } * ``` * + * Lore reads as blocks rather than one dense wall of text: [loreBreak] starts a + * new block and [loreActions] closes with the hints for what clicking does, set + * off by a divider rule. [LoreBlocks] documents how the blocks are laid out. + * * Use [loreWrapped] for long descriptions (wrapped with [LoreUtil]), [head] * for player heads, and the [meta] escape hatch for anything else. */ @@ -32,7 +37,7 @@ class ItemStackBuilder(private val material: Material) { private val miniMessage = MiniMessage.miniMessage() private var displayName: String? = null - private val loreLines = mutableListOf() + private val loreBlocks = LoreBlocks() private var glint: Boolean? = null private var isHideTooltip: Boolean = false private var headOwner: OfflinePlayer? = null @@ -50,12 +55,27 @@ class ItemStackBuilder(private val material: Material) { /** Appends lore lines; each line is parsed with MiniMessage independently. */ fun lore(lines: Iterable) { - lines.forEach { loreLines += miniMessage.deserialize("$it") } + lines.forEach { loreBlocks.add(miniMessage.deserialize("$it")) } } /** Appends [text] to the lore, word-wrapped by [LoreUtil.wrapLore]. */ fun loreWrapped(text: String, maxWidth: Int = 40) { - loreLines += LoreUtil.wrapLore(text, maxWidth) + LoreUtil.wrapLore(text, maxWidth).forEach(loreBlocks::add) + } + + /** Starts a new lore block, separated from the one above by a blank line. */ + fun loreBreak() { + loreBlocks.separator() + } + + /** + * Appends the icon's action hints — what a left- or right-click does — as the + * closing lore block, set off from the data above by a divider rule. + */ + fun loreActions(lines: Iterable) { + if (!lines.iterator().hasNext()) return + loreBlocks.divider() + lore(lines) } /** Forces the enchantment glint on (`true`) or off (`false`). */ @@ -80,10 +100,11 @@ class ItemStackBuilder(private val material: Material) { /** Builds the configured [ItemStack]. */ fun build(): ItemStack { + val lore = loreBlocks.render() val item = ItemStack(material) item.editMeta { meta -> displayName?.let { meta.displayName(miniMessage.deserialize("$it")) } - if (loreLines.isNotEmpty()) meta.lore(loreLines) + if (lore.isNotEmpty()) meta.lore(lore) glint?.let { meta.setEnchantmentGlintOverride(it) } meta.isHideTooltip = isHideTooltip meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ADDITIONAL_TOOLTIP) diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocks.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocks.kt new file mode 100644 index 0000000..9cb4568 --- /dev/null +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocks.kt @@ -0,0 +1,90 @@ +package net.trilleo.mc.plugins.townymenu.utils + +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.Style +import net.kyori.adventure.text.format.TextDecoration +import net.kyori.adventure.text.minimessage.MiniMessage +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer + +/** + * Assembles an icon's lore out of blocks, so a tooltip reads as description, + * data, and actions rather than one dense wall of text. + * + * Lines go in with [add], block boundaries with [separator], and the closing + * actions block with [divider]. [render] lays them out: + * + * - a blank line always follows the display name, so the title has room; + * - repeated separators collapse into one, and a line with no visible text + * counts as a separator, so callers may pass `""` between blocks; + * - a divider swallows the separators above it and is drawn as a rule as wide + * as the widest line; + * - separators left dangling at either end are dropped, so a caller may open a + * block that turns out to be empty without leaving a hole behind. + * + * @see ItemStackBuilder + */ +class LoreBlocks { + + private enum class Kind { TEXT, SEPARATOR, DIVIDER } + + private class Line(val component: Component, val kind: Kind) + + private val lines = mutableListOf() + + /** Appends [component], treating a line with no visible text as a [separator]. */ + fun add(component: Component) { + lines += Line(component, if (PLAIN.serialize(component).isBlank()) Kind.SEPARATOR else Kind.TEXT) + } + + /** Ends the current block; the next line starts a new one. */ + fun separator() { + lines += Line(BLANK, Kind.SEPARATOR) + } + + /** Ends the data blocks; what follows is the icon's actions, set off by a rule. */ + fun divider() { + lines += Line(BLANK, Kind.DIVIDER) + } + + /** The finished lore, or an empty list when nothing but separators was added. */ + fun render(): List { + val result = mutableListOf() + for (line in lines) { + when (line.kind) { + Kind.TEXT -> result += line + Kind.SEPARATOR -> if (result.lastOrNull()?.kind == Kind.TEXT) result += line + Kind.DIVIDER -> { + while (result.lastOrNull()?.kind == Kind.SEPARATOR) result.removeLast() + if (result.isNotEmpty()) result += line + } + } + } + while (result.isNotEmpty() && result.last().kind != Kind.TEXT) result.removeLast() + if (result.isEmpty()) return emptyList() + + val rule = rule(result) + return listOf(BLANK) + result.map { if (it.kind == Kind.DIVIDER) rule else it.component } + } + + /** + * The divider rule, as wide as the widest line. It is drawn as struck-through + * spaces, and a space is narrower than an average character, so the count is + * scaled up rather than matching the column count one to one. + */ + private fun rule(lines: List): Component { + val columns = lines.filter { it.kind == Kind.TEXT } + .maxOf { LoreUtil.columns(PLAIN.serialize(it.component)) } + val spaces = (columns * 3 / 2).coerceIn(MIN_RULE, MAX_RULE) + return MiniMessage.miniMessage().deserialize("" + " ".repeat(spaces)) + } + + private companion object { + val PLAIN: PlainTextComponentSerializer = PlainTextComponentSerializer.plainText() + + val BLANK: Component = Component.empty() + .style(Style.style().decoration(TextDecoration.ITALIC, false).build()) + + const val MIN_RULE = 16 + const val MAX_RULE = 60 + } +} diff --git a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreUtil.kt b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreUtil.kt index 916d64c..dff9518 100644 --- a/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreUtil.kt +++ b/src/main/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreUtil.kt @@ -82,6 +82,12 @@ object LoreUtil { return result } + /** + * The display width of [text] in columns, the same measure [wrapLore] wraps on: + * Chinese, Japanese, and Korean characters count as two. + */ + fun columns(text: String): Int = text.sumOf { width(it) } + /** * Represents a single visible character paired with its resolved style. */ diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index 57ea3f2..c283f73 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -90,7 +90,7 @@ icon: currently: "Currently: {value}" click-toggle: "Click to toggle" bank: "Bank: {balance}" - open-public: "Open: {open} Public: {public}" + open-public: "Open: {open} · Public: {public}" resident: town: "Town: {town}" mayor: "Mayor" @@ -107,9 +107,9 @@ icon: nation: leader: "Leader: {leader}" capital: "Capital: {capital}" - size: "Towns: {towns} Residents: {residents}" - relations: "Allies: {allies} Enemies: {enemies}" - flags: "Open: {open} Public: {public} Peaceful: {peaceful}" + size: "Towns: {towns} · Residents: {residents}" + relations: "Allies: {allies} · Enemies: {enemies}" + flags: "Open: {open} · Public: {public} · Peaceful: {peaceful}" main: title: "Towny" @@ -253,8 +253,8 @@ town: not-in-town: "You are not in a town" plot-tax: "Plot tax: {tax}" outposts: "Outposts: {count}" - pvp-mobs: "PvP: {pvp} Mobs: {mobs}" - fire-explosions: "Fire: {fire} Explosions: {explosions}" + pvp-mobs: "PvP: {pvp} · Mobs: {mobs}" + fire-explosions: "Fire: {fire} · Explosions: {explosions}" residents: "Residents" residents-description: "View residents, manage ranks, and invite players." bank: "Town Bank" @@ -360,7 +360,7 @@ claims: claimed: "Claimed: {claims}/{max}" available: "Available: {available}" unlimited: "Unlimited" - bonus: "Bonus claims: {bonus} Purchased: {purchased}" + bonus: "Bonus claims: {bonus} · Purchased: {purchased}" outposts: "Outposts: {outposts}/{limit}" price: "Claim price: {price}" claim: "Claim This Chunk" diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index bf4d0cf..7c17533 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -90,7 +90,7 @@ icon: currently: "当前: {value}" click-toggle: "点击切换" bank: "银行: {balance}" - open-public: "开放: {open} 公开: {public}" + open-public: "开放: {open} · 公开: {public}" resident: town: "城镇: {town}" mayor: "镇长" @@ -107,9 +107,9 @@ icon: nation: leader: "国王: {leader}" capital: "首都: {capital}" - size: "城镇: {towns} 居民: {residents}" - relations: "盟友: {allies} 敌人: {enemies}" - flags: "开放: {open} 公开: {public} 和平: {peaceful}" + size: "城镇: {towns} · 居民: {residents}" + relations: "盟友: {allies} · 敌人: {enemies}" + flags: "开放: {open} · 公开: {public} · 和平: {peaceful}" main: title: "Towny" @@ -253,8 +253,8 @@ town: not-in-town: "你不在任何城镇中" plot-tax: "地块税: {tax}" outposts: "前哨: {count}" - pvp-mobs: "PvP: {pvp} 怪物: {mobs}" - fire-explosions: "火焰: {fire} 爆炸: {explosions}" + pvp-mobs: "PvP: {pvp} · 怪物: {mobs}" + fire-explosions: "火焰: {fire} · 爆炸: {explosions}" residents: "居民" residents-description: "查看居民、管理职位和邀请玩家。" bank: "城镇银行" @@ -360,7 +360,7 @@ claims: claimed: "已占领: {claims}/{max}" available: "可用: {available}" unlimited: "无限" - bonus: "额外领地: {bonus} 已购买: {purchased}" + bonus: "额外领地: {bonus} · 已购买: {purchased}" outposts: "前哨: {outposts}/{limit}" price: "占领价格: {price}" claim: "占领此区块" diff --git a/src/test/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocksTest.kt b/src/test/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocksTest.kt new file mode 100644 index 0000000..2ab94ff --- /dev/null +++ b/src/test/kotlin/net/trilleo/mc/plugins/townymenu/utils/LoreBlocksTest.kt @@ -0,0 +1,106 @@ +package net.trilleo.mc.plugins.townymenu.utils + +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class LoreBlocksTest { + + private val plain = PlainTextComponentSerializer.plainText() + + private fun blocks(build: LoreBlocks.() -> Unit): List = + LoreBlocks().apply(build).render().map { plain.serialize(it) } + + private fun LoreBlocks.text(value: String) = add(Component.text(value)) + + @Test + fun `nothing added renders nothing`() { + assertEquals(emptyList(), blocks {}) + } + + @Test + fun `a blank line always follows the display name`() { + assertEquals(listOf("", "Residents: 12"), blocks { text("Residents: 12") }) + } + + @Test + fun `separators divide blocks`() { + val lore = blocks { + text("A description.") + separator() + text("Residents: 12") + } + assertEquals(listOf("", "A description.", "", "Residents: 12"), lore) + } + + @Test + fun `repeated separators collapse into one`() { + val lore = blocks { + text("A description.") + separator() + separator() + add(Component.empty()) + text("Residents: 12") + } + assertEquals(listOf("", "A description.", "", "Residents: 12"), lore) + } + + @Test + fun `separators at either end are dropped`() { + val lore = blocks { + separator() + text("Residents: 12") + separator() + } + assertEquals(listOf("", "Residents: 12"), lore) + } + + @Test + fun `a divider replaces the separator above it`() { + val lore = blocks { + text("A description.") + separator() + divider() + text("Click to view") + } + assertEquals(4, lore.size) + assertEquals(listOf("", "A description."), lore.take(2)) + assertTrue(lore[2].isNotEmpty() && lore[2].isBlank(), "expected a rule, got '${lore[2]}'") + assertEquals("Click to view", lore[3]) + } + + @Test + fun `a divider with nothing above it is dropped`() { + val lore = blocks { + divider() + text("Click to view") + } + assertEquals(listOf("", "Click to view"), lore) + } + + @Test + fun `a trailing divider is dropped`() { + val lore = blocks { + text("Residents: 12") + divider() + } + assertEquals(listOf("", "Residents: 12"), lore) + } + + @Test + fun `the rule is as wide as the widest line`() { + val short = blocks { + text("Cost: 25") + divider() + text("Go") + } + val long = blocks { + text("A considerably longer line of lore text") + divider() + text("Go") + } + assertTrue(short[2].length < long[2].length, "the rule should grow with the lore") + } +} From f349a41bd4018a2d5ede68701248a9f49542cf08 Mon Sep 17 00:00:00 2001 From: Trilleo Date: Fri, 18 Sep 2026 13:28:21 +0800 Subject: [PATCH 4/4] Update: Plugin version 1.0.1 release --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edf748d..d6c53ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## Version 1.0.1 + ### Improvements #### Town Menu diff --git a/gradle.properties b/gradle.properties index fe1fccd..d2496dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ kotlin.code.style=official # Plugin Properties -plugin_version=1.0.0 +plugin_version=1.0.1 # Dependency Versions towny_version=0.103.2.7