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
30 changes: 30 additions & 0 deletions .github/workflows/module-example-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Module Example CI
on:
push:
branches: ['**']
pull_request:
permissions:
contents: read
jobs:
verify:
name: Test & package module (JDK ${{ matrix.java-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java-version: ['25']
steps:
- name: Checkout
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
cache: maven
cache-dependency-path: module-example/pom.xml
- name: Verify module
working-directory: module-example
# -U: this build depends on UltiTools-API 7.0.0-SNAPSHOT, and the restored Maven cache can hold
# an older snapshot that Maven would otherwise not re-check until the next day.
run: mvn -B -ntp -U clean verify
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ With the server stopped, install `target/UltiTools-External-Example-1.0.0.jar` i
## License

MIT

## UltiTools Module Example

See [FieldJournal](module-example/) for a separate Maven project that runs as an UltiTools 7.0 module, rather than a standalone Paper plugin.
16 changes: 16 additions & 0 deletions module-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target/
*.class
*.jar
*.log

# IDE
.idea/
*.iml
.vscode/
.settings/
.project
.classpath

# OS
.DS_Store
Thumbs.db
43 changes: 43 additions & 0 deletions module-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# FieldJournal

An UltiTools **module** for recording exploration sites and keeping a short note per player. It is independent of the standalone Paper plugin example at the repository root.

## Build and install

Run `mvn -B -ntp clean verify` in this directory with JDK 25. The `pom.xml` uses UltiTools-API `7.0.0-SNAPSHOT` from Maven Central snapshots and Paper API as `provided` dependencies. The JAR contains the module's descriptor and catalogues, not the server or framework.

On a stopped server running UltiTools 7.0, put `target/FieldJournal-1.0.0.jar` in `plugins/UltiTools/plugins/`, not directly in `plugins/`, then start the server. The root `plugin.yml` declares the module API level as the integer `700`.

## Use the journal

All commands are in-game only and require `fieldjournal.use`. On a fresh server with no permissions plugin, use an operator to try them.

| Command | What it does |
| --- | --- |
| `/fieldjournal record <site>` | Records `forest`, `river`, or `mountain` (Tab suggests them). Increments your count and replaces the latest site without changing your note. |
| `/fieldjournal status` | Reads your count, latest site, and note from module storage. |
| `/fieldjournal note` | Opens a native dialog. Submit a short note after recording a site; closing the dialog does not save. |
| `/fieldjournal book` | Opens a chest screen. The centre book shows your saved journal in chat and closes the screen. |

The module uses the framework's selected data backend; no separate database credentials are needed for the default SQLite setup. With the framework's `language: auto`, replies and UI labels follow the player's client language (English or Chinese). Site tokens in the command remain English.

## Configure and reload

Edit `plugins/UltiTools/pluginConfig/FieldJournal/config/journal.yml`, then run `/ul reload`:

- `journal-name` defaults to `Field Journal`. It must not be blank or longer than 40 characters. A valid change appears the next time you open a journal screen; a refused change keeps the previous running value.
- `reminder-seconds` defaults to `60`. Use a positive integer (up to `107374182`). Both the initial delay and the interval use this setting. A successful reload updates the running schedule; an out-of-range setting keeps the previous timing. The reminder appears in the action bar for online players with `fieldjournal.use`.

The early hook contributes `fieldjournal:trail_mark` (`Trail Mark`), a level-one enchantment for a diamond shovel. The demo enchantment has no additional gameplay effect. The contribution is made on server start, not on `/ul reload`.

See [UAT-CHECKLIST.md](UAT-CHECKLIST.md) for steps to verify the module on Paper. Unit tests cover module behavior and public API arguments; they do not start a Paper server.

## 中文速览

用 JDK 25 运行 `mvn -B -ntp clean verify`,在服务器停止时将 `target/FieldJournal-1.0.0.jar` 放入 `plugins/UltiTools/plugins/`,再启动服务器。需要 UltiTools 7.0。

持有 `fieldjournal.use` 权限的玩家可用 `/fieldjournal record <site>` 记录地点、`status` 查询、`note` 打开表单保存笔记、`book` 打开箱子界面查看记录。框架设为 `language: auto` 时,中文客户端会收到中文消息。修改 `config/journal.yml` 后运行 `/ul reload` 可更新界面名称和提醒间隔;引导期注册的附魔只在启动时贡献。

## License

MIT
25 changes: 25 additions & 0 deletions module-example/UAT-CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# FieldJournal 1.0.0 — Paper acceptance checklist

Use a fresh Paper 26.3 server (build 258) on Java 25 and a matching UltiTools 7.0 framework JAR. Put the framework JAR in `plugins/`. In the framework's `plugins/UltiTools/config.yml`, use `language: auto`, `fallback-language: en`, and `datasource.type: sqlite`; let the framework generate its config on a first start without the module if needed, then stop it. With the server stopped, put `target/FieldJournal-1.0.0.jar` in `plugins/UltiTools/plugins/`, start the server and keep the startup log. Do not use Bukkit `/reload`.

Use a player with `fieldjournal.use` (make the player an operator on the fresh server) and an ordinary non-operator without that permission. Start the first player in English (US). Join or reconnect both players after setting their permissions. Run the rows in order with the same first player so the counts and note below match. Command examples with `/` are for the client; omit `/` in the server console. Expected messages below give the displayed text, without colour or log prefixes.

| ID | Preconditions | Steps | Expected |
| --- | --- | --- | --- |
| Command | First player has no journal entries; second player has no permission. | As the second player, type `/fieldj` and inspect suggestions without executing. As the first player, type `/fieldjournal record r` without executing and inspect suggestions. Then send `/fieldjournal record forest`. | `/fieldjournal` is absent from the second player's suggestions. `river` is offered to the first player. Sending the command shows `Recorded forest (entries: 1).` |
| Messages | Command row passed; framework uses `language: auto`. | Run `/fieldjournal status` in English. Change the client language to 简体中文 (中国), then run `/fieldjournal status` again as the same player. Switch the client back to English. | In English: `Entries: 1; latest site: forest.` In Chinese: `累计 1 条;最近地点:森林。` |
| Dialog | Messages row passed and the client is back in English. | Run `/fieldjournal note`. Type `Blue moss` in the text box and press the save button. Open the form again, type `Unsaved note`, press **Cancel**, then run `/fieldjournal status`. | The native dialog title is `Field Journal — New note`, with `Field note` and `Save note`. Submission prints `Saved field note: Blue moss`. After cancellation, status still includes `Field note: Blue moss`. |
| Chest | Dialog row passed, with `Blue moss` saved. | Run `/fieldjournal book`. Click the writable book in the centre of the one-row chest screen. | Title: `Field Journal — Journal book`. Book name: `Read saved journal`. The chest closes and chat shows `Entries: 1; latest site: forest.` and `Field note: Blue moss`. |
| Scheduled task | Server ticking at about 20 TPS; first player in game. Config still uses the default `reminder-seconds: 60`. | Observe at least two consecutive reminder ticks in the console. Change `reminder-seconds` to `5` in `plugins/UltiTools/pluginConfig/FieldJournal/config/journal.yml` and run `/ul reload` from the console. Observe the next three tick lines and the first player's action bar. | Each tick logs `Field Journal reminder tick.` The default log spacing is about 60 seconds; after reload it is about 5 seconds (measure consecutive lines after the first post-reload tick). The player sees `Field Journal reminder: record a site or add a note.` |
| Configuration | Journal screen closed; file generated in the previous row. | Set `journal-name: Ranger Log` in the same file. Run `/ul reload`, then open and close `/fieldjournal book`. Set `journal-name: ' '` and run `/ul reload` again; reopen the book. Restore `journal-name: Ranger Log` in the file and reload before moving on. | The book title changes from `Field Journal — Journal book` to `Ranger Log — Journal book`. The blank value is refused (the console contains `Module 'FieldJournal' failed to reload:` and `journalName`), and the book still opens as `Ranger Log — Journal book`. |
| Data | Same first player with one recorded site and `Blue moss` saved; SQLite backend selected. | Send `/fieldjournal record river` and `/fieldjournal status`. Stop the server normally; with it stopped, use SQLite in read-only mode to inspect the module DB (example below). Start it again and run `/fieldjournal status` as the same player. | Before stop: `Recorded river (entries: 2).`, `Entries: 2; latest site: river.` and `Field note: Blue moss`. Table `field_journal_entries` contains one row with `2`, `river`, `Blue moss`. After restart, the same two status lines appear without recording again. |
| Bootstrap | Startup log retained; an operator in survival has an empty inventory slot. | Look for the module's declaration in the startup log before enable. Use `give <player> minecraft:diamond_shovel` in the console. Have the player hold the shovel and run `enchant <player> fieldjournal:trail_mark 1` from the console. Inspect the shovel's tooltip. | The bootstrap logger prints `Declared Trail Mark (fieldjournal:trail_mark).` The held shovel gains an enchantment named `Trail Mark`; a successful declaration log alone does not pass this row. |

Example read-only table check, from the stopped server's directory (requires the `sqlite3` CLI):

```bash
sqlite3 -readonly plugins/UltiTools/sqliteDB/FieldJournal.db \
'SELECT entry_count, site, note FROM field_journal_entries;'
```

Expected output on this fresh setup: `2|river|Blue moss`.
142 changes: 142 additions & 0 deletions module-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ultikits.plugins</groupId>
<artifactId>FieldJournal</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>FieldJournal</name>
<description>Record and revisit your exploration notes</description>

<properties>
<java.version>25</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ultitools.version>7.0.0-SNAPSHOT</ultitools.version>
</properties>

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>central-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>26.3.build.258-stable</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ultikits</groupId>
<artifactId>UltiTools-API</artifactId>
<version>${ultitools.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.48</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>6.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>6.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>6.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.24.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.24.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.16.0</version>
<configuration>
<release>${java.version}</release>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.48</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.6.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.16</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.fieldjournal;

import com.ultikits.ultitools.abstracts.UltiToolsPlugin;
import com.ultikits.ultitools.annotations.UltiToolsModule;

@UltiToolsModule(scanBasePackages = "com.example.fieldjournal")
public class FieldJournal extends UltiToolsPlugin {

@Override
public boolean registerSelf() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.fieldjournal;

import com.ultikits.ultitools.bootstrap.ModuleBootstrap;
import com.ultikits.ultitools.bootstrap.ModuleBootstrapContext;
import com.ultikits.ultitools.text.MessageKey;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.set.RegistrySet;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.bukkit.inventory.EquipmentSlotGroup;

public final class FieldJournalBootstrap implements ModuleBootstrap {
@Override
public void bootstrap(ModuleBootstrapContext context) {
Key trailMark = Key.key(MessageKey.namespaceFor(context.moduleName()), "trail_mark");
Key shovel = Key.key("minecraft:diamond_shovel");
context.enchantments().register(trailMark, (builder, tags) -> builder
.description(Component.text("Trail Mark"))
.supportedItems(RegistrySet.keySet(RegistryKey.ITEM, RegistryKey.ITEM.typedKey(shovel)))
.weight(5).maxLevel(1)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(1, 0))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(21, 0))
.anvilCost(1).activeSlots(EquipmentSlotGroup.MAINHAND));
context.logger().info("Declared Trail Mark (" + trailMark.asString() + ").");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.fieldjournal;

import com.ultikits.ultitools.abstracts.command.BaseCommandExecutor;
import com.ultikits.ultitools.annotations.command.CmdExecutor;
import com.ultikits.ultitools.annotations.command.CmdMapping;
import com.ultikits.ultitools.annotations.command.CmdParam;
import com.ultikits.ultitools.annotations.command.CmdSender;
import com.ultikits.ultitools.annotations.command.CmdTarget;
import com.ultikits.ultitools.text.Arg;
import com.ultikits.ultitools.text.Messages;
import com.ultikits.ultitools.text.Text;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.Locale;

@CmdExecutor(alias = {"fieldjournal"}, permission = JournalCommand.PERMISSION, description = "command.description")
@CmdTarget(CmdTarget.CmdTargetType.PLAYER)
public class JournalCommand extends BaseCommandExecutor {
static final String PERMISSION = "fieldjournal.use";
private static final List<String> SITES = List.of("forest", "river", "mountain");

private final JournalStore store;
private final JournalScreens screens;
private final Messages messages;

public JournalCommand(JournalStore store, JournalScreens screens, Messages messages) {
this.store = store;
this.screens = screens;
this.messages = messages;
}

@CmdMapping(format = "record <site>")
public void record(@CmdSender Player player, @CmdParam(value = "site", suggest = "suggestSites") String site) {
String normalized = site.toLowerCase(Locale.ROOT);
if (!SITES.contains(normalized)) {
messages.send(player, messages.key("command.invalid-site"));
return;
}
JournalEntry entry = store.record(player.getUniqueId(), normalized);
messages.send(player, messages.key("journal.recorded"),
Arg.text("site", Text.of(messages.key("site." + entry.site()))),
Arg.number("count", entry.entryCount()));
}

public List<String> suggestSites(String partial) {
String prefix = partial.toLowerCase(Locale.ROOT);
return SITES.stream().filter(site -> site.startsWith(prefix)).toList();
}

@CmdMapping(format = "status")
public void status(@CmdSender Player player) {
screens.showStatus(player);
}

@CmdMapping(format = "note")
public void note(@CmdSender Player player) {
screens.openNote(player);
}

@CmdMapping(format = "book")
public void book(@CmdSender Player player) {
screens.openBook(player);
}

@Override
protected void handleHelp(CommandSender sender) {
messages.send(sender, messages.key("command.help"));
}
}
Loading