diff --git a/src/main/java/net/minestom/server/utils/location/RelativeLocation.java b/src/main/java/net/minestom/server/utils/location/RelativeLocation.java index e800bc0bb..fac09b12f 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeLocation.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeLocation.java @@ -28,7 +28,20 @@ public abstract class RelativeLocation { * @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. diff --git a/src/test/java/demo/commands/TeleportCommand.java b/src/test/java/demo/commands/TeleportCommand.java index 2956747a9..562efa677 100644 --- a/src/test/java/demo/commands/TeleportCommand.java +++ b/src/test/java/demo/commands/TeleportCommand.java @@ -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);