mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 02:25:41 +01:00
Implement ExactDestination#fromLocation
This commit is contained in:
parent
d3f6b11fe5
commit
cee6a4879a
@ -36,6 +36,16 @@ public class ExactDestination implements Destination<ExactDestination, ExactDest
|
||||
return "e";
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new {@link ExactDestinationInstance} from a {@link Location}.
|
||||
*
|
||||
* @param location The target location
|
||||
* @return A new {@link ExactDestinationInstance}
|
||||
*/
|
||||
public @NotNull ExactDestinationInstance fromLocation(@NotNull Location location) {
|
||||
return new ExactDestinationInstance(this, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -31,6 +31,7 @@ public class ExactDestinationInstance extends DestinationInstance<ExactDestinati
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Option<Location> getLocation(@NotNull Entity teleportee) {
|
||||
// todo: maybe check if the world is null?
|
||||
return Option.of(location);
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,17 @@ class DestinationTest : TestWithMockBukkit() {
|
||||
assertEquals("e:world:1.2,2.0,3.0:10.5:9.5", destination.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Exact destination instance from location`() {
|
||||
val exactDestination = serviceLocator.getActiveService(ExactDestination::class.java).takeIf { it != null } ?: run {
|
||||
throw IllegalStateException("ExactDestination is not available as a service") }
|
||||
|
||||
val location = Location(world.bukkitWorld.orNull, 1.2, 2.0, 3.0, 9.5F, 10.5F)
|
||||
val destination = exactDestination.fromLocation(location)
|
||||
assertEquals(location, destination.getLocation(player).orNull)
|
||||
assertEquals("e:world:1.2,2.0,3.0:10.5:9.5", destination.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Player destination instance`() {
|
||||
assertTrue(destinationsProvider.getDestinationById("pl") is PlayerDestination)
|
||||
|
Loading…
Reference in New Issue
Block a user