3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00

Reduced code duplication in the WorldEdit.get*Direction methods.

Dieser Commit ist enthalten in:
TomyLobo 2011-10-25 01:03:37 +02:00
Ursprung 3962e6c9d8
Commit 2d654b59c5

Datei anzeigen

@ -29,6 +29,7 @@ import javax.script.ScriptException;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.commands.*; import com.sk89q.worldedit.commands.*;
@ -764,8 +765,8 @@ public class WorldEdit {
dirStr = dirStr.toLowerCase(); dirStr = dirStr.toLowerCase();
if (dirStr.equals("me")) { final PlayerDirection dir = getPlayerDirection(player, dirStr);
final PlayerDirection dir = player.getCardinalDirection();
switch (dir) { switch (dir) {
case WEST: case WEST:
case EAST: case EAST:
@ -773,36 +774,63 @@ public class WorldEdit {
case NORTH: case NORTH:
case UP: case UP:
case DOWN: case DOWN:
dirStr = dir.name().toLowerCase(); return dir.vector();
break;
default: default:
throw new UnknownDirectionException(dir.name()); throw new UnknownDirectionException(dir.name());
} }
} }
private PlayerDirection getPlayerDirection(LocalPlayer player, String dirStr) throws UnknownDirectionException {
final PlayerDirection dir;
switch (dirStr.charAt(0)) { switch (dirStr.charAt(0)) {
case 'w': case 'w':
return new Vector(0, 0, 1); dir = PlayerDirection.WEST;
break;
case 'e': case 'e':
return new Vector(0, 0, -1); dir = PlayerDirection.EAST;
break;
case 's': case 's':
return new Vector(1, 0, 0); if (dirStr.indexOf('w') > 0) {
return PlayerDirection.SOUTH_WEST;
}
if (dirStr.indexOf('e') > 0) {
return PlayerDirection.SOUTH_EAST;
}
dir = PlayerDirection.SOUTH;
break;
case 'n': case 'n':
return new Vector(-1, 0, 0); if (dirStr.indexOf('w') > 0) {
return PlayerDirection.NORTH_WEST;
}
if (dirStr.indexOf('e') > 0) {
return PlayerDirection.NORTH_EAST;
}
dir = PlayerDirection.NORTH;
break;
case 'u': case 'u':
return new Vector(0, 1, 0); dir = PlayerDirection.UP;
break;
case 'd': case 'd':
return new Vector(0, -1, 0); dir = PlayerDirection.DOWN;
break;
case 'm':
dir = player.getCardinalDirection(0);
break;
default: default:
throw new UnknownDirectionException(dirStr); throw new UnknownDirectionException(dirStr);
} }
return dir;
} }
/** /**
@ -814,53 +842,10 @@ public class WorldEdit {
* @return * @return
* @throws UnknownDirectionException * @throws UnknownDirectionException
*/ */
public Vector getDiagonalDirection( LocalPlayer player, String dirStr ) public Vector getDiagonalDirection(LocalPlayer player, String dirStr)
throws UnknownDirectionException { throws UnknownDirectionException {
dirStr = dirStr.toLowerCase(); return getPlayerDirection(player, dirStr.toLowerCase()).vector();
if (dirStr.equals("me")) {
dirStr = player.getCardinalDirection().name().toLowerCase();
}
switch (dirStr.charAt(0)) {
case 'w':
return new Vector(0, 0, 1);
case 'e':
return new Vector(0, 0, -1);
case 's':
if (dirStr.indexOf('w') > 0) {
return new Vector(1, 0, 1);
}
if (dirStr.indexOf('e') > 0) {
return new Vector(1, 0, -1);
}
return new Vector(1, 0, 0);
case 'n':
if (dirStr.indexOf('w') > 0) {
return new Vector(-1, 0, 1);
}
if (dirStr.indexOf('e') > 0) {
return new Vector(-1, 0, -1);
}
return new Vector(-1, 0, 0);
case 'u':
return new Vector(0, 1, 0);
case 'd':
return new Vector(0, -1, 0);
default:
throw new UnknownDirectionException(dirStr);
}
} }
/** /**
@ -871,48 +856,28 @@ public class WorldEdit {
* @return * @return
* @throws UnknownDirectionException * @throws UnknownDirectionException
*/ */
public CuboidClipboard.FlipDirection getFlipDirection( public FlipDirection getFlipDirection(LocalPlayer player, String dirStr)
LocalPlayer player, String dirStr)
throws UnknownDirectionException { throws UnknownDirectionException {
if (dirStr.equals("me")) { final PlayerDirection dir = getPlayerDirection(player, dirStr);
final PlayerDirection dir = player.getCardinalDirection();
switch (dir) { switch (dir) {
case WEST: case WEST:
case EAST: case EAST:
return CuboidClipboard.FlipDirection.WEST_EAST; return FlipDirection.WEST_EAST;
case NORTH: case NORTH:
case SOUTH: case SOUTH:
return CuboidClipboard.FlipDirection.NORTH_SOUTH; return FlipDirection.NORTH_SOUTH;
case UP: case UP:
case DOWN: case DOWN:
return CuboidClipboard.FlipDirection.UP_DOWN; return FlipDirection.UP_DOWN;
default: default:
throw new UnknownDirectionException(dir.name()); throw new UnknownDirectionException(dir.name());
} }
} }
switch (dirStr.charAt(0)) {
case 'w':
case 'e':
return CuboidClipboard.FlipDirection.WEST_EAST;
case 'n':
case 's':
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
case 'u':
case 'd':
return CuboidClipboard.FlipDirection.UP_DOWN;
default:
throw new UnknownDirectionException(dirStr);
}
}
/** /**
* Remove a session. * Remove a session.
* *