From: MadMetzger <mad...@us...> - 2010-04-07 18:35:40
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/client In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv28162/src/games/stendhal/client Modified Files: PlayerList.java World.java Log Message: make tab completion work without calling /who before (fixes #2983381) Index: World.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/World.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** World.java 4 Jan 2009 14:45:38 -0000 1.2 --- World.java 7 Apr 2010 18:35:32 -0000 1.3 *************** *** 3,9 **** public final class World { ! private static final World instance = new World(); public static World get() { return instance; } --- 3,12 ---- public final class World { ! private static World instance; public static World get() { + if(instance == null) { + instance = new World(); + } return instance; } *************** *** 11,17 **** private PlayerList playerList = new PlayerList(); ! public static PlayerList getPlayerList() { ! return get().playerList; } } --- 14,27 ---- private PlayerList playerList = new PlayerList(); ! public PlayerList getPlayerList() { ! return playerList; ! } ! ! public void removePlayerLoggingOut(String player) { ! playerList.removePlayer(player); } + public void addPlayerLoggingOn(String player) { + playerList.addPlayer(player); + } } Index: PlayerList.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/PlayerList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PlayerList.java 2 Dec 2008 17:29:05 -0000 1.2 --- PlayerList.java 7 Apr 2010 18:35:32 -0000 1.3 *************** *** 1,38 **** package games.stendhal.client; ! import java.util.Vector; ! import java.util.regex.Matcher; ! import java.util.regex.Pattern; public class PlayerList { ! private Vector<String> namesList = new Vector<String>(); ! public Vector<String> getNamesList() { return namesList; } - - public void generateWhoPlayers(final String text) { - - Matcher matcher = Pattern.compile("^[0-9]+ Players online:( .+)$").matcher( - text); - - if (matcher.find()) { - final String[] names = matcher.group(1).split("\\s+"); ! getNamesList().removeAllElements(); ! for (int i = 0; i < names.length; i++) { ! /* ! * NOTE: On the future Players names won't have any non ascii ! * character. ! */ ! matcher = Pattern.compile( ! "^([-_a-zA-Z0-9äöüÃÃÃÃ]+)\\([0-9]+\\)$").matcher( ! names[i]); ! if (matcher.find()) { ! getNamesList().addElement(matcher.group(1)); ! } ! } ! } } } --- 1,25 ---- package games.stendhal.client; ! import java.util.HashSet; ! import java.util.Set; public class PlayerList { ! ! private Set<String> namesList = new HashSet<String>(); ! public Set<String> getNamesList() { return namesList; } ! public void removePlayer(String player) { ! namesList.remove(player); ! } + public void addPlayer(String player) { + namesList.add(player); + } + + public boolean contains(String player) { + return namesList.contains(player); } } |