SHARE
TWEET

Untitled

a guest Nov 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public LinkedHashMap<Double, String> getMoneyTop() {
  2.         try {
  3.             String sql = "SELECT player, money FROM economy ORDER BY money DESC LIMIT 10";
  4.             PreparedStatement stmt = connection.prepareStatement(sql);
  5.             ResultSet results = stmt.executeQuery();
  6.            
  7.             Map<Double, String> playersInfo = new TreeMap<Double, String>(Collections.reverseOrder()); // player / money
  8.            
  9.             LinkedHashMap<Double, String> playersInfoSorted = new LinkedHashMap<>();
  10.            
  11.            
  12.             while(results.next()) {
  13.                 playersInfo.put(results.getDouble("money"), results.getString("player"));
  14.             }
  15.             playersInfo.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
  16.             .forEachOrdered(x -> playersInfoSorted.put(x.getKey(), x.getValue()));
  17.             return playersInfoSorted;
  18.            
  19.         } catch (SQLException e) {
  20.             Bukkit.getConsoleSender().sendMessage(serverTag + "§4[ERR:DB:3.2] §cFailed to DB_SELECT => @sqlSelect");
  21.             e.printStackTrace();
  22.         }
  23.         return null;
  24.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top