Paper Custom Advancements
ASecurityPaper 自訂進度:以插件內附資料包放進度 JSON(自己的分頁、背景、父子關係、隱藏挑戰、獎勵),只用不帶條件的 minecraft:impossible/tick 觸發讓同一份 JSON 在 1.21.11 與 26.3 都能載入,由 Java 授予條件(AdvancementProgress#awardCriteria)、多條件做進度條、PDC 計數、PlayerAdvancementDoneEvent 改公告 / Paper custom advancements: advancement JSON in a plugin-bundled data pack (own tab, background, parents, hidden challenges, rewards), only condition-free minecraft:impossible / tick triggers so one JSON loads on 1.21.11 and 26.3, criteria awarded from Java (AdvancementProgress#award...
- 3 stars
- 0 votes
- 0 copies
- 0 views
- Added December 5, 2026
Works with
Security analysis
100/100Pro scans all 4 files and shows the line behind each finding
npx -y skills add MrPippi/MJP-Paper-Skills --skill paper-custom-advancements --agent claude-codeAre you the author of Paper Custom Advancements?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mrpippi-paper-custom-advancements)---
name: paper-custom-advancements
description: "Paper 自訂進度:以插件內附資料包放進度 JSON(自己的分頁、背景、父子關係、隱藏挑戰、獎勵),只用不帶條件的 minecraft:impossible/tick 觸發讓同一份 JSON 在 1.21.11 與 26.3 都能載入,由 Java 授予條件(AdvancementProgress#awardCriteria)、多條件做進度條、PDC 計數、PlayerAdvancementDoneEvent 改公告 / Paper custom advancements: advancement JSON in a plugin-bundled data pack (own tab, background, parents, hidden challenges, rewards), only condition-free minecraft:impossible / tick triggers so one JSON loads on 1.21.11 and 26.3, criteria awarded from Java (AdvancementProgress#awardCriteria), multi-criteria progress bars, PDC counters, PlayerAdvancementDoneEvent announcements"
---
# Paper Custom Advancements
## Skill Name
`paper-custom-advancements`
## Purpose
Custom advancements give quests, achievements and tutorials the vanilla UI: their own tab with a background, toasts, chat announcements and a progress bar, without a GUI plugin. The reliable way to add them is a data pack bundled in the plugin jar (see `paper-datapack-bundling`) whose advancements use **condition-free triggers**, while the plugin decides when a criterion is met:
| Choice | Why |
|------|------|
| Data pack, not `Bukkit.getUnsafe().loadAdvancement` | The unsafe call is deprecated, bypasses the data pack system and is lost on `/minecraft:reload`; data pack advancements survive reloads |
| `minecraft:impossible` criteria + `awardCriteria` from Java | Game logic stays in the plugin (config, database, custom events); the JSON has no conditions to break between versions |
| `minecraft:tick` for the root | Granted on the first tick to every player, so the tab is visible immediately |
| One criterion per step (`kill_1`..`kill_5`) | The client shows "3/5" progress when every criterion is required |
Version check (vanilla advancement JSON of 1.21.11 and 26.3 compared file by file): the `display` block (`icon`, `title`, `description`, `frame`, `background`, `show_toast`, `announce_to_chat`, `hidden`), `parent`, `requirements` and `rewards.experience` are written the same way on both (26.3 only omits a default `"count": 1` in icons). Trigger **conditions** changed: entity predicates became a single object with `"type": "minecraft:entity_properties"` instead of a list with `"condition"`. Advancements without conditions are therefore portable; ones with conditions need per-version folders (`paper-datapack-bundling`, example 2).
Runtime-checked on Paper 26.3 and 1.21.11 (no player online): the four advancements of this template load from the bundled pack with their tab, parents, criteria, requirements, frames and hidden flag, and are still there after `/minecraft:reload`.
## Paper Version Requirements
- Paper 1.21.11 / 26.3: `Advancement`, `AdvancementProgress`, `io.papermc.paper.advancement.AdvancementDisplay`, `PlayerAdvancementDoneEvent`, `LifecycleEvents.DATAPACK_DISCOVERY` have identical signatures on both; compile-verified and runtime-checked on both
- `pack.mcmeta` range `[94, 1]`..`121` accepts both servers (data pack formats in `paper-datapack-bundling`)
- **Spigot**: no `PluginBootstrap`; the admin installs the data pack into `world/datapacks/`, and the Java part works unchanged except `AdvancementDisplay` (Spigot has `org.bukkit.advancement.AdvancementDisplay` with `getTitle()` strings)
## Triggers
- 「自訂進度」「custom advancement」「成就」「achievement」「任務進度」「quest advancement」「進度分頁」
- 「awardCriteria」「AdvancementProgress」「PlayerAdvancementDoneEvent」「minecraft:impossible」
- 「進度條」「隱藏挑戰」「進度獎勵」「進度公告」
## Inputs
| Parameter | Example | Description |
|------|------|------|
| `tab` | "Quests" with a stone background | Root advancement: title, icon, background |
| `advancements` | first steps, slayer (5 kills), secret | Each advancement: parent, frame, criteria count, hidden, rewards |
| `triggers` | first join, mob kills | Game events that award criteria |
| `announcement` | custom chat line, none for secrets | How completion is announced |
## Outputs
- `src/main/resources/quests/pack.mcmeta` and `data/example/advancement/quests/*.json` — the tab and its advancements
- `QuestBootstrap.java` — registers the bundled pack during bootstrap
- `Quests.java` — awards single criteria and step counters, reads progress
- `QuestPlugin.java` — awards on join and on kills (counter in the player's PDC), customizes announcements
## Build Setup
See [`references/paper-api-platform.md`](references/paper-api-platform.md). Only `paper-api` (`compileOnly`). Uses `paper-plugin.yml` with a `bootstrapper` (required for `DATAPACK_DISCOVERY`):
```yaml
name: Quests
version: 1.0.0
main: com.example.quests.QuestPlugin
bootstrapper: com.example.quests.QuestBootstrap
api-version: '26.3'
```
## Code Template
### `src/main/resources/quests/pack.mcmeta`
```json
{
"pack": {
"description": "Quest advancements bundled with the Quests plugin",
"min_format": [94, 1],
"max_format": 121
}
}
```
### `src/main/resources/quests/data/example/advancement/quests/root.json`
```json
{
"criteria": {
"joined": {
"trigger": "minecraft:tick"
}
},
"display": {
"icon": {
"id": "minecraft:writable_book"
},
"title": {
"text": "Quests"
},
"description": {
"text": "Server quests and challenges"
},
"background": "minecraft:gui/advancements/backgrounds/stone",
"show_toast": false,
"announce_to_chat": false
}
}
```
### `src/main/resources/quests/data/example/advancement/quests/first_steps.json`
```json
{
"parent": "example:quests/root",
"criteria": {
"done": {
"trigger": "minecraft:impossible"
}
},
"display": {
"icon": {
"id": "minecraft:oak_sapling"
},
"title": {
"text": "First Steps"
},
"description": {
"text": "Join the server"
},
"frame": "task"
}
}
```
### `src/main/resources/quests/data/example/advancement/quests/slayer.json`
```json
{
"parent": "example:quests/first_steps",
"criteria": {
"kill_1": { "trigger": "minecraft:impossible" },
"kill_2": { "trigger": "minecraft:impossible" },
"kill_3": { "trigger": "minecraft:impossible" },
"kill_4": { "trigger": "minecraft:impossible" },
"kill_5": { "trigger": "minecraft:impossible" }
},
"requirements": [["kill_1"], ["kill_2"], ["kill_3"], ["kill_4"], ["kill_5"]],
"display": {
"icon": {
"id": "minecraft:iron_sword"
},
"title": {
"text": "Slayer"
},
"description": {
"text": "Defeat 5 hostile mobs"
},
"frame": "goal"
},
"rewards": {
"experience": 50
}
}
```
### `src/main/resources/quests/data/example/advancement/quests/secret.json`
```json
{
"parent": "example:quests/first_steps",
"criteria": {
"found": {
"trigger": "minecraft:impossible"
}
},
"display": {
"icon": {
"id": "minecraft:ender_eye"
},
"title": {
"text": "Hidden Path"
},
"description": {
"text": "Find the secret room"
},
"frame": "challenge",
"hidden": true,
"announce_to_chat": false
}
}
```
### `QuestBootstrap.java`
```java
package com.example.quests;
import io.papermc.paper.datapack.Datapack;
import io.papermc.paper.datapack.DiscoveredDatapack;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.kyori.adventure.text.Component;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** Registers src/main/resources/quests/ as a data pack. Never throws; problems are reported by QuestPlugin. */
public final class QuestBootstrap implements PluginBootstrap {
static final String PACK_ID = "quests";
private final List<String> problems = new CopyOnWriteArrayList<>();
@Override
public void bootstrap(BootstrapContext context) {
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> {
try {
URL root = QuestBootstrap.class.getResource("/" + PACK_ID);
if (root == null) {
problems.add("/" + PACK_ID + " is missing from the jar");
return;
}
DiscoveredDatapack pack = event.registrar().discoverPack(root.toURI(), PACK_ID, config -> config
.title(Component.text("Quest advancements"))
.autoEnableOnServerStart(true)
.position(false, Datapack.Position.TOP));
if (pack == null) {
problems.add("pack.mcmeta missing or invalid");
} else if (pack.getCompatibility() != Datapack.Compatibility.COMPATIBLE) {
problems.add("pack format range does not include this server (" + pack.getCompatibility() + ")");
}
} catch (URISyntaxException | IOException | RuntimeException e) {
problems.add("discovery failed: " + e);
}
});
}
@Override
public JavaPlugin createPlugin(PluginProviderContext context) {
return new QuestPlugin(problems);
}
}
```
### `Quests.java`
```java
package com.example.quests;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Optional;
/** Awards the plugin's advancements. Call on the player's thread (main thread on Paper). */
public final class Quests {
public static final NamespacedKey ROOT = key("quests/root");
public static final NamespacedKey FIRST_STEPS = key("quests/first_steps");
public static final NamespacedKey SLAYER = key("quests/slayer");
public static final NamespacedKey SECRET = key("quests/secret");
public static final List<NamespacedKey> ALL = List.of(ROOT, FIRST_STEPS, SLAYER, SECRET);
private Quests() {
}
public static NamespacedKey key(String path) {
return new NamespacedKey("example", path);
}
/** Null when the data pack is missing or a file failed to parse. */
public static Optional<Advancement> find(NamespacedKey key) {
return Optional.ofNullable(Bukkit.getAdvancement(key));
}
/** Awards one criterion. @return true if it was newly awarded */
public static boolean award(Player player, NamespacedKey key, String criterion) {
return find(key).map(advancement -> player.getAdvancementProgress(advancement).awardCriteria(criterion)).orElse(false);
}
/** Awards every remaining criterion. */
public static boolean complete(Player player, NamespacedKey key) {
return find(key).map(advancement -> {
AdvancementProgress progress = player.getAdvancementProgress(advancement);
List.copyOf(progress.getRemainingCriteria()).forEach(progress::awardCriteria);
return progress.isDone();
}).orElse(false);
}
/** For step advancements (prefix_1..prefix_n): awards criteria up to `count`. Never revokes. */
public static void progress(Player player, NamespacedKey key, String prefix, int count) {
find(key).ifPresent(advancement -> {
AdvancementProgress progress = player.getAdvancementProgress(advancement);
for (int i = 1; i <= count; i++) {
String criterion = prefix + i;
if (advancement.getCriteria().contains(criterion)) {
progress.awardCriteria(criterion);
}
}
});
}
/** Removes all progress (tests, season resets). Rewards already given are not taken back. */
public static void reset(Player player, NamespacedKey key) {
find(key).ifPresent(advancement -> {
AdvancementProgress progress = player.getAdvancementProgress(advancement);
List.copyOf(progress.getAwardedCriteria()).forEach(progress::revokeCriteria);
});
}
}
```
### `QuestPlugin.java`
```java
package com.example.quests;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Enemy;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
public final class QuestPlugin extends JavaPlugin implements Listener {
private static final int SLAYER_GOAL = 5;
private final List<String> bootstrapProblems;
private NamespacedKey killsKey;
QuestPlugin(List<String> bootstrapProblems) {
this.bootstrapProblems = List.copyOf(bootstrapProblems);
}
@Override
public void onEnable() {
killsKey = new NamespacedKey(this, "hostile_kills");
bootstrapProblems.forEach(problem -> getLogger().warning("Quest data pack: " + problem));
List<NamespacedKey> missing = Quests.ALL.stream().filter(key -> Quests.find(key).isEmpty()).toList();
if (!missing.isEmpty()) {
getLogger().warning("Advancements not loaded: " + missing + " (check the log for 'Couldn't load' / parse errors)");
}
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Quests.award(event.getPlayer(), Quests.FIRST_STEPS, "done");
}
/** Counter kept in the player's PDC, so it survives restarts with the player data. */
@EventHandler(ignoreCancelled = true)
public void onKill(EntityDeathEvent event) {
Player killer = event.getEntity().getKiller();
if (killer == null || !(event.getEntity() instanceof Enemy)) {
return;
}
PersistentDataContainer data = killer.getPersistentDataContainer();
int kills = Math.min(SLAYER_GOAL, data.getOrDefault(killsKey, PersistentDataType.INTEGER, 0) + 1);
data.set(killsKey, PersistentDataType.INTEGER, kills);
Quests.progress(killer, Quests.SLAYER, "kill_", kills);
}
/** Vanilla announces with the advancement's chat line; replace it for the plugin's tab. */
@EventHandler
public void onDone(PlayerAdvancementDoneEvent event) {
NamespacedKey key = event.getAdvancement().getKey();
if (!key.getNamespace().equals("example") || key.equals(Quests.ROOT)) {
return;
}
if (event.message() != null) { // null when announce_to_chat is false or the gamerule is off
event.message(Component.text(event.getPlayer().getName() + " completed the quest ", NamedTextColor.GRAY)
.append(event.getAdvancement().displayName()));
}
}
}
```
## Recommended Directory Structure
```
src/main/
├── java/com/example/quests/
│ ├── QuestBootstrap.java <- registers the bundled pack
│ ├── Quests.java <- award / progress / reset helpers
│ └── QuestPlugin.java <- join, kills, announcements
└── resources/
├── paper-plugin.yml
└── quests/
├── pack.mcmeta
└── data/example/advancement/quests/
├── root.json
├── first_steps.json
├── slayer.json
└── secret.json
```
## Thread Safety
- `awardCriteria` / `revokeCriteria` change player data and send packets: call them on the player's thread (main thread on Paper; on Folia, the region that owns the player, e.g. via `player.getScheduler()`)
- Reading `Bukkit.getAdvancement` is safe on any tick thread; advancements change only on `/minecraft:reload`
- See [`references/paper-threading.md`](references/paper-threading.md)
### Key Techniques
| Topic | Approach |
|------|------|
| Own tab | A root advancement (no `parent`) with a `background`; `minecraft:tick` grants it at once so the tab shows |
| Portable JSON | Only `minecraft:impossible` and `minecraft:tick` criteria; the plugin awards them |
| Progress bar | N criteria, `requirements` with one list per criterion (all required); award `kill_1..kill_n` |
| Any-of | One list with several criteria (`[["a", "b"]]`): any one completes it |
| Hidden challenge | `"hidden": true` + `"frame": "challenge"`; it and its children stay hidden until it is done |
| Rewards | `rewards.experience` is portable; `loot` changed type in 26.3 (`HolderSet` codec) and `function` needs a function in the pack |
| Announcement | `PlayerAdvancementDoneEvent#message(Component)`; `null` hides it; JSON `announce_to_chat` turns it off |
| Reset | `revokeCriteria` for each awarded criterion; rewards are not taken back |
## Fallback
| Error | Cause | Fix |
|------|------|------|
| `Bukkit.getAdvancement(key)` is null | Pack not enabled, wrong folder (`advancement/`, singular, since 1.21), or a JSON error | Check `DatapackManager` and the log for "Couldn't load advancement"; the folder is `data/<ns>/advancement/` |
| Tab never shows | Root has an `impossible` criterion nobody is given | Use `minecraft:tick` for the root, or award it on join |
| Works on 1.21.11, fails on 26.3 (or the reverse) | Trigger conditions written for one version | Keep conditions out of the JSON and award from Java, or ship per-version folders |
| Progress shows 0/1 instead of 0/5 | All criteria in one requirement list (any-of) | One list per criterion |
| `awardCriteria` returns false | Criterion name misspelled, or already awarded | Compare with `advancement.getCriteria()` |
| `a.equals(b)` or `getChildren().contains(a)` is false for the same advancement | `Advancement` objects are new wrappers each call (observed on 26.3: `root.getRoot().equals(root)` was false) | Compare `getKey()`; copy `getCriteria()` into a `Set` before comparing |
| Toast but no chat line | `announce_to_chat` false, or the game rule `show_advancement_messages` is off | Expected; send your own message if needed |
| Advancements vanish after `/reload` with `getUnsafe().loadAdvancement` | Unsafe API, not part of the data pack | Use the bundled data pack (this template) |
| Hidden advancement and everything below it missing from the tab | `hidden: true` hides the advancement and its children until it is completed | Put only the secret itself (or a secret branch) under a hidden advancement |
Files in this skill
- SKILL.md
- examples.md
- references/paper-api-platform.md
- references/paper-threading.md
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.