Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,65 @@

## Unreleased

## Version 1.0.1

### 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.
+ 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

#### 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
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

### New Features
Expand Down
18 changes: 15 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ Before finishing any task that changes the plugin, do all of the following:

```powershell
./gradlew build # Builds build/libs/TownyMenu-<version>.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.

Expand All @@ -77,7 +79,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
Expand Down Expand Up @@ -115,6 +117,16 @@ 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.
- **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

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,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.

Expand Down
15 changes: 11 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Copy>("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<Copy>("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<JavaExec>("startServer") {
Expand Down
60 changes: 57 additions & 3 deletions docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ 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.
- **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.
Expand All @@ -305,6 +311,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. |
Expand Down Expand Up @@ -339,7 +347,7 @@ visible page are built:
```kotlin
override fun entries(): List<MenuEntry> =
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()
}
}
Expand All @@ -355,7 +363,7 @@ override fun entries(): List<MenuEntry> =
| `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`)

Expand Down Expand Up @@ -434,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
Expand Down Expand Up @@ -1066,7 +1119,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.

---

Expand Down
Loading