Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mapid: List<characterid, donation_amount>
- Map Id Character Id Amount
- 100000 3 100000
- 110000 4 200000
- 100000 5 10000
- 110000 6 100000
- 200000 7 0
- public void loadDonations() {
- try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM medal_rankings ORDER BY donated DESC");
- ResultSet rs = ps.executeQuery()) {
- while (rs.next()) {
- int mapid = rs.getInt("mapid");
- int characterid = rs.getInt("characterid");
- int donated = rs.getInt("donated");
- if (!donations.containsKey(mapid))
- donations.put(mapid, new ArrayList<Pair<Integer, Integer>>());
- donations.get(mapid).add(new Pair<Integer, Integer>(characterid, donated));
- }
- } catch (Exception e) {
- e.printStackTrace();
- LogHelper.INVOCABLE.get().info("DonorKing: failed to load donations");
- }
- }
- public void addDonation(int amount, int mapid, int characterid) {
- List<Pair<Integer, Integer>> map_donations = donations.get(mapid);
- if (!donations.containsKey(mapid))
- donations.put(mapid, new ArrayList<Pair<Integer, Integer>>());
- if (!map_donations.contains(characterid))
- map_donations.add(new Pair<Integer, Integer>(characterid, amount));
- else {
- for (int x = 0; x < map_donations.size(); x++) {
- List<Pair<Integer, Integer>> donation = map_donations;
- if (donation.get(x).left == characterid) {
- amount += donation.get(x).right;
- donation.remove(donation.get(x));
- break;
- }
- }
- for (int x = 0; x < map_donations.size(); x++)
- if (map_donations.get(x).right <= amount) {
- map_donations.add(new Pair<Integer, Integer>(characterid, amount));
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement