Add default method and fix tests

This commit is contained in:
LeoDog896 2021-03-04 11:57:58 -05:00
parent e3c47e60ba
commit b20de605e1
2 changed files with 15 additions and 2 deletions

View File

@ -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.

View File

@ -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);