From: Astrid S. <ast...@us...> - 2007-12-17 11:29:11
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/actions In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv16439/src/games/stendhal/server/actions Modified Files: ChatAction.java PlayersQuery.java Log Message: start hiding implementation details on Players in ruleprocessor Index: PlayersQuery.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/actions/PlayersQuery.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** PlayersQuery.java 15 Dec 2007 15:41:39 -0000 1.40 --- PlayersQuery.java 17 Dec 2007 11:29:14 -0000 1.41 *************** *** 13,17 **** package games.stendhal.server.actions; - import games.stendhal.server.actions.admin.AdministrationAction; import games.stendhal.server.core.engine.StendhalRPRuleProcessor; import games.stendhal.server.core.engine.StendhalRPZone; --- 13,16 ---- *************** *** 21,24 **** --- 20,24 ---- import java.util.ArrayList; + import java.util.Collection; import java.util.Collections; import java.util.Comparator; *************** *** 31,35 **** private static final String _SHEEP = "sheep"; - private static final String _ATTR_TITLE = "title"; private static final String _WHERE = "where"; private static final String _WHO = "who"; --- 31,34 ---- *************** *** 50,75 **** public void onWho(Player player, RPAction action) { ! ! final int REQUIRED_LEVEL_TO_SEE_GHOST = AdministrationAction.getLevelForCommand("ghostmode"); ! StendhalRPRuleProcessor rules = StendhalRPRuleProcessor.get(); ! if (player.has(_ATTR_TITLE)) { ! rules.addGameEvent(player.get(_ATTR_TITLE), _WHO); ! } rules.addGameEvent(player.getName(), _WHO); StringBuilder online = new StringBuilder(); ! int amount = 0; ! for (Player p : rules.getPlayers()) { ! if (!p.isGhost() ! || player.getAdminLevel() > REQUIRED_LEVEL_TO_SEE_GHOST) { ! amount++; ! } ! } online.append(amount + " Players online: "); ! for (Player p : getSortedPlayers()) { ! if (!p.isGhost() ! || player.getAdminLevel() > REQUIRED_LEVEL_TO_SEE_GHOST) { String playername = p.getTitle(); --- 49,65 ---- public void onWho(Player player, RPAction action) { ! final Collection< ? extends Player> playerlist = StendhalRPRuleProcessor.getPlayers(player.getAdminLevel()); ! StendhalRPRuleProcessor rules = StendhalRPRuleProcessor.get(); ! rules.addGameEvent(player.getName(), _WHO); StringBuilder online = new StringBuilder(); ! int amount = playerlist.size(); online.append(amount + " Players online: "); ! ! ! for (Player p : getSortedPlayers(playerlist)) { String playername = p.getTitle(); *************** *** 83,101 **** online.append(p.getLevel()); online.append(") "); ! } } player.sendPrivateText(online.toString()); player.notifyWorldAboutChanges(); - } /** * sorts the list of players. * ! * @return sorted list of players */ ! private List<Player> getSortedPlayers() { ! StendhalRPRuleProcessor rules = StendhalRPRuleProcessor.get(); ! List<Player> players = new ArrayList<Player>(rules.getPlayers()); Collections.sort(players, new Comparator<Player>() { --- 73,90 ---- online.append(p.getLevel()); online.append(") "); ! } player.sendPrivateText(online.toString()); player.notifyWorldAboutChanges(); } /** * sorts the list of players. + * @param playerlist TODO * ! * @return sorted list of players< */ ! private List<Player> getSortedPlayers(Collection< ? extends Player> playerlist) { ! List<Player> players = new ArrayList<Player>(playerlist); Collections.sort(players, new Comparator<Player>() { *************** *** 120,125 **** if (zone != null) { ! player.sendPrivateText(who.getTitle() + " is in " ! + zone.getName() + " at (" + who.getX() + "," + who.getY() + ")"); } --- 109,113 ---- if (zone != null) { ! player.sendPrivateText(who.getTitle() + " is in " + zone.getName() + " at (" + who.getX() + "," + who.getY() + ")"); } *************** *** 128,133 **** if (sheep != null) { ! player.sendPrivateText("Your sheep is at (" + sheep.getX() ! + "," + sheep.getY() + ")"); } else { --- 116,120 ---- if (sheep != null) { ! player.sendPrivateText("Your sheep is at (" + sheep.getX() + "," + sheep.getY() + ")"); } else { *************** *** 138,143 **** if (pet != null) { ! player.sendPrivateText("Your pet is at (" + pet.getX() ! + "," + pet.getY() + ")"); } else { --- 125,129 ---- if (pet != null) { ! player.sendPrivateText("Your pet is at (" + pet.getX() + "," + pet.getY() + ")"); } else { *************** *** 145,150 **** } } else { ! player.sendPrivateText("No player named \"" + whoName ! + "\" is currently logged in."); } --- 131,135 ---- } } else { ! player.sendPrivateText("No player named \"" + whoName + "\" is currently logged in."); } Index: ChatAction.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/actions/ChatAction.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** ChatAction.java 15 Dec 2007 15:41:39 -0000 1.47 --- ChatAction.java 17 Dec 2007 11:29:14 -0000 1.48 *************** *** 272,276 **** _SUPPORT, action.get(TEXT)); ! sendMessageToSupporters(player.getTitle(), message); player.sendPrivateText("You ask for support: " --- 272,276 ---- _SUPPORT, action.get(TEXT)); ! StendhalRPRuleProcessor.sendMessageToSupporters(player.getTitle(), message); player.sendPrivateText("You ask for support: " *************** *** 283,308 **** /** - * sends a message to all supporters. - * - * @param source - * a player or script name - * @param message - * Support message - */ - // TODO: try to clean up the dependencies, having other places in - // the code call directly into an action does not seem to be a - // good idea - public static void sendMessageToSupporters(final String source, - final String message) { - String text = source + " asks for support to ADMIN: " + message; - for (Player p : StendhalRPRuleProcessor.get().getPlayers()) { - if (p.getAdminLevel() >= AdministrationAction.REQUIRED_ADMIN_LEVEL_FOR_SUPPORT) { - p.sendPrivateText(text); - p.notifyWorldAboutChanges(); - } - } - } - - /** * Deletes the chatlog after a short delay. Note this runs inside a thread * outside the normal turn based processing because the SQL command may take --- 283,286 ---- |