whimxiqal / journey

A server-side path-finding Minecraft plugin
MIT License
14 stars 3 forks source link

[API] Create createItinerary Function #41

Closed TheDeafCreeper closed 1 year ago

TheDeafCreeper commented 1 year ago

The goal of this pull request is to allow developers to create an itinerary for a player via the API. (Resolves #40 )

Currently I:

  1. Add toJourneyPlayer to the JourneyBukkitAPI and BukkitUtil.
  2. Add createItineraryTo to JourneyPlayer.
TheDeafCreeper commented 1 year ago

I've never made an API before so I have no idea how to actually set this up to test it.

So, TODO:

TheDeafCreeper commented 1 year ago

Alright tested API and it works.

TheDeafCreeper commented 1 year ago

I think having methods that act on a player would be intuitive to have on that player instead of having to do something like createPath(player, origin, dest).

Being able to do more advanced stuff by making a path manually would also be nice, but 90% of the time devs are probably going to just want to tell a player how to walk from point a to point b.

whimxiqal commented 1 year ago

Another big integration I have planned is for Citizens, so I want for devs to be able to execute a search for an NPC given a set list of modes that the NPC should be expected to use, and then the NPC can act as a guide instead of the path search for the player

whimxiqal commented 1 year ago

And about your point about the JourneyPlayer, there's no need to get an entire JourneyPlayer when all you need to identify a a player is their UUID. So I'd be imagining something like

Future<SearchResult> calculateDestinationPath(CalculationSettings settings, Cell origin, Cell destination);

Future<SearchResult> calculateDomainPath(CalculationSettings settings, Cell origin, int domain);

CalculationSettings playerSettings(UUID playerUuid, boolean display);

And you would use it like:

CalculationSettings playerSettings = journeyApi.playerSettings(myPlayer, true);
journeyApi.calculateDestinationPath(playerSettings, origin, destination);  // ignore future if you don't want to use it

or, if you just want to calculate the path for your own dev purposes:

CalculationSettings playerSettings = journeyApi.playerSettings(myPlayer, false);
Future<SearchResult> searchFuture = journeyApi.calculateDestinationPath(playerSettings, origin, destination);  // using future

// in a repeated task
if (searchFuture.isDone()) {
  // Use the resulting path for whatever purposes you have, like using a custom displaying mechanism
  myDisplayMethod(searchFuture.get().getPath());

  // Or maybe you just wanted to know how far away it was
  audience().sendMessage("The path is " + searchFuture.get().getLength() + " blocks away");
}

and finally, if you wanted to have an NPC follow a path, or just do something different uninvolving of a player:

CalculationSettings npcSettings = new NpcCalculationSettings(/* args */);  // your own custom settings
Future<SearchResult> searchFuture = journeyApi.calculateDestinationPath(npcSettings, origin, destination);  // using future

// in a repeated task
if (searchFuture.isDone()) {
  myGuideMethod(searchFuture.get().getPath());
}

What do you think?

whimxiqal commented 1 year ago

Closed in favor of API changes added in v1.1