From ea3057878141548b44c6dd269d33b019b7bc1c99 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 21 Dec 2018 17:05:30 +1000 Subject: [PATCH] Added a way to get the spawn position of a world --- .../main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java | 5 +++++ .../src/main/java/com/sk89q/worldedit/world/NullWorld.java | 5 +++++ .../src/main/java/com/sk89q/worldedit/world/World.java | 7 +++++++ .../main/java/com/sk89q/worldedit/forge/ForgeAdapter.java | 4 ++-- .../main/java/com/sk89q/worldedit/forge/ForgeWorld.java | 5 +++++ .../main/java/com/sk89q/worldedit/sponge/SpongeWorld.java | 5 +++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 8bffc3a2e..6b5a2ef77 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -404,6 +404,11 @@ public class BukkitWorld extends AbstractWorld { } } + @Override + public BlockVector3 getSpawnPosition() { + return BukkitAdapter.asBlockVector(getWorld().getSpawnLocation()); + } + @Override public void simulateBlockMine(BlockVector3 pt) { getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index eec1d47a9..6ac2ba3a0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -125,6 +125,11 @@ public class NullWorld extends AbstractWorld { public void setWeather(WeatherType weatherType, long duration) { } + @Override + public BlockVector3 getSpawnPosition() { + return BlockVector3.ZERO; + } + @Override public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index d47723a42..b335de3cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -246,6 +246,13 @@ public interface World extends Extent { */ void setWeather(WeatherType weatherType, long duration); + /** + * Gets the spawn position of this world. + * + * @return The spawn position + */ + BlockVector3 getSpawnPosition(); + @Override boolean equals(Object other); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java index 671e2e0f4..e0f319cee 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java @@ -54,8 +54,8 @@ final class ForgeAdapter { return Vector3.at(vector.x, vector.y, vector.z); } - public static Vector3 adapt(BlockPos pos) { - return Vector3.at(pos.getX(), pos.getY(), pos.getZ()); + public static BlockVector3 adapt(BlockPos pos) { + return BlockVector3.at(pos.getX(), pos.getY(), pos.getZ()); } public static Vec3d toVec3(BlockVector3 vector) { diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index d3d84d48a..2a4fe60c0 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -467,6 +467,11 @@ public class ForgeWorld extends AbstractWorld { } } + @Override + public BlockVector3 getSpawnPosition() { + return ForgeAdapter.adapt(getWorld().getSpawnPoint()); + } + @Override public BlockState getBlock(BlockVector3 position) { World world = getWorld(); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java index e3401190e..a6631a252 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java @@ -320,6 +320,11 @@ public abstract class SpongeWorld extends AbstractWorld { getWorld().setWeather(Sponge.getRegistry().getType(Weather.class, weatherType.getId()).get(), duration); } + @Override + public BlockVector3 getSpawnPosition() { + return SpongeAdapter.asBlockVector(getWorld().getSpawnLocation()); + } + /** * Thrown when the reference to the world is lost. */