Skip to content

Commit

Permalink
Adds Locatable
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Aug 11, 2024
1 parent 993531d commit 0f96650
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/main/java/us/mytheria/bloblib/entities/Locatable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package us.mytheria.bloblib.entities;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;

public interface Locatable extends Spatial {
@Nullable
World getWorld();

@Override
default Location toLocation() {
Vector vector = toVector();
return new Location(getWorld(), vector.getX(), vector.getY(), vector.getZ(), getYaw(), getPitch());
}

@Override
default boolean isLocatable() {
return getWorld() != null;
}
}
18 changes: 18 additions & 0 deletions src/main/java/us/mytheria/bloblib/entities/Positionable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package us.mytheria.bloblib.entities;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface Positionable {
double getX();
Expand All @@ -14,4 +17,19 @@ public interface Positionable {
default Vector toVector() {
return new Vector(getX(), getY(), getZ());
}

@NotNull
default Location toLocation() {
return toLocation(null);
}

@NotNull
default Location toLocation(@Nullable World world) {
Vector vector = toVector();
return new Location(world, vector.getX(), vector.getY(), vector.getZ());
}

default boolean isLocatable() {
return false;
}
}
6 changes: 1 addition & 5 deletions src/main/java/us/mytheria/bloblib/entities/Spatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ public interface Spatial extends Positionable {

float getPitch();

@NotNull
default Location toLocation() {
return toLocation(null);
}

@Override
@NotNull
default Location toLocation(@Nullable World world) {
Vector vector = toVector();
Expand Down

0 comments on commit 0f96650

Please sign in to comment.