Destinations¶
A destination is a named location that /navigate can route to. Destinations are supplied by a
DestinationService, which is queried per player, per search.
Structure¶
flowchart LR
A[DestinationService] -->|provide player| B[DestinationTree]
B --> C[entries, by key]
C -->|a destination| D[DestinationLeaf]
C -->|a subtree| B
D --> E[MinecraftDestination]
E --> F["regions() — where it actually is"]
A tree is a set of entries, each named by a key. An entry is a destination, a subtree of further entries, or both — a town is somewhere to go, and also holds its home and plots. A tree itself is never a destination; only its entries are.
Minimal example¶
A single destination at a fixed location:
import org.cobblestonemc.paper.plugin.api.CobblestonePaperApi;
import org.cobblestonemc.paper.plugin.api.Destination;
import org.cobblestonemc.paper.plugin.api.DestinationService;
public final class ShopsPlugin extends JavaPlugin {
@Override
public void onEnable() {
CobblestonePaperApi.registrar().registerDestinations(this, player ->
Destination.tree()
.destination("market", () -> Destination.at(marketLocation(), "Market"))
.build());
}
}
import net.kyori.adventure.text.Component;
import org.cobblestonemc.sponge.plugin.api.CobblestoneSpongeApi;
import org.cobblestonemc.sponge.plugin.api.Destination;
import org.cobblestonemc.sponge.plugin.api.DestinationService;
@Listener
public void onStartedEngine(StartedEngineEvent<Server> event) {
CobblestoneSpongeApi.registrar().registerDestinations(container, player ->
Destination.tree()
.destination("market", () -> Destination.at(marketLocation(), Component.text("Market")))
.build());
}
For a plugin named Shops, the address is shops market. Players may use /nav market, or
/nav shops market if the name is ambiguous.
Note
The tree is already registered under the owner plugin's name. Do not add a top-level entry for it.
Trees¶
Destination.tree() begins a tree. Add entries to it, each keyed by a string: destination(key, …)
for somewhere to go, subtree(key, …) for a tree of further entries beneath it.
Tip
Hold a tree you are still adding to in a var — var tree = Destination.tree(); — rather than
spelling out its type, DestinationTree.Builder<MinecraftDestination<World, Vector3i>>.
Destination.tree()
.subtree("warp", () -> warps(player))
.subtree("dungeon", Destination.tree()
.strict() // (1)!
.destination("crypt", () -> Destination.at(crypt, "The Crypt"))
.destination("mines", () -> Destination.at(mines, "Deep Mines")))
.build();
- A strict tree's key cannot be omitted:
/nav dungeon cryptis valid;/nav cryptis not.
Destination.tree()
.subtree("warp", () -> warps(player))
.subtree("dungeon", Destination.tree()
.strict() // (1)!
.destination("crypt", () -> Destination.at(crypt, Component.text("The Crypt")))
.destination("mines", () -> Destination.at(mines, Component.text("Deep Mines"))))
.build();
- A strict tree's key cannot be omitted:
/nav dungeon cryptis valid;/nav cryptis not.
Rules:
- Keys are single tokens. Upper case is permitted; special characters are not. Spaces are permitted but discouraged, since keys appear in commands and permission nodes.
- Each key is added once. Adding a key again, or a key that is already an alias, throws.
- Subtrees from a supplier are built each time they are traversed, and never if they are not. A subtree given as a builder is built once, when it is added.
- Return
nullfromprovidewhen there are no destinations for the player. Empty trees are omitted. - Mark large trees
strict(). Strict trees are skipped when computing suggestions. alias(other, key)lets a destination answer to another name players may guess. An alias is never suggested, and the destination keeps its own key in messages and permissions.
Both at once¶
An entry may be a destination and hold a subtree. Build it with Destination.entry() and add it
with entry(key, …):
for (Town town : towns()) {
tree.entry(town.name(), Destination.entry()
.destination(() -> Destination.regions(() -> claims(town), town.name()))
.subtree(() -> townDetail(town))); // its home, outposts, plots
}
/nav town riverwood goes to the whole town; /nav town riverwood home goes to its home. An entry
must have a destination, a subtree, or both; build() refuses one with neither.
Lazy subtrees¶
private DestinationTree<MinecraftDestination<World, Vector3i>> warps(Player player) {
var tree = Destination.tree().strict();
for (Warp warp : store.visibleTo(player)) {
// The lambda body runs only if this destination is actually picked.
tree.destination(warp.name(), () -> Destination.at(warp.location(), warp.name()));
}
return tree.build();
}
private DestinationTree<MinecraftDestination<ServerWorld, Vector3i>> warps(ServerPlayer player) {
var tree = Destination.tree().strict();
for (Warp warp : store.visibleTo(player)) {
// The lambda body runs only if this destination is actually picked.
tree.destination(warp.name(), () -> Destination.at(warp.location(), Component.text(warp.name())));
}
return tree.build();
}
Destination types¶
Destination provides factories for common cases:
// A single block. Its coordinates are shown on hover.
Destination.at(location, "Market");
// Anywhere in one region.
Destination.region(BoxWorldRegion.of(corner1, corner2), "The Arena");
Destination.region(BoxWorldRegion.around(center, 8), "Near the well");
Destination.region(WholeWorldRegion.of(world), "The Nether");
// Several regions — the search heads for whichever is cheapest to reach, and
// the supplier is re-evaluated every search, so a moving target stays current.
Destination.regions(() -> town.claims().stream().map(this::toRegion).toList(), "Riverwood");
// A single block. Its coordinates are shown on hover.
Destination.at(location, Component.text("Market"));
// Anywhere in one region.
Destination.region(BoxWorldRegion.of(corner1, corner2), Component.text("The Arena"));
Destination.region(BoxWorldRegion.around(center, 8), Component.text("Near the well"));
Destination.region(WholeWorldRegion.of(world), Component.text("The Nether"));
// Several regions — the search heads for whichever is cheapest to reach, and
// the supplier is re-evaluated every search, so a moving target stays current.
Destination.regions(
() -> town.claims().stream().map(this::toRegion).toList(), Component.text("Riverwood"));
A destination with no regions is valid and unreachable. Use this when the target is temporarily unavailable, such as when its world is unloaded.
Moving targets¶
Destination.builder takes the same regions as Destination.regions, plus optional settings:
Destination.builder(
npc.getName(),
// Re-read on every search, so a live trip follows the NPC.
() -> npc.isSpawned()
? List.of(SingleCellWorldRegion.of(npc.getEntity().getLocation()))
: List.of())
.mobile() // trips to it default to -live
.labeled() // its nameplate already names it
.existence(() -> CitizensAPI.getNPCRegistry().getById(npc.getId()) != null)
.detail(Component.text("Wanders the market"))
.build();
mobile()sets the default for live trips. Players may override it with-liveor-no-live.labeled()says the destination already shows its name in the world, as an NPC's nameplate does.detail(...)andexistence(...)are described under Hover detail and Existence.
You may also implement MinecraftDestination yourself; isMobile(), hasLabel(), detail()
and exists() are its defaults to override.
Leaves¶
destination(key, () -> destination) is the common case: a destination with no options or
permissions that is always valid. For anything more, pass a DestinationLeaf. A leaf describes
itself (its permissions and options) and builds its destination only once a player picks it:
- Tab completion reads every leaf's description on each keystroke, possibly off the server thread, so the description must be cheap and must not read the world.
build(OptionValues)runs once, when the command runs, on the thread that owns the player (their region, on Folia). It may read the world around them. It returns aValidity: the destination, or the reason there is nothing to navigate to right now.
// Always valid, nothing typed after the key; the same as destination(key, () -> ...).
DestinationLeaf.of(() -> Destination.at(market, "Market"));
// May be invalid.
DestinationLeaf.ofValidity(
() -> town.isOpen()
? Validity.valid(Destination.at(town.spawn(), town.name()))
: Validity.invalid(Component.text("The town is closed.", NamedTextColor.RED)));
// Requires a permission.
DestinationLeaf.of(() -> Destination.at(vault, "Vault")).withPermissions("towns.vault");
Options¶
A leaf may take values typed after its key, such as the coordinates in
/nav coordinates block 100 64 -200. Declare them in the order they are typed, and build the
destination from what was typed:
DestinationOption<Outpost> outpost =
DestinationOption.required(
"outpost",
partial -> town.outposts().stream().map(Outpost::name).toList(),
token -> Optional.ofNullable(town.outpost(token)));
tree.destination(
"outpost",
DestinationLeaf.withOptions(
List.of(outpost),
values -> {
Outpost chosen = values.get(outpost);
return Validity.valid(Destination.at(chosen.spawn(), chosen.name()));
}));
- Each option reads one word.
DestinationOption.integer(name, hint)reads a whole number and suggestshint;required(…)andoptional(…)take any suggestion and parsing logic. - Required options come first. Optional ones may be left off from the end.
- Options are never part of the address, so they never affect the destination's permission node and are never promoted past its name.
- If the words after the name do not fit, the player is shown the usage, such as
/navigate outpost <outpost>.
Validity¶
When build returns Validity.invalid(reason), the player is shown reason as is, instead of a
search starting. The leaf is still offered in tab completion, so the player learns why rather than
finding nothing there. Cobblestone's own destinations use it for surface when the player is
already in the open, death when no death is on record, respawn when the player has none, and
target when they are not looking at a block in range.
Hover detail¶
Set detail(...) on the builder to add a line to the hover text of Searching for a route... and of the error
that follows if no route is found. The address is always shown; the detail goes beneath it.
Cobblestone's own destinations use it for the coordinates of fixed places, such as death, so a
player can find the place by hand. Destination.at adds a block's coordinates for you.
Existence¶
Set existence(...) on the builder for a target that can stop existing partway through a trip, such as an
animal that dies. A trip polls it about once a second and ends quietly once it returns false.
Being out of reach, for example unloaded, is not the same as not existing. It is called on the
travelling player's thread, so keep it cheap. Cobblestone ends trips to pets and mounts that die,
and to players who log off.
In the navigation menu¶
Typing /navigate on its own opens a chest menu of the same tree. By default each entry shows
as its key on a plain item. Give it a label, a description and an icon to make it look like yours:
An Icon is one of:
Icon.item("minecraft:oak_sign")— an item, by key.Icon.head(texture)— a player head wearing a skin texture: the base64texturesvalue that head databases such as minecraft-heads.com publish.Icon.playerHead(uuid)— a player's own head.PaperIcon.of(…)/SpongeIcon.of(…)— a platform item stack, item type, or block, for full control (a custom model, dyed leather, a glint).
Icon.parse(text, fallback) reads head:<texture> or an item key, the form admins write in a
config file, and falls back when the text is blank. Read icons from your plugin's own config so
admins can theme them.
Your plugin's own entry at the top of the menu is shown with DestinationService.display(player):
public final class ShopsDestinations implements DestinationService {
@Override
public DestinationTree<MinecraftDestination<World, Vector3i>> provide(Player player) { … }
@Override
public Display display(Player player) {
return Display.of(Icon.item("minecraft:emerald"));
}
}
A destination with required options, such as coordinates, asks for them before navigating, using the options' names and suggestions. An option with a handful of suggestions is a choice among them; one with a single suggestion is text that starts as that suggestion.
Permissions¶
- Destination node:
cobblestone.navigate.<address>. Generated automatically, default allow, and managed by server admins. - A leaf's
permissions(): Additional required permissions, all of which the player must hold. Use for access control only. Cobblestone's own destinations declare none.
Addressing¶
Players may omit leading words of an address if the remainder is unambiguous.
- The final key is always required.
strict()trees are always required.- Keys that collide across plugins are resolved by the player using the full address.
- Matching is case-insensitive;
questandQuestcollide.