Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ServerInfo getBetterLobby() {
- if(UnikBungee.getOnlineLobbys().isEmpty())
- if(getOnlineLobbys().isEmpty())
- return null;
- Map<ServerInfo, Integer> map = sortByValues(getOnlineLobbys());
- return map.keySet().iterator().next();
- }
- /* Trier une HashMap en fonction des valeurs
- *
- * @param map HashMap à trier
- * @return HashMap triée
- */
- public static HashMap sortByValues(HashMap map) {
- List list = new LinkedList(map.entrySet());
- Collections.sort(list, new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) ((Map.Entry) (o1)).getValue())
- .compareTo(((Map.Entry) (o2)).getValue());
- }
- });
- HashMap sortedHashMap = new LinkedHashMap();
- for (Iterator it = list.iterator(); it.hasNext(); ) {
- Map.Entry entry = (Map.Entry) it.next();
- sortedHashMap.put(entry.getKey(), entry.getValue());
- }
- return sortedHashMap;
- }
- /*Récupérer les Lobbys en ligne
- *
- * @return Un Map de ServerInfo, joueur en ligne.
- */
- public static HashMap<ServerInfo, Integer> getOnlineLobbys() {
- HashMap<ServerInfo, Integer> lobbys = new HashMap<>();
- for (ServerInfo si : ProxyServer.getInstance().getServers().values())
- if (si.getName().contains("Lobby"))
- lobbys.put(si, si.getPlayers().size());
- return lobbys;
- }
Advertisement
Add Comment
Please, Sign In to add comment