/** * 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(); }
/** * 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)); }
@Override public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) { String orgAge = null; if (index > -1) { orgAge = player.getQuest(questname, index); } else { orgAge = player.getQuest(questname); } int diff = player.getAge() - Integer.parseInt(orgAge); DBCommandQueue.get() .enqueue(new WriteHallOfFamePointsCommand(player.getName(), fametype, diff, false)); }