Placeholders for island level/votes rank

This commit is contained in:
Esophose 2019-04-08 18:12:20 -06:00
parent 80b856f7c0
commit 1d80ffbaeb
3 changed files with 68 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import me.goodandevil.skyblock.leaderboard.leaderheads.TopLevel;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopVotes;
import me.goodandevil.skyblock.visit.Visit;
import me.goodandevil.skyblock.visit.VisitManager;
import org.bukkit.entity.Player;
public class LeaderboardManager {
@ -63,6 +64,40 @@ public class LeaderboardManager {
}
}
public int getPlayerIslandLeaderboardPosition(Player player, Leaderboard.Type type) {
VisitManager visitManager = skyblock.getVisitManager();
visitManager.loadIslands();
List<LeaderboardPlayer> leaderboardPlayers = new ArrayList<>();
switch (type) {
case Level:
for (int i = 0; i < visitManager.getIslands().size(); i++) {
UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[i];
Visit visit = visitManager.getIslands().get(ownerUUID);
leaderboardPlayers.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel()));
}
break;
case Votes:
for (int i = 0; i < visitManager.getIslands().size(); i++) {
UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[i];
Visit visit = visitManager.getIslands().get(ownerUUID);
leaderboardPlayers.add(new LeaderboardPlayer(ownerUUID, visit.getVoters().size()));
}
break;
}
leaderboardPlayers.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed());
for (int i = 0; i < leaderboardPlayers.size(); i++) {
if (leaderboardPlayers.get(i).getUUID().equals(player.getUniqueId())) {
return i + 1;
}
}
return -1;
}
public void setupLeaderHeads() {
if (Bukkit.getServer().getPluginManager().getPlugin("LeaderHeads") != null) {
new TopLevel(skyblock);

View File

@ -7,6 +7,7 @@ import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandManager;
import me.goodandevil.skyblock.island.IslandRole;
import me.goodandevil.skyblock.leaderboard.Leaderboard;
import me.goodandevil.skyblock.leaderboard.LeaderboardManager;
import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.levelling.LevellingMaterial;
import me.goodandevil.skyblock.utils.NumberUtil;
@ -306,6 +307,28 @@ public class PlaceholderManager {
configLoad.getString("Placeholder.fabledskyblock_island_bank_balance.Non-empty.Message"))
.replace("%placeholder", "" + island.getBankBalance());
}
} else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_level_rank")) {
if (island == null) {
return ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Empty.Message"));
} else {
LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager();
int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Level);
return ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Non-empty.Message")
.replace("%placeholder", "" + rank));
}
} else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_votes_rank")) {
if (island == null) {
return ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Empty.Message"));
} else {
LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager();
int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Votes);
return ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Non-empty.Message")
.replace("%placeholder", "" + rank));
}
} else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_level_block_count_")) {
if (island == null) {
return ChatColor.translateAlternateColorCodes('&',

View File

@ -1205,6 +1205,16 @@ Placeholder:
Message: "&c0"
Non-empty:
Message: "&f%placeholder"
fabledskyblock_island_leaderboard_level_rank:
Empty:
Message: "&c0"
Non-empty:
Message: "&f%placeholder"
fabledskyblock_island_leaderboard_votes_rank:
Empty:
Message: "&c0"
Non-empty:
Message: "&f%placeholder"
fabledskyblock_island_level_block_count:
Empty:
Message: "&c0"