Trips¶
A trip is a path being followed by a player, rendered by a navigator. Trips recompute when the
player strays and end on arrival. TripService starts trips programmatically.
Starting a trip¶
This runs the search and starts the trip. Every trip needs a label. It names the trip in
/cobblestone trips and in the player's trip HUD, where it is shown exactly as given. Keep it
short, and make it tell your own trips apart: unlike a /navigate address, Cobblestone cannot
shorten or disambiguate it. The label is also the trip's identity. Starting another trip for the
same player with the same label replaces the first one, which suits a quest objective that moves.
Outcomes¶
navigate returns a CompletableFuture<TripOutcome>:
tripService.navigate(player, objective, NavigatorSettings.defaults(), "Lost Lantern")
.thenAccept(outcome -> {
switch (outcome) {
case TripOutcome.Started started ->
log("trip {} started, about {}s", started.tripId(), started.durationSeconds());
case TripOutcome.Failed failed ->
player.sendMessage("No route found."); // failed.reason()
case TripOutcome.TripLimitReached ignored ->
player.sendMessage("Finish or cancel a trip first.");
case TripOutcome.Error error ->
log.warn("navigation failed", error.throwable());
}
});
FailureReason is one of NO_ROUTE, DESTINATION_UNREACHABLE, LIMIT_EXCEEDED, TIMED_OUT,
CANCELLED.
An overload accepts only a failure callback:
tripService.navigate(player, objective, NavigatorSettings.defaults(), "Lost Lantern",
reason -> player.sendMessage("No route: " + reason));
Warning
The future completes off the main thread. Return to the server or region thread before accessing server state.
Navigator settings¶
NavigatorSettings selects the navigator and overrides its appearance for a single trip. Unset
values fall back to the server configuration.
import org.bukkit.Color;
import org.bukkit.Particle;
import org.cobblestonemc.paper.plugin.api.TrailNavigatorSettings;
NavigatorSettings settings = TrailNavigatorSettings.builder()
.particles(List.of(Particle.DUST))
.colors(List.of(Color.fromRGB(0xFFD54F), Color.fromRGB(0x4FC3F7)))
.highlightParticles(List.of(Particle.END_ROD))
.showLabel(false) // no floating name over the trail for this trip
.build();
tripService.navigate(player, objective, settings, "Lost Lantern");
import org.spongepowered.api.effect.particle.ParticleTypes;
import org.spongepowered.api.util.Color;
import org.cobblestonemc.sponge.plugin.api.TrailNavigatorSettings;
NavigatorSettings settings = TrailNavigatorSettings.builder()
.particles(List.of(ParticleTypes.DUST.get()))
.colors(List.of(Color.ofRgb(0xFFD54F), Color.ofRgb(0x4FC3F7)))
.highlightParticles(List.of(ParticleTypes.END_ROD.get()))
.showLabel(false) // no floating name over the trail for this trip
.build();
tripService.navigate(player, objective, settings, "Lost Lantern");
showLabel decides whether the trip's name floats over its trail while the player stands still
(where hitting Cancel above it cancels the trip). Unset, it follows the server's
trips.holograms config.
To use another navigator, build settings for its id:
NavigatorSettings.defaults() selects the server's default navigator with its configured
appearance.
Starting a trip from a path¶
To render a path from a search you ran (see Searching):
SearchHandle<Location, MinecraftStepPayload> handle =
CobblestoneCoreApi.navigationService().navigatePlayer(player, destination);
handle.future().thenAccept(result -> {
if (result instanceof NavigationResult.Success<Location, MinecraftStepPayload> success) {
CobblestonePaperApi.tripService()
.startTrip(player, success.path(), NavigatorSettings.defaults(), "Lost Lantern");
}
});
SearchHandle<ServerLocation, MinecraftStepPayload> handle =
CobblestoneCoreApi.navigationService().navigatePlayer(player, destination);
handle.future().thenAccept(result -> {
if (result instanceof NavigationResult.Success<ServerLocation, MinecraftStepPayload> success) {
CobblestoneSpongeApi.tripService()
.startTrip(player, success.path(), NavigatorSettings.defaults(), "Lost Lantern");
}
});
Trips started this way are not live. Use navigate for trips that re-search.
Lifecycle¶
Programmatic trips appear in /cobblestone trips and the trip HUD, count toward
trips.max_active_per_player, and can be cancelled by the player. Do not restart a trip the player
has cancelled.
Trips end on arrival, cancellation, or disconnect.