/** * Handle direction press to invoke or disable auto-walk. * * @param direction The direction to move/face * @param user The entity to set/check */ private synchronized void processAutoWalk(final Direction direction, final User user) { RPAction walkAction = new RPAction(); final boolean facing = direction == user.getDirection(); /* Correct facing direction if necessary. */ if (!facing) { RPAction faceAction = new RPAction(); faceAction.put(TYPE, FACE); faceAction.put(DIR, direction.get()); this.client.send(faceAction); } /* Check if player is already using auto-walk. */ if (!user.getRPObject().has(AUTOWALK)) { walkAction.put(TYPE, WALK); } else if (facing) { /* Player can press key of current walking direction to toggle * auto-walk off. */ walkAction.put(TYPE, WALK); walkAction.put(MODE, "stop"); } /* Send auto-walk action to the server. */ if (walkAction.has(TYPE)) { /* Toggle auto-walk. */ this.client.send(walkAction); } }