From f1448c8c89ead89abb748807f383c950523b4875 Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 14 Feb 2021 00:31:49 +0100 Subject: [PATCH] Renamed RelativeLocation#from --- .../server/utils/location/RelativeBlockPosition.java | 5 +++-- .../net/minestom/server/utils/location/RelativeLocation.java | 2 +- .../java/net/minestom/server/utils/location/RelativeVec.java | 4 ++-- src/test/java/demo/commands/TeleportCommand.java | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java b/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java index 4af216dbd..0d1eec53f 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java @@ -3,6 +3,7 @@ package net.minestom.server.utils.location; import net.minestom.server.entity.Entity; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Position; +import org.jetbrains.annotations.Nullable; /** * Represents a relative {@link BlockPosition}. @@ -16,11 +17,11 @@ public class RelativeBlockPosition extends RelativeLocation { } @Override - public BlockPosition fromRelativePosition(Entity entity) { + public BlockPosition from(@Nullable Entity entity) { if (!relativeX && !relativeY && !relativeZ) { return location.clone(); } - final Position entityPosition = entity.getPosition(); + final Position entityPosition = entity != null ? entity.getPosition() : new Position(); final int x = location.getX() + (relativeX ? (int) entityPosition.getX() : 0); final int y = location.getY() + (relativeY ? (int) entityPosition.getY() : 0); 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 af5959f13..7a2cb3ec4 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeLocation.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeLocation.java @@ -27,7 +27,7 @@ public abstract class RelativeLocation { * @param entity the entity to get the relative position from * @return the location */ - public abstract T fromRelativePosition(@Nullable Entity entity); + public abstract T from(@Nullable Entity entity); /** * Gets if the 'x' field is relative. diff --git a/src/main/java/net/minestom/server/utils/location/RelativeVec.java b/src/main/java/net/minestom/server/utils/location/RelativeVec.java index ea0c76d22..606e9d62d 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeVec.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeVec.java @@ -17,11 +17,11 @@ public class RelativeVec extends RelativeLocation { } @Override - public Vector fromRelativePosition(@Nullable Entity entity) { + public Vector from(@Nullable Entity entity) { if (!relativeX && !relativeY && !relativeZ) { return location.clone(); } - final Position entityPosition = entity.getPosition(); + final Position entityPosition = entity != null ? entity.getPosition() : new Position(); final double x = location.getX() + (relativeX ? entityPosition.getX() : 0); final double y = location.getY() + (relativeY ? entityPosition.getY() : 0); diff --git a/src/test/java/demo/commands/TeleportCommand.java b/src/test/java/demo/commands/TeleportCommand.java index 486032ce5..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.fromRelativePosition(player).toPosition(); + final Position position = relativeVec.from(player).toPosition(); player.teleport(position); player.sendMessage("You have been teleported to " + position);