Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. mapid: List<characterid, donation_amount>
  2.  
  3. Map Id Character Id Amount
  4. 100000 3 100000
  5. 110000 4 200000
  6. 100000 5 10000
  7. 110000 6 100000
  8. 200000 7 0
  9.  
  10. public void loadDonations() {
  11. try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM medal_rankings ORDER BY donated DESC");
  12. ResultSet rs = ps.executeQuery()) {
  13.  
  14. while (rs.next()) {
  15. int mapid = rs.getInt("mapid");
  16. int characterid = rs.getInt("characterid");
  17. int donated = rs.getInt("donated");
  18.  
  19. if (!donations.containsKey(mapid))
  20. donations.put(mapid, new ArrayList<Pair<Integer, Integer>>());
  21. donations.get(mapid).add(new Pair<Integer, Integer>(characterid, donated));
  22. }
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. LogHelper.INVOCABLE.get().info("DonorKing: failed to load donations");
  26. }
  27. }
  28.  
  29. public void addDonation(int amount, int mapid, int characterid) {
  30. List<Pair<Integer, Integer>> map_donations = donations.get(mapid);
  31. if (!donations.containsKey(mapid))
  32. donations.put(mapid, new ArrayList<Pair<Integer, Integer>>());
  33. if (!map_donations.contains(characterid))
  34. map_donations.add(new Pair<Integer, Integer>(characterid, amount));
  35. else {
  36. for (int x = 0; x < map_donations.size(); x++) {
  37. List<Pair<Integer, Integer>> donation = map_donations;
  38. if (donation.get(x).left == characterid) {
  39. amount += donation.get(x).right;
  40. donation.remove(donation.get(x));
  41. break;
  42. }
  43. }
  44.  
  45. for (int x = 0; x < map_donations.size(); x++)
  46. if (map_donations.get(x).right <= amount) {
  47. map_donations.add(new Pair<Integer, Integer>(characterid, amount));
  48. break;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement