Fix WorldEditPlugin assuming that worlds are an instance of BukkitWorld.

Fixes WORLDEDIT-3168.
This commit is contained in:
sk89q 2014-07-25 17:29:36 -07:00
parent 5dd7b83940
commit e93c9c9736
3 changed files with 24 additions and 3 deletions

View File

@ -35,6 +35,27 @@ final class BukkitAdapter {
private BukkitAdapter() {
}
/**
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
*
* <p>If a matching world cannot be found, a {@link RuntimeException}
* will be thrown.</p>
*
* @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.
*

View File

@ -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;

View File

@ -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);