Advertisement
Superloup10

Untitled

Dec 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. public List[] getRanking(int stat) {
  2.         List[] rank = new List[3];
  3.         Connection connection = getNewConnection();
  4.         if(connection != null) {
  5.             Statement state = null;
  6.             try {
  7.                 state = connection.createStatement();
  8.                 String st = "game";
  9.                 switch(stat) {
  10.                     case 1:
  11.                         st = "kill";
  12.                         break;
  13.                     case 2:
  14.                         st = "death";
  15.                         break;
  16.                     case 3:
  17.                         st = "win";
  18.                         break;
  19.                     case 4:
  20.                         st = "feast";
  21.                         break;
  22.                     case 5:
  23.                         st = "spec";
  24.                         break;
  25.                     case 6:
  26.                         st = "rand";
  27.                         break;
  28.                     default:
  29.                         st = "game";
  30.                 }
  31.  
  32.                 ResultSet s = state.executeQuery("SELECT `uuid`,`username`,`rank_" + st + "` FROM `nhg`.`st_user` ORDER BY `rank_" + st + "` DESC LIMIT 25");
  33.                 if(s != null) {
  34.                     List<String> uuid = new ArrayList<>();
  35.                     List<String> players = new ArrayList<>();
  36.                     List<Integer> stats = new ArrayList<>();
  37.  
  38.                     while(s.next()) {
  39.                         uuid.add(s.getString("uuid"));
  40.                         players.add(s.getString("username"));
  41.                         stats.add(s.getInt("rank_" + st));
  42.                     }
  43.                     s.close();
  44.  
  45.                     rank = new List[] {uuid, players, stats};
  46.                 }
  47.             }
  48.             catch(SQLException e) {
  49.                 e.printStackTrace();
  50.                 SQLLog.logAndMail("", e.toString(), e.getStackTrace());
  51.             }
  52.             finally {
  53.                 safeClose(connection, state);
  54.             }
  55.         }
  56.         return rank;
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement