Converted API over to use new World.

This breaks backwards compatibility for all getWorld() methods, but
shim methods were added for binary compatibility with method calls that
use LocalWorld.
This commit is contained in:
sk89q
2014-04-05 02:59:38 -07:00
parent 63a2ca824d
commit 24f8fbc92a
49 changed files with 827 additions and 232 deletions

View File

@@ -19,12 +19,11 @@
package com.sk89q.worldedit.extension.input;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.registry.MaskRegistry;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@@ -38,7 +37,7 @@ public class ParserContext {
private @Nullable Extent extent;
private @Nullable LocalSession session;
private @Nullable LocalWorld world;
private @Nullable World world;
private @Nullable Actor actor;
private boolean restricted = true;
private boolean preferringWildcard;
@@ -80,11 +79,11 @@ public class ParserContext {
}
/**
* Get the {@link LocalWorld} set on this context.
* Get the {@link World} set on this context.
*
* @return a world
*/
public @Nullable LocalWorld getWorld() {
public @Nullable World getWorld() {
return world;
}
@@ -93,7 +92,7 @@ public class ParserContext {
*
* @param world a world, or null if none is available
*/
public void setWorld(@Nullable LocalWorld world) {
public void setWorld(@Nullable World world) {
this.world = world;
}
@@ -144,13 +143,13 @@ public class ParserContext {
}
/**
* Get the {@link LocalWorld} set on this context.
* Get the {@link World} set on this context.
*
* @return a world
* @throws InputParseException thrown if no {@link LocalWorld} is set
* @throws InputParseException thrown if no {@link World} is set
*/
public LocalWorld requireWorld() throws InputParseException {
LocalWorld world = getWorld();
public World requireWorld() throws InputParseException {
World world = getWorld();
if (world == null) {
throw new InputParseException("No world is known");
}
@@ -161,7 +160,7 @@ public class ParserContext {
* Get the {@link Actor} set on this context.
*
* @return an actor
* @throws InputParseException thrown if no {@link LocalPlayer} is set
* @throws InputParseException thrown if no {@link Actor} is set
*/
public Actor requireActor() throws InputParseException {
Actor actor = getActor();

View File

@@ -22,7 +22,7 @@ package com.sk89q.worldedit.extension.platform;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.world.World;
import java.util.Collections;
import java.util.List;
@@ -38,7 +38,7 @@ public abstract class AbstractPlatform implements Platform {
}
@Override
public List<LocalWorld> getWorlds() {
public List<? extends World> getWorlds() {
return Collections.emptyList();
}

View File

@@ -27,6 +27,7 @@ import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.world.World;
import java.io.File;
@@ -94,7 +95,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
@Override
public void findFreePosition(WorldVector searchPos) {
LocalWorld world = searchPos.getWorld();
World world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int origY = y;
@@ -126,7 +127,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
@Override
public void setOnGround(WorldVector searchPos) {
LocalWorld world = searchPos.getWorld();
World world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int z = searchPos.getBlockZ();
@@ -155,7 +156,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ();
final LocalWorld world = pos.getWorld();
final World world = pos.getWorld();
byte free = 0;
byte spots = 0;
@@ -196,7 +197,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY() - 1);
final int z = pos.getBlockZ();
final LocalWorld world = pos.getWorld();
final World world = pos.getWorld();
byte free = 0;
@@ -247,7 +248,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2);
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
World world = getPosition().getWorld();
// No free space above
if (world.getBlockType(new Vector(x, y, z)) != 0) {
@@ -281,7 +282,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
int y = Math.max(0, pos.getBlockY() + 1);
final int z = pos.getBlockZ();
final int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance);
final LocalWorld world = getPosition().getWorld();
final World world = getPosition().getWorld();
while (y <= world.getMaxY() + 2) {
if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
@@ -383,7 +384,7 @@ public abstract class AbstractPlayerActor implements Actor, Player {
public boolean passThroughForwardWall(int range) {
int searchDist = 0;
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
LocalWorld world = getPosition().getWorld();
World world = getPosition().getWorld();
BlockWorldVector block;
boolean firstBlock = true;
int freeToFind = 2;

View File

@@ -19,9 +19,9 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEditPermissionException;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.world.World;
import java.io.File;
@@ -42,7 +42,7 @@ public interface Actor {
*
* @return the world
*/
LocalWorld getWorld();
World getWorld();
/**
* Print a message.

View File

@@ -24,7 +24,7 @@ import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.world.World;
import java.util.List;
@@ -75,7 +75,7 @@ public interface Platform {
*/
int schedule(long delay, long period, Runnable task);
List<LocalWorld> getWorlds();
List<? extends World> getWorlds();
@Deprecated
void onCommandRegistration(List<Command> commands);

View File

@@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.platform;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.World;
import java.util.List;
@@ -70,7 +71,7 @@ class ServerInterfaceAdapter extends ServerInterface {
}
@Override
public List<LocalWorld> getWorlds() {
public List<? extends World> getWorlds() {
return platform.getWorlds();
}

View File

@@ -28,6 +28,7 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.World;
/**
* Parses block input strings.
@@ -79,7 +80,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
data = blockInHand.getData();
} else if ("pos1".equalsIgnoreCase(testID)) {
// Get the block type from the "primary position"
final LocalWorld world = context.requireWorld();
final World world = context.requireWorld();
final BlockVector primaryPosition;
try {
primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition();