private static Location getAdjacentTrack(final Block center, final BlockFace dir) {
   if (MinecartUtils.isTrack(center.getRelative(dir)))
     return center.getRelative(dir).getLocation();
   if ((center.getRelative(dir).getTypeId() == Material.CHEST.getId())
       && MinecartUtils.isTrack(center.getRelative(dir).getRelative(dir)))
     return center.getRelative(dir).getRelative(dir).getLocation();
   return null;
 }
 private static Location getAdjacentTrack(final Block center) {
   if (MinecartUtils.isTrack(center.getRelative(-1, 0, 0)))
     return center.getRelative(-1, 0, 0).getLocation();
   else if (MinecartUtils.isTrack(center.getRelative(-1, -1, 0))
       && MinecartUtils.isSlopedTrack(center.getRelative(-1, -1, 0)))
     return center.getRelative(-1, 0, 0).getLocation();
   if (MinecartUtils.isTrack(center.getRelative(0, 0, -1)))
     return center.getRelative(0, 0, -1).getLocation();
   else if (MinecartUtils.isTrack(center.getRelative(0, -1, -1))
       && MinecartUtils.isSlopedTrack(center.getRelative(0, -1, -1)))
     return center.getRelative(0, 0, -1).getLocation();
   if (MinecartUtils.isTrack(center.getRelative(1, 0, 0)))
     return center.getRelative(1, 0, 0).getLocation();
   else if (MinecartUtils.isTrack(center.getRelative(1, -1, 0))
       && MinecartUtils.isSlopedTrack(center.getRelative(1, -1, 0)))
     return center.getRelative(1, 0, 0).getLocation();
   if (MinecartUtils.isTrack(center.getRelative(0, 0, 1)))
     return center.getRelative(0, 0, 1).getLocation();
   else if (MinecartUtils.isTrack(center.getRelative(0, -1, 1))
       && MinecartUtils.isSlopedTrack(center.getRelative(0, -1, 1)))
     return center.getRelative(0, 0, 1).getLocation();
   return null;
 }
  public static void processStation(MinecartEvent event) {
    MinecartManiaMinecart minecart = event.getMinecart();

    ArrayList<Sign> signList = SignUtils.getAdjacentSignList(minecart, 2);
    for (Sign sign : signList) {
      convertCraftBookSorter(sign);
      for (int k = 0; k < 4; k++) {
        // Setup initial data
        String str = sign.getLine(k);
        String newLine = str;
        String val[] = str.split(":");
        if (val.length != 2) {
          continue;
        }
        // Strip header and ending characters
        val[0] = StringUtils.removeBrackets(val[0]);
        val[1] = StringUtils.removeBrackets(val[1]);
        // Strip whitespace
        val[0] = val[0].trim();
        val[1] = val[1].trim();
        boolean valid = false;
        // end of data setup

        for (StationCondition e : StationCondition.values()) {
          if (e.result(minecart, val[0])) {
            valid = true;
            break;
          }
        }

        if (valid) {
          CompassDirection direction = CompassDirection.NO_DIRECTION;

          for (StationDirection e : StationDirection.values()) {
            direction = e.direction(minecart, val[1]);
            if (direction != CompassDirection.NO_DIRECTION) {
              break;
            }
          }

          // Special case - if we are at a launcher, set the launch speed as well
          // mze 2012-08-29: Remove it because it makes more problems than it solves...
          /*if (event instanceof MinecartLaunchedEvent && direction != null && direction != CompassDirection.NO_DIRECTION) {
          	minecart.setMotion(direction, 0.6D);
          	((MinecartLaunchedEvent)event).setLaunchSpeed(minecart.minecart.getVelocity());
          }*/

          // setup sign formatting
          newLine = StringUtils.removeBrackets(newLine);
          char[] ch = {' ', ':'};
          newLine = WordUtils.capitalize(newLine, ch);
          newLine = StringUtils.addBrackets(newLine);

          boolean handled = false;
          // Handle minecart destruction
          if (direction == null) {
            // vanish sign, minecart is just gone ;)
            if (val[1].equals("V") || val[1].toLowerCase().contains("vanish")) {
              minecart.kill(false);
            }

            minecart.kill();
            handled = true;
          } else if (MinecartUtils.validMinecartTrack(
              minecart.minecart.getWorld(),
              minecart.getX(),
              minecart.getY(),
              minecart.getZ(),
              2,
              direction)) {
            int data =
                DirectionUtils.getMinetrackRailDataForDirection(direction, minecart.getDirection());
            if (data != -1) {
              handled = true;

              // Force the game to remember the old data of the rail we are on, and reset it once we
              // are done
              Block oldBlock =
                  MinecartManiaWorld.getBlockAt(
                      minecart.minecart.getWorld(),
                      minecart.getX(),
                      minecart.getY(),
                      minecart.getZ());
              ArrayList<Integer> blockData = new ArrayList<Integer>();
              blockData.add(new Integer(oldBlock.getX()));
              blockData.add(new Integer(oldBlock.getY()));
              blockData.add(new Integer(oldBlock.getZ()));
              blockData.add(new Integer(oldBlock.getData()));
              minecart.setDataValue("old rail data", blockData);

              // change the track dirtion
              MinecartManiaWorld.setBlockData(
                  minecart.minecart.getWorld(),
                  minecart.getX(),
                  minecart.getY(),
                  minecart.getZ(),
                  data);
            } else if (DirectionUtils.getOppositeDirection(direction)
                .equals(minecart.getDirection())) {
              // format the sign
              minecart.reverse();
              handled = true;
            }
          }

          if (handled) {
            event.setActionTaken(true);
            // format the sign
            sign.setLine(k, newLine);
            sign.update(true);
            return;
          }
        }
      }
    }
  }