Untitled

 avatar
unknown
plain_text
3 years ago
2.9 kB
6
Indexable
.














public class HologramLB extends Leaderboard {

    private final String[] leaderboardLines;
    private Hologram hologram;

    public HologramLB(Location location, LeaderboardType leaderboardType) {
        super(location, leaderboardType);

        this.leaderboardLines = new String[]{
                "&d10. {10_name} &7- &e{10_playerstats}",
                "&d9. {9_name} &7- &e{9_playerstats}",
                "&d8. {8_name} &7- &e{8_playerstats}",
                "&d7. {7_name} &7- &e{7_playerstats}",
                "&d6. {6_name} &7- &e{6_playerstats}",
                "&d5. {5_name} &7- &e{5_playerstats}",
                "&d4. {4_name} &7- &e{4_playerstats}",
                "&d3. {3_name} &7- &e{3_playerstats}",
                "&d2. {2_name} &7- &e{2_playerstats}",
                "&d1. {1_name} &7- &e{1_playerstats}",
                "",
                "&7All Modes",
                "&d&l{stats}"
        };
    }

    @SneakyThrows
    @Override
    public void spawnOrUpdate() {
        final CachedRowSet cachedRowSet = DatabaseManager.query(getLeaderboardType().getSql());
        final Map<Integer, String> map = IntStream.range(0, leaderboardLines.length).boxed()
                .collect(Collectors.toMap(i -> i + 1, i -> leaderboardLines[i].replace("{stats}", getLeaderboardType().getDisplayName()), (a, b) -> b));

        int slot = 1;
        if (cachedRowSet != null) {
            cachedRowSet.beforeFirst();
            while (cachedRowSet.next()) {

                final int count = cachedRowSet.getInt(getLeaderboardType().getRows());
                final String lastRank = DatabaseManager.query("SELECT `lastRank` FROM `FeatherAccount` WHERE `name` = ?",
                        cachedRowSet.getString("name")).getString("lastRank");
                for (Integer i : map.keySet()) map.put(i, map.get(i).replace("{" + slot + "_name}", lastRank + cachedRowSet.getString("name"))
                            .replace("{" + slot + "_playerstats}", new DecimalFormat("#,###").format(count)));
                slot++;
            }
        }

        while (slot < 100) {
            for (Integer i : map.keySet()) map.put(i, map.get(i).replace("{" + slot + "_name}", "&7None").replace("{" + slot + "_playerstats}", "0"));
            slot++;
        }

        final List<String> lines = IntStream.range(0, leaderboardLines.length).mapToObj(i -> map.get(i + 1)).collect(Collectors.toList());
        if (hologram == null) hologram = HologramUtil.createHologram(getLocation(), lines);
        else IntStream.range(0, lines.size()).forEach(i -> hologram.updateLine(i + 1, lines.get(i)));
    }


    @Override
    public void remove() {
        if (hologram == null) return;
        HologramUtil.removeHologram(hologram);
        this.hologram = null;
    }

}
Editor is loading...