diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index c9de48b73..306f19b7b 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -35,6 +35,27 @@ final class BukkitAdapter { private BukkitAdapter() { } + /** + * Convert any WorldEdit world into an equivalent wrapped Bukkit world. + * + *
If a matching world cannot be found, a {@link RuntimeException} + * will be thrown.
+ * + * @param world the world + * @return a wrapped Bukkit world + */ + public static BukkitWorld asBukkitWorld(World world) { + if (world instanceof BukkitWorld) { + return (BukkitWorld) world; + } else { + BukkitWorld bukkitWorld = WorldEditPlugin.getInstance().getInternalPlatform().matchWorld(world); + if (bukkitWorld == null) { + throw new RuntimeException("World '" + world.getName() + "' has no matching version in Bukkit"); + } + return bukkitWorld; + } + } + /** * Create a WorldEdit world from a Bukkit world. * diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index adb25c7de..04a1e7456 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -110,9 +110,9 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP @Nullable @Override - public com.sk89q.worldedit.world.World matchWorld(com.sk89q.worldedit.world.World world) { + public BukkitWorld matchWorld(com.sk89q.worldedit.world.World world) { if (world instanceof BukkitWorld) { - return world; + return (BukkitWorld) world; } else { World bukkitWorld = server.getWorld(world.getName()); return bukkitWorld != null ? new BukkitWorld(bukkitWorld) : null; diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 9b0ff432d..0a804208d 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -412,7 +412,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { try { Region region = selector.getRegion(); - World world = ((BukkitWorld) session.getSelectionWorld()).getWorld(); + World world = BukkitAdapter.asBukkitWorld(session.getSelectionWorld()).getWorld(); if (region instanceof CuboidRegion) { return new CuboidSelection(world, selector, (CuboidRegion) region);