diff --git a/src/main/java/de/craftinc/borderprotection/borders/Border.java b/src/main/java/de/craftinc/borderprotection/borders/Border.java index 1ab9ea8..151342c 100644 --- a/src/main/java/de/craftinc/borderprotection/borders/Border.java +++ b/src/main/java/de/craftinc/borderprotection/borders/Border.java @@ -79,6 +79,8 @@ public abstract class Border */ public abstract Location[] getSurroundingRect(); + public abstract Location getCenter(); + public Boolean isActive() { return isActive; diff --git a/src/main/java/de/craftinc/borderprotection/borders/CircBorder.java b/src/main/java/de/craftinc/borderprotection/borders/CircBorder.java index ee4b699..87022e3 100644 --- a/src/main/java/de/craftinc/borderprotection/borders/CircBorder.java +++ b/src/main/java/de/craftinc/borderprotection/borders/CircBorder.java @@ -129,4 +129,10 @@ public class CircBorder extends Border implements ConfigurationSerializable return new Location[]{ l1, l2 }; } + + @Override + public Location getCenter() + { + return center; + } } \ No newline at end of file diff --git a/src/main/java/de/craftinc/borderprotection/borders/RectBorder.java b/src/main/java/de/craftinc/borderprotection/borders/RectBorder.java index 2091f71..a17fa28 100644 --- a/src/main/java/de/craftinc/borderprotection/borders/RectBorder.java +++ b/src/main/java/de/craftinc/borderprotection/borders/RectBorder.java @@ -21,6 +21,7 @@ import de.craftinc.borderprotection.Plugin; import de.craftinc.borderprotection.util.PlayerMovementUtil; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.configuration.serialization.ConfigurationSerializable; import java.util.HashMap; @@ -186,4 +187,15 @@ public class RectBorder extends Border implements ConfigurationSerializable { return new Location[]{ rectPoint1, rectPoint2 }; } + + @Override + public Location getCenter() + { + World w = rectPoint1.getWorld(); + double x = Math.abs(rectPoint1.getX() - rectPoint2.getX()) / 2.0 + Math.min(rectPoint1.getX(), rectPoint2.getX()); + double y = rectPoint1.getY(); + double z = Math.abs(rectPoint1.getZ() - rectPoint2.getZ()) / 2.0 + Math.min(rectPoint1.getZ(), rectPoint2.getZ()); + + return new Location(w, x, y, z); + } }