Example #1
0
  /**
   * Set up the player on a new route
   *
   * @param player Player using the start sign
   * @param token Route associated with the start sign
   */
  private void activateStartSign(final Player player, final String token) {
    String message;
    final String name = player.getName();

    synchronized (explorers) {
      final PlayerProgress currentToken = explorers.get(name);

      if (currentToken != null && currentToken.getToken().equalsIgnoreCase(token)) {
        message = ALREADY_EXPLORING_MSG;
      } else {
        if (currentToken == null) {
          message = String.format(EXPLORATION_STARTED_MSG, token);
        } else {
          message =
              ChatColor.YELLOW
                  + "You have switched to exploring "
                  + ChatColor.GREEN
                  + token
                  + ChatColor.YELLOW
                  + "!";
          ;
        }
        explorers.put(name, new PlayerProgress(token));
      }
    }

    player.sendMessage(message);
    saveState();
  }
Example #2
0
  /**
   * Attempt to complete a route.
   *
   * @param player Player using the finish sign
   * @param token Route associated with the finish sign
   * @param w Way-point number required to finish the route
   */
  private void activateFinishSign(final Player player, final String token, final int w) {
    final String name = player.getName();
    final PlayerProgress progress = explorers.get(name);

    final String message;
    boolean broadcast = false;

    if (progress == null) {
      message = NOT_STARTED_MSG;
    } else if (progress.getToken().equalsIgnoreCase(token)) {

      if (progress.getWaypoints() + 1 == w) {
        broadcast = true;
        message = String.format(SUCCESS_MSG, name, token);

        explorers.remove(name);
        addPlayerToExploration(player, token);
        saveState();
      } else {
        message = ChatColor.RED + "You need waypoint " + (progress.getWaypoints() + 1);
      }
    } else {
      message = String.format(BAD_FINISH_MSG, token, progress.getToken());
    }

    if (broadcast) {
      getServer().broadcastMessage(message);
    } else {
      player.sendMessage(message);
    }
  }
Example #3
0
  private void playerStatusCommand(CommandSender sender, final Player player) {
    final String name = player.getName();
    final PlayerProgress progress = explorers.get(name);
    final String formattedToken =
        progress == null ? ChatColor.RED + "None" : progress.toChatString();

    sender.sendMessage(ChatColor.YELLOW + "Exploration: " + formattedToken);
  }
Example #4
0
  /**
   * Notify a player if they are on the current route and thus are able to use the protected block.
   *
   * @param player Player who is touching the sign
   * @param routeName Route associated with the sign
   * @throws ExplorersException
   */
  private void activateEnrouteSign(Player player, String routeName) throws ExplorersException {
    PlayerProgress p = explorers.get(player.getName());

    if (p != null && p.getToken().equalsIgnoreCase(routeName)) {
      player.sendMessage(ChatColor.GREEN + "Unlocked");
    } else {
      player.sendMessage(ChatColor.RED + "You are not on this route.");
    }
  }
Example #5
0
  /**
   * Perform checks when a player uses a route protected block.
   *
   * @param player Player using the block
   * @param routeName Route protecting the block
   * @param cst Type of protection being used.
   * @throws ExplorersException Exceptions will be generated when the route does not exist or when
   *     permission is denied.
   */
  public void allowUseLockedBlock(Player player, String routeName, CommandSignType cst)
      throws ExplorersException {

    if (cst == CommandSignType.LOCK_SIGN) {
      Route r = getExistingRoute(routeName);
      if (!r.isWinner(player)) {
        throw new ExplorersPermissionException();
      }
    } else {
      PlayerProgress p = explorers.get(player.getName());
      if (p == null || !p.getToken().equalsIgnoreCase(routeName)) {
        throw new ExplorersPermissionException();
      }
    }
  }
Example #6
0
  /**
   * Attempt to progress the player along the current route.
   *
   * @param player Player using the sign
   * @param token Route associated with the sign
   * @param w Way-point number associated with the sign
   */
  private void activateWaypointSign(Player player, String token, int w) {
    PlayerProgress progress = explorers.get(player.getName());

    if (progress == null) {
      player.sendMessage(NOT_STARTED_MSG);
    } else if (!progress.getToken().equalsIgnoreCase(token)) {
      player.sendMessage(String.format(BAD_FINISH_MSG, token, progress.getToken()));
    } else {
      if (progress.getWaypoints() + 1 == w) {
        progress.setWaypoints(w);
        player.sendMessage(ChatColor.GREEN + "Progress recorded!");
      } else {
        player.sendMessage(ChatColor.RED + "You need waypoint " + (progress.getWaypoints() + 1));
      }
    }
  }