Use current PlayerDirection

This commit is contained in:
Jesse Boyd 2018-08-13 01:43:20 +10:00
parent 289707b410
commit fa06ff357e
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 13 additions and 89 deletions

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
/** /**
@ -29,106 +28,31 @@ import com.sk89q.worldedit.util.Direction;
*/ */
public enum PlayerDirection { public enum PlayerDirection {
NORTH(new Vector(0, 0, -1), new Vector(-1, 0, 0), true), NORTH(new Vector(0, 0, -1), true),
NORTH_EAST((new Vector(1, 0, -1)), (new Vector(-1, 0, -1)), false), NORTH_EAST((new Vector(1, 0, -1)).normalize(), false),
EAST(new Vector(1, 0, 0), new Vector(0, 0, -1), true), EAST(new Vector(1, 0, 0), true),
SOUTH_EAST((new Vector(1, 0, 1)), (new Vector(1, 0, -1)), false), SOUTH_EAST((new Vector(1, 0, 1)).normalize(), false),
SOUTH(new Vector(0, 0, 1), new Vector(1, 0, 0), true), SOUTH(new Vector(0, 0, 1), true),
SOUTH_WEST((new Vector(-1, 0, 1)), (new Vector(1, 0, 1)), false), SOUTH_WEST((new Vector(-1, 0, 1)).normalize(), false),
WEST(new Vector(-1, 0, 0), new Vector(0, 0, 1), true), WEST(new Vector(-1, 0, 0), true),
NORTH_WEST((new Vector(-1, 0, -1)), (new Vector(-1, 0, 1)), false), NORTH_WEST((new Vector(-1, 0, -1)).normalize(), false),
UP(new Vector(0, 1, 0), new Vector(0, 0, 1), true), UP(new Vector(0, 1, 0), true),
DOWN(new Vector(0, -1, 0), new Vector(0, 0, 1), true); DOWN(new Vector(0, -1, 0), true);
private final Vector dir; private final Vector dir;
private final Vector leftDir;
private final boolean isOrthogonal; private final boolean isOrthogonal;
PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) { PlayerDirection(Vector vec, boolean isOrthogonal) {
this.dir = vec; this.dir = vec;
this.leftDir = leftDir;
this.isOrthogonal = isOrthogonal; this.isOrthogonal = isOrthogonal;
} }
public static PlayerDirection valueOf(Player player, String dirStr) throws UnknownDirectionException {
final PlayerDirection dir;
switch (dirStr.charAt(0)) {
case 'w':
dir = PlayerDirection.WEST;
break;
case 'e':
dir = PlayerDirection.EAST;
break;
case 's':
if (dirStr.indexOf('w') > 0) {
return PlayerDirection.SOUTH_WEST;
}
if (dirStr.indexOf('e') > 0) {
return PlayerDirection.SOUTH_EAST;
}
dir = PlayerDirection.SOUTH;
break;
case 'n':
if (dirStr.indexOf('w') > 0) {
return PlayerDirection.NORTH_WEST;
}
if (dirStr.indexOf('e') > 0) {
return PlayerDirection.NORTH_EAST;
}
dir = PlayerDirection.NORTH;
break;
case 'u':
dir = PlayerDirection.UP;
break;
case 'd':
dir = PlayerDirection.DOWN;
break;
case 'm': // me
case 'f': // forward
dir = player.getCardinalDirection(0);
break;
case 'b': // back
dir = player.getCardinalDirection(180);
break;
case 'l': // left
dir = player.getCardinalDirection(-90);
break;
case 'r': // right
dir = player.getCardinalDirection(90);
break;
default:
throw new UnknownDirectionException(dirStr);
}
return dir;
}
public Vector vector() { public Vector vector() {
return dir; return dir;
} }
@Deprecated
public Vector leftVector() {
return leftDir;
}
public boolean isOrthogonal() { public boolean isOrthogonal() {
return isOrthogonal; return isOrthogonal;
} }
public static Class<?> inject() {
return PlayerDirection.class;
}
} }

View File

@ -312,7 +312,7 @@ public class WorldEditBinding extends BindingHelper {
public Vector getDirection(ArgumentStack context, Direction direction) public Vector getDirection(ArgumentStack context, Direction direction)
throws ParameterException, UnknownDirectionException { throws ParameterException, UnknownDirectionException {
Player sender = getPlayer(context); Player sender = getPlayer(context);
return PlayerDirection.valueOf(sender, context.next()).vector(); return worldEdit.getDirection(sender, context.next());
} }
/** /**