@Override
  public void execute(final Player admin, final List<String> args) {
    int outdated = 0;
    final ObjectCounter<Class<?>> counter = new ObjectCounter<Class<?>>();

    final TurnNotifier turnNotifier = SingletonRepository.getTurnNotifier();
    final int currentTurn = turnNotifier.getCurrentTurnForDebugging();
    final Map<Integer, Set<TurnListener>> events = turnNotifier.getEventListForDebugging();

    for (final Map.Entry<Integer, Set<TurnListener>> it : events.entrySet()) {
      final Integer turn = it.getKey();

      // count outdated
      if (turn.intValue() < currentTurn) {
        outdated++;
      }

      // count classes
      for (final TurnListener event : it.getValue()) {
        counter.add(event.getClass());
      }
    }

    // send result
    admin.sendPrivateText(
        "Statistics: "
            + "\n"
            + counter.getMap()
            + "\nCounted turn events:"
            + events.size()
            + "\nOutdated turn events: "
            + outdated);
  }
  /**
   * Completes handling the buddy action.
   *
   * @param currentTurn ignored
   */
  @Override
  public void onTurnReached(int currentTurn) {
    QueryCanonicalCharacterNamesCommand checkcommand =
        DBCommandQueue.get().getOneResult(QueryCanonicalCharacterNamesCommand.class, handle);

    if (checkcommand == null) {
      TurnNotifier.get().notifyInTurns(0, new TurnListenerDecorator(this));
      return;
    }

    Player player = checkcommand.getPlayer();

    Collection<String> queriedNames = checkcommand.getQueriedNames();
    String who = queriedNames.iterator().next(); // We know, we queried exactly one character.

    Collection<String> validNames = checkcommand.getValidNames();
    if (validNames.isEmpty()) {
      player.sendPrivateText(NotificationType.ERROR, "Sorry, " + who + " could not be found.");
      return;
    }

    // get the canonical name
    who = validNames.iterator().next();
    final Player buddy = SingletonRepository.getRuleProcessor().getPlayer(who);

    if (player.addBuddy(who, (buddy != null) && !buddy.isGhost())) {
      new GameEvent(player.getName(), "buddy", "add", who).raise();
      player.sendPrivateText(who + " was added to your buddy list.");
    } else {
      player.sendPrivateText(who + " was already on your buddy list.");
    }

    new BuddyCleanup(player).cleanup();
  }
示例#3
0
  /**
   * Starts to handle a buddy action.
   *
   * @param player The player.
   * @param action The action.
   */
  public void onAction(final Player player, final RPAction action) {
    if (countBuddies(player) > 500) {
      player.sendPrivateText(NotificationType.ERROR, "Sorry, you have already too many buddies");
      return;
    }

    final String who = action.get(TARGET);

    DBCommand command = new QueryCanonicalCharacterNamesCommand(player, Arrays.asList(who));
    DBCommandQueue.get().enqueueAndAwaitResult(command, handle);
    TurnNotifier.get().notifyInTurns(0, new TurnListenerDecorator(this));
  }