mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-27 06:03:01 +02:00
Add default method and fix tests
This commit is contained in:
parent
e3c47e60ba
commit
b20de605e1
@ -28,7 +28,20 @@ public abstract class RelativeLocation<T> {
|
||||
* @param entity the entity to get the relative position from
|
||||
* @return the location
|
||||
*/
|
||||
public abstract T from(@Nullable Position entity);
|
||||
public T from(@Nullable Entity entity) {
|
||||
|
||||
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
|
||||
|
||||
return from(entityPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location based on the relative fields and {@code position}.
|
||||
*
|
||||
* @param position the relative position
|
||||
* @return the location
|
||||
*/
|
||||
public abstract T from(@Nullable Position position);
|
||||
|
||||
/**
|
||||
* Gets if the 'x' field is relative.
|
||||
|
@ -38,7 +38,7 @@ public class TeleportCommand extends Command {
|
||||
final Player player = sender.asPlayer();
|
||||
|
||||
final RelativeVec relativeVec = args.getRelativeVector("pos");
|
||||
final Position position = relativeVec.from(player.getPosition()).toPosition();
|
||||
final Position position = relativeVec.from(player).toPosition();
|
||||
|
||||
player.teleport(position);
|
||||
player.sendMessage("You have been teleported to " + position);
|
||||
|
Loading…
Reference in New Issue
Block a user