From fa06ff357eb16a6cf4d692cb72d4dcfdd94426b1 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 13 Aug 2018 01:43:20 +1000 Subject: [PATCH] Use current PlayerDirection --- .../com/sk89q/worldedit/PlayerDirection.java | 100 +++--------------- .../internal/command/WorldEditBinding.java | 2 +- 2 files changed, 13 insertions(+), 89 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java index 637a3532b..45eb24dba 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit; -import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Direction; /** @@ -29,106 +28,31 @@ import com.sk89q.worldedit.util.Direction; */ public enum PlayerDirection { - NORTH(new Vector(0, 0, -1), new Vector(-1, 0, 0), true), - NORTH_EAST((new Vector(1, 0, -1)), (new Vector(-1, 0, -1)), false), - EAST(new Vector(1, 0, 0), new Vector(0, 0, -1), true), - SOUTH_EAST((new Vector(1, 0, 1)), (new Vector(1, 0, -1)), false), - SOUTH(new Vector(0, 0, 1), new Vector(1, 0, 0), true), - SOUTH_WEST((new Vector(-1, 0, 1)), (new Vector(1, 0, 1)), false), - WEST(new Vector(-1, 0, 0), new Vector(0, 0, 1), true), - NORTH_WEST((new Vector(-1, 0, -1)), (new Vector(-1, 0, 1)), false), - UP(new Vector(0, 1, 0), new Vector(0, 0, 1), true), - DOWN(new Vector(0, -1, 0), new Vector(0, 0, 1), true); + NORTH(new Vector(0, 0, -1), true), + NORTH_EAST((new Vector(1, 0, -1)).normalize(), false), + EAST(new Vector(1, 0, 0), true), + SOUTH_EAST((new Vector(1, 0, 1)).normalize(), false), + SOUTH(new Vector(0, 0, 1), true), + SOUTH_WEST((new Vector(-1, 0, 1)).normalize(), false), + WEST(new Vector(-1, 0, 0), true), + NORTH_WEST((new Vector(-1, 0, -1)).normalize(), false), + UP(new Vector(0, 1, 0), true), + DOWN(new Vector(0, -1, 0), true); private final Vector dir; - private final Vector leftDir; private final boolean isOrthogonal; - PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) { + PlayerDirection(Vector vec, boolean isOrthogonal) { this.dir = vec; - this.leftDir = leftDir; 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() { return dir; } - @Deprecated - public Vector leftVector() { - return leftDir; - } - public boolean isOrthogonal() { return isOrthogonal; } - public static Class inject() { - return PlayerDirection.class; - } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java index d3c97bc58..ff04710b6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java @@ -312,7 +312,7 @@ public class WorldEditBinding extends BindingHelper { public Vector getDirection(ArgumentStack context, Direction direction) throws ParameterException, UnknownDirectionException { Player sender = getPlayer(context); - return PlayerDirection.valueOf(sender, context.next()).vector(); + return worldEdit.getDirection(sender, context.next()); } /**