mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-16 07:35:35 +01:00
Renamed RelativeLocation#from
This commit is contained in:
parent
beaf25ff47
commit
f1448c8c89
@ -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<BlockPosition> {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -27,7 +27,7 @@ public abstract class RelativeLocation<T> {
|
||||
* @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.
|
||||
|
@ -17,11 +17,11 @@ public class RelativeVec extends RelativeLocation<Vector> {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user