diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/admin/RemoveHologramCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/admin/RemoveHologramCommand.java index f088e468..c17a4060 100644 --- a/src/main/java/me/goodandevil/skyblock/command/commands/admin/RemoveHologramCommand.java +++ b/src/main/java/me/goodandevil/skyblock/command/commands/admin/RemoveHologramCommand.java @@ -43,10 +43,16 @@ public class RemoveHologramCommand extends SubCommand { if (args.length == 1) { HologramType hologramType = null; - if (args[0].equalsIgnoreCase("Level")) { - hologramType = HologramType.Level; - } else if (args[0].equalsIgnoreCase("Votes")) { - hologramType = HologramType.Votes; + switch (args[0].toLowerCase()) { + case "level": + hologramType = HologramType.Level; + break; + case "bank": + hologramType = HologramType.Bank; + break; + case "votes": + hologramType = HologramType.Votes; + break; } if (hologramType != null) { @@ -107,6 +113,6 @@ public class RemoveHologramCommand extends SubCommand { @Override public String[] getArguments() { - return new String[] { "level", "votes" }; + return new String[] { "level", "bank", "votes" }; } } diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/admin/SetHologramCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/admin/SetHologramCommand.java index a28a314c..d495f4a5 100644 --- a/src/main/java/me/goodandevil/skyblock/command/commands/admin/SetHologramCommand.java +++ b/src/main/java/me/goodandevil/skyblock/command/commands/admin/SetHologramCommand.java @@ -32,10 +32,16 @@ public class SetHologramCommand extends SubCommand { if (args.length == 1) { HologramType hologramType = null; - if (args[0].equalsIgnoreCase("Level")) { - hologramType = HologramType.Level; - } else if (args[0].equalsIgnoreCase("Votes")) { - hologramType = HologramType.Votes; + switch (args[0].toLowerCase()) { + case "level": + hologramType = HologramType.Level; + break; + case "bank": + hologramType = HologramType.Bank; + break; + case "votes": + hologramType = HologramType.Votes; + break; } if (hologramType != null) { @@ -91,6 +97,6 @@ public class SetHologramCommand extends SubCommand { @Override public String[] getArguments() { - return new String[] { "level", "votes" }; + return new String[] { "level", "bank", "votes" }; } } diff --git a/src/main/java/me/goodandevil/skyblock/hologram/HologramManager.java b/src/main/java/me/goodandevil/skyblock/hologram/HologramManager.java index 8aa76516..9571d31f 100644 --- a/src/main/java/me/goodandevil/skyblock/hologram/HologramManager.java +++ b/src/main/java/me/goodandevil/skyblock/hologram/HologramManager.java @@ -41,7 +41,7 @@ public class HologramManager { removeWorldHolograms(); for (HologramType hologramTypeList : HologramType.values()) { - if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Votes) { + if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) { if (hologramTypeList == HologramType.Votes) { if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) .getFileConfiguration().getBoolean("Island.Visitor.Vote")) { @@ -77,10 +77,16 @@ public class HologramManager { List hologramLines = new ArrayList<>(); Leaderboard.Type leaderboardType = null; - if (type == HologramType.Level) { - leaderboardType = Leaderboard.Type.Level; - } else if (type == HologramType.Votes) { - leaderboardType = Leaderboard.Type.Votes; + switch (type) { + case Level: + leaderboardType = Leaderboard.Type.Level; + break; + case Bank: + leaderboardType = Leaderboard.Type.Bank; + break; + case Votes: + leaderboardType = Leaderboard.Type.Votes; + break; } hologramLines.add(messageManager.replaceMessage(null, @@ -109,13 +115,22 @@ public class HologramManager { IslandLevel level = visit.getLevel(); hologramLines.add(ChatColor.translateAlternateColorCodes('&', languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); + } else if (type == HologramType.Bank) { + hologramLines.add(ChatColor.translateAlternateColorCodes('&', + languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) + .replace("%balance", + "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance())))); } else if (type == HologramType.Votes) { hologramLines.add(ChatColor.translateAlternateColorCodes('&', languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) .replace("%votes", "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size())))); } @@ -166,7 +181,7 @@ public class HologramManager { FileConfiguration configLoad = config.getFileConfiguration(); for (HologramType hologramTypeList : HologramType.values()) { - if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Votes) { + if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) { if (configLoad.getString("Location.Hologram.Leaderboard." + hologramTypeList.name()) != null) { locations.add(fileManager.getLocation(config, "Location.Hologram.Leaderboard." + hologramTypeList.name(), true)); @@ -220,7 +235,7 @@ public class HologramManager { .getFileConfiguration(); for (HologramType hologramTypeList : HologramType.values()) { - if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Votes) { + if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) { if (hologramTypeList == HologramType.Votes) { if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Visitor.Vote")) { @@ -238,10 +253,16 @@ public class HologramManager { Leaderboard.Type leaderboardType = null; - if (hologramTypeList == HologramType.Level) { - leaderboardType = Leaderboard.Type.Level; - } else if (hologramTypeList == HologramType.Votes) { - leaderboardType = Leaderboard.Type.Votes; + switch (hologramTypeList) { + case Level: + leaderboardType = Leaderboard.Type.Level; + break; + case Bank: + leaderboardType = Leaderboard.Type.Bank; + break; + case Votes: + leaderboardType = Leaderboard.Type.Votes; + break; } for (int i = 0; i < 10; i++) { @@ -268,13 +289,22 @@ public class HologramManager { IslandLevel level = visit.getLevel(); hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); + } else if (hologramTypeList == HologramType.Bank) { + hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) + .replace("%balance", + "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance())))); } else if (hologramTypeList == HologramType.Votes) { hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) .replace("%votes", "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size())))); } diff --git a/src/main/java/me/goodandevil/skyblock/hologram/HologramType.java b/src/main/java/me/goodandevil/skyblock/hologram/HologramType.java index be7229d5..b2625aa7 100644 --- a/src/main/java/me/goodandevil/skyblock/hologram/HologramType.java +++ b/src/main/java/me/goodandevil/skyblock/hologram/HologramType.java @@ -2,6 +2,6 @@ package me.goodandevil.skyblock.hologram; public enum HologramType { - Level, Votes, Stackable; + Level, Bank, Votes, Stackable; } diff --git a/src/main/java/me/goodandevil/skyblock/island/Island.java b/src/main/java/me/goodandevil/skyblock/island/Island.java index a06ebd3d..69c73d5e 100644 --- a/src/main/java/me/goodandevil/skyblock/island/Island.java +++ b/src/main/java/me/goodandevil/skyblock/island/Island.java @@ -619,17 +619,23 @@ public class Island { } public void addToBank(double value) { - value = value + getBankBalance(); - skyblock.getFileManager().getConfig( - new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) - .getFileConfiguration().set("Bank.Balance", value); + FileManager fileManager = skyblock.getFileManager(); + + Config config = fileManager + .getConfig(new File(skyblock.getDataFolder().toString() + "/island-data", ownerUUID.toString() + ".yml")); + + value = getBankBalance() + value; + config.getFileConfiguration().set("Bank.Balance", value); + + try { + config.getFileConfiguration().save(config.getFile()); + } catch (IOException e) { + e.printStackTrace(); + } } public void removeFromBank(double value) { - value = getBankBalance() - value; - skyblock.getFileManager().getConfig( - new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) - .getFileConfiguration().set("Bank.Balance", value); + addToBank(-value); } public boolean isOpen() { diff --git a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java index a386a58c..51d934e8 100644 --- a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java +++ b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java @@ -165,6 +165,7 @@ public class IslandManager { island.getIslandLocation(IslandWorld.End, IslandEnvironment.Island)}, island.getSize(), island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, + island.getBankBalance(), visitManager.getIslandSafeLevel(island.getOwnerUUID()), island.getLevel(), island.getMessage(IslandMessage.Signature), island.isOpen()); } @@ -524,6 +525,7 @@ public class IslandManager { island.getIslandLocation(IslandWorld.End, IslandEnvironment.Island)}, island.getSize(), island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, + island.getBankBalance(), visitManager.getIslandSafeLevel(island.getOwnerUUID()), island.getLevel(), island.getMessage(IslandMessage.Signature), island.isOpen()); } diff --git a/src/main/java/me/goodandevil/skyblock/leaderboard/Leaderboard.java b/src/main/java/me/goodandevil/skyblock/leaderboard/Leaderboard.java index 7856eb83..077747e4 100644 --- a/src/main/java/me/goodandevil/skyblock/leaderboard/Leaderboard.java +++ b/src/main/java/me/goodandevil/skyblock/leaderboard/Leaderboard.java @@ -28,7 +28,7 @@ public class Leaderboard { public enum Type { - Level, Votes; + Level, Bank, Votes } } diff --git a/src/main/java/me/goodandevil/skyblock/leaderboard/LeaderboardManager.java b/src/main/java/me/goodandevil/skyblock/leaderboard/LeaderboardManager.java index 554890f7..9a3749c4 100644 --- a/src/main/java/me/goodandevil/skyblock/leaderboard/LeaderboardManager.java +++ b/src/main/java/me/goodandevil/skyblock/leaderboard/LeaderboardManager.java @@ -1,22 +1,20 @@ package me.goodandevil.skyblock.leaderboard; +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.leaderboard.leaderheads.TopBank; +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.Bukkit; +import org.bukkit.entity.Player; + import java.io.File; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.UUID; -import me.goodandevil.skyblock.island.Island; -import me.goodandevil.skyblock.island.IslandManager; -import org.bukkit.Bukkit; - -import me.goodandevil.skyblock.SkyBlock; -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 { private final SkyBlock skyblock; @@ -39,16 +37,19 @@ public class LeaderboardManager { visitManager.loadIslands(); List islandLevels = new ArrayList<>(); + List islandBanks = new ArrayList<>(); List islandVotes = new ArrayList<>(); for (int i = 0; i < visitManager.getIslands().size(); i++) { UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[i]; Visit visit = visitManager.getIslands().get(ownerUUID); islandLevels.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel())); + islandBanks.add(new LeaderboardPlayer(ownerUUID, (long)visit.getBankBalance())); islandVotes.add(new LeaderboardPlayer(ownerUUID, visit.getVoters().size())); } islandLevels.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed()); + islandBanks.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed()); islandVotes.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed()); for (int i = 0; i < 10; i++) { @@ -57,6 +58,11 @@ public class LeaderboardManager { leaderboardStorage.add(leaderboard); } + if (!islandBanks.isEmpty() && i < islandBanks.size()) { + Leaderboard leaderboard = new Leaderboard(Leaderboard.Type.Bank, visitManager.getIsland(islandBanks.get(i).getUUID()), i); + leaderboardStorage.add(leaderboard); + } + if (!islandLevels.isEmpty() && i < islandLevels.size()) { Leaderboard leaderboard = new Leaderboard(Leaderboard.Type.Level, visitManager.getIsland(islandLevels.get(i).getUUID()), i); leaderboardStorage.add(leaderboard); @@ -78,6 +84,12 @@ public class LeaderboardManager { leaderboardPlayers.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel())); } break; + case Bank: + 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, (long)visit.getBankBalance())); + } case Votes: for (int i = 0; i < visitManager.getIslands().size(); i++) { UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[i]; @@ -101,6 +113,7 @@ public class LeaderboardManager { public void setupLeaderHeads() { if (Bukkit.getServer().getPluginManager().getPlugin("LeaderHeads") != null) { new TopLevel(skyblock); + new TopBank(skyblock); new TopVotes(skyblock); } } diff --git a/src/main/java/me/goodandevil/skyblock/leaderboard/leaderheads/TopBank.java b/src/main/java/me/goodandevil/skyblock/leaderboard/leaderheads/TopBank.java new file mode 100644 index 00000000..123e28c4 --- /dev/null +++ b/src/main/java/me/goodandevil/skyblock/leaderboard/leaderheads/TopBank.java @@ -0,0 +1,47 @@ +package me.goodandevil.skyblock.leaderboard.leaderheads; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; + +import java.util.UUID; + +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.leaderboard.Leaderboard; +import me.goodandevil.skyblock.leaderboard.Leaderboard.Type; +import me.goodandevil.skyblock.visit.Visit; +import me.robin.leaderheads.api.LeaderHeadsAPI; +import me.robin.leaderheads.datacollectors.DataCollector; +import me.robin.leaderheads.objects.BoardType; + +public class TopBank extends DataCollector { + + private final SkyBlock skyblock; + + public TopBank(SkyBlock skyblock) { + super("topbank", skyblock.getDescription().getName(), BoardType.DEFAULT, "&bTop Bank", "topbank", + Arrays.asList(ChatColor.DARK_GRAY + "-=+=-", ChatColor.AQUA + "{name}", + ChatColor.WHITE + "Bal: ${amount}", ChatColor.DARK_GRAY + "-=+=-"), + true, UUID.class); + + this.skyblock = skyblock; + } + + @Override + public List> requestAll() { + Map topLevels = new HashMap<>(); + + List leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Bank); + + for (Leaderboard leaderboard : leaderboards) { + Visit visit = leaderboard.getVisit(); + topLevels.put(visit.getOwnerUUID(), visit.getBankBalance()); + } + + return LeaderHeadsAPI.sortMap(topLevels); + } +} diff --git a/src/main/java/me/goodandevil/skyblock/menus/Leaderboard.java b/src/main/java/me/goodandevil/skyblock/menus/Leaderboard.java index 8b865b74..e057c26e 100644 --- a/src/main/java/me/goodandevil/skyblock/menus/Leaderboard.java +++ b/src/main/java/me/goodandevil/skyblock/menus/Leaderboard.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import me.goodandevil.skyblock.utils.NumberUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -74,6 +75,14 @@ public class Leaderboard { + ".Item.Leaderboard.Displayname") .replace("%leaderboard", Viewer.Type.Level.name()))))) { playerDataManager.getPlayerData(player).setViewer(new Viewer(Viewer.Type.Level)); + } else if ((is.getType() == Material.GOLD_INGOT) && (is.hasItemMeta()) + && (is.getItemMeta().getDisplayName() + .equals(ChatColor.translateAlternateColorCodes('&', + configLoad + .getString("Menu.Leaderboard." + Viewer.Type.Browse.name() + + ".Item.Leaderboard.Displayname") + .replace("%leaderboard", Viewer.Type.Bank.name()))))) { + playerDataManager.getPlayerData(player).setViewer(new Viewer(Viewer.Type.Bank)); } else if ((is.getType() == Material.EMERALD) && (is.hasItemMeta()) && (is.getItemMeta().getDisplayName() .equals(ChatColor.translateAlternateColorCodes('&', @@ -109,6 +118,16 @@ public class Leaderboard { new Placeholder[] { new Placeholder("%leaderboard", Viewer.Type.Level.name()) }, null, null), 1); + nInv.addItem( + nInv.createItem(new ItemStack(Material.GOLD_INGOT), configLoad + .getString( + "Menu.Leaderboard." + viewer.getType().name() + ".Item.Leaderboard.Displayname") + .replace("%leaderboard", Viewer.Type.Bank.name()), + configLoad.getStringList( + "Menu.Leaderboard." + viewer.getType().name() + ".Item.Leaderboard.Lore"), + new Placeholder[] { new Placeholder("%leaderboard", Viewer.Type.Bank.name()) }, null, + null), + 2); nInv.addItem( nInv.createItem(new ItemStack(Material.EMERALD), configLoad .getString( @@ -304,6 +323,7 @@ public class Leaderboard { new Placeholder("%position", "" + (leaderboard.getPosition() + 1)), new Placeholder("%owner", playerName), new Placeholder("%level", "" + visit.getLevel().getLevel()), + new Placeholder("%balance", NumberUtil.formatNumberByDecimal(visit.getBankBalance())), new Placeholder("%votes", "" + visit.getVoters().size()), new Placeholder("%members", "" + visit.getMembers()) }, null, null), @@ -354,7 +374,7 @@ public class Leaderboard { public enum Type { - Browse, Level, Votes; + Browse, Level, Bank, Votes } } diff --git a/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java b/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java index e044cf17..3b58f247 100644 --- a/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java +++ b/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java @@ -55,6 +55,7 @@ public class EZPlaceholder extends PlaceholderExpansion implements Listener { FileConfiguration configLoad = config.getFileConfiguration(); List leaderboardLevelPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Level); + List leaderboardBankPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Bank); List leaderboardVotesPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Votes); if (identifier.equalsIgnoreCase("islands")) { @@ -82,7 +83,30 @@ public class EZPlaceholder extends PlaceholderExpansion implements Listener { } return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Empty.Message")); + configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Empty.Message")); + } else if (identifier.equalsIgnoreCase("leaderboard_bank_" + (i + 1))) { + if (i < leaderboardLevelPlayers.size()) { + Leaderboard leaderboard = leaderboardLevelPlayers.get(i); + Visit visit = leaderboard.getVisit(); + IslandLevel level = visit.getLevel(); + + Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); + String islandOwnerName; + + if (targetPlayer == null) { + islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); + } else { + islandOwnerName = targetPlayer.getName(); + } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Non-empty.Message") + .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) + .replace("%balance", NumberUtil.formatNumberByDecimal(level.getLevel()))); + } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Empty.Message")); } else if (identifier.equalsIgnoreCase("leaderboard_level_" + (i + 1))) { if (i < leaderboardLevelPlayers.size()) { Leaderboard leaderboard = leaderboardLevelPlayers.get(i); diff --git a/src/main/java/me/goodandevil/skyblock/placeholder/MVdWPlaceholder.java b/src/main/java/me/goodandevil/skyblock/placeholder/MVdWPlaceholder.java index b7f4d8aa..6dc9a2ed 100644 --- a/src/main/java/me/goodandevil/skyblock/placeholder/MVdWPlaceholder.java +++ b/src/main/java/me/goodandevil/skyblock/placeholder/MVdWPlaceholder.java @@ -37,94 +37,107 @@ public class MVdWPlaceholder { FileConfiguration configLoad = config.getFileConfiguration(); List leaderboardLevelPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Level); + List leaderboardBankPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Bank); List leaderboardVotesPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Votes); - PlaceholderAPI.registerPlaceholder(skyblock, "fabledskyblock_islands", new PlaceholderReplacer() { - @Override - public String onPlaceholderReplace(PlaceholderReplaceEvent event) { - return "" + skyblock.getVisitManager().getIslands().size(); - } - }); + PlaceholderAPI.registerPlaceholder(skyblock, "fabledskyblock_islands", event -> "" + skyblock.getVisitManager().getIslands().size()); for (int i = 0; i < 10; i++) { PlaceholderAPI.registerPlaceholder(skyblock, "fabledskyblock_leaderboard_votes_" + (i + 1), - new PlaceholderReplacer() { - @Override - public String onPlaceholderReplace(PlaceholderReplaceEvent event) { - int index = Integer - .valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_votes_", "")); + event -> { + int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_votes_", "")); - if (index < leaderboardVotesPlayers.size()) { - Leaderboard leaderboard = leaderboardVotesPlayers.get(index); - Visit visit = leaderboard.getVisit(); + if (index < leaderboardVotesPlayers.size()) { + Leaderboard leaderboard = leaderboardVotesPlayers.get(index); + Visit visit = leaderboard.getVisit(); - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; + Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); + String islandOwnerName; - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Non-empty.Message") - .replace("%position", "" + (index + 1)) - .replace("%player", islandOwnerName).replace("%votes", - NumberUtil.formatNumberByDecimal(visit.getVoters().size()))); + if (targetPlayer == null) { + islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); + } else { + islandOwnerName = targetPlayer.getName(); } return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Empty.Message")); + configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Non-empty.Message") + .replace("%position", "" + (index + 1)) + .replace("%player", islandOwnerName) + .replace("%votes", NumberUtil.formatNumberByDecimal(visit.getVoters().size()))); } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Empty.Message")); + }); + + PlaceholderAPI.registerPlaceholder(skyblock, "fabledskyblock_leaderboard_bank_" + (i + 1), + event -> { + int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_bank_", "")); + + if (index < leaderboardBankPlayers.size()) { + Leaderboard leaderboard = leaderboardBankPlayers.get(index); + Visit visit = leaderboard.getVisit(); + + Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); + String islandOwnerName; + + if (targetPlayer == null) { + islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); + } else { + islandOwnerName = targetPlayer.getName(); + } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Non-empty.Message") + .replace("%position", "" + (index + 1)) + .replace("%player", islandOwnerName) + .replace("%balance", NumberUtil.formatNumberByDecimal(visit.getBankBalance()))); + } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Empty.Message")); }); PlaceholderAPI.registerPlaceholder(skyblock, "fabledskyblock_leaderboard_level_" + (i + 1), - new PlaceholderReplacer() { - @Override - public String onPlaceholderReplace(PlaceholderReplaceEvent event) { - int index = Integer - .valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_level_", "")); + event -> { + int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_level_", "")); - if (index < leaderboardLevelPlayers.size()) { - Leaderboard leaderboard = leaderboardLevelPlayers.get(index); - Visit visit = leaderboard.getVisit(); - IslandLevel level = visit.getLevel(); + if (index < leaderboardLevelPlayers.size()) { + Leaderboard leaderboard = leaderboardLevelPlayers.get(index); + Visit visit = leaderboard.getVisit(); + IslandLevel level = visit.getLevel(); - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; + Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); + String islandOwnerName; - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', configLoad - .getString("Placeholder.fabledskyblock_leaderboard_level.Non-empty.Message") - .replace("%position", "" + (index + 1)).replace("%player", islandOwnerName) - .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints()))); + if (targetPlayer == null) { + islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); + } else { + islandOwnerName = targetPlayer.getName(); } - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_level.Empty.Message")); + return ChatColor.translateAlternateColorCodes('&', configLoad + .getString("Placeholder.fabledskyblock_leaderboard_level.Non-empty.Message") + .replace("%position", "" + (index + 1)).replace("%player", islandOwnerName) + .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) + .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints()))); } + + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_leaderboard_level.Empty.Message")); }); } for (String placeholderList : placeholderManager.getPlaceholders()) { - PlaceholderAPI.registerPlaceholder(skyblock, placeholderList, new PlaceholderReplacer() { - @Override - public String onPlaceholderReplace(PlaceholderReplaceEvent event) { - Player player = event.getPlayer(); + PlaceholderAPI.registerPlaceholder(skyblock, placeholderList, event -> { + Player player = event.getPlayer(); - if (player == null) { - return null; - } - - return placeholderManager.getPlaceholder(player, event.getPlaceholder()); + if (player == null) { + return null; } + + return placeholderManager.getPlaceholder(player, event.getPlaceholder()); }); } } diff --git a/src/main/java/me/goodandevil/skyblock/placeholder/PlaceholderManager.java b/src/main/java/me/goodandevil/skyblock/placeholder/PlaceholderManager.java index 06376c5c..6f45bbd3 100644 --- a/src/main/java/me/goodandevil/skyblock/placeholder/PlaceholderManager.java +++ b/src/main/java/me/goodandevil/skyblock/placeholder/PlaceholderManager.java @@ -318,6 +318,17 @@ public class PlaceholderManager { configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Non-empty.Message") .replace("%placeholder", "" + rank)); } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_bank_rank")) { + if (island == null) { + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Empty.Message")); + } else { + LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); + int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Bank); + return ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Non-empty.Message") + .replace("%placeholder", "" + rank)); + } } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_votes_rank")) { if (island == null) { return ChatColor.translateAlternateColorCodes('&', diff --git a/src/main/java/me/goodandevil/skyblock/visit/Visit.java b/src/main/java/me/goodandevil/skyblock/visit/Visit.java index f2e2e05d..ef5554ba 100644 --- a/src/main/java/me/goodandevil/skyblock/visit/Visit.java +++ b/src/main/java/me/goodandevil/skyblock/visit/Visit.java @@ -30,6 +30,7 @@ public class Visit { private int islandSize; private int islandMembers; private int safeLevel; + private double islandBankBalance; private final IslandLevel islandLevel; @@ -38,12 +39,13 @@ public class Visit { private boolean open; protected Visit(SkyBlock skyblock, UUID islandOwnerUUID, IslandLocation[] islandLocations, int islandSize, - int islandMembers, int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { + int islandMembers, double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { this.skyblock = skyblock; this.islandOwnerUUID = islandOwnerUUID; this.islandLocations = islandLocations; this.islandSize = islandSize; this.islandMembers = islandMembers; + this.islandBankBalance = islandBankBalance; this.safeLevel = safeLevel; this.islandLevel = islandLevel; this.islandSignature = islandSignature; @@ -103,6 +105,10 @@ public class Visit { this.islandSize = islandSize; } + public double getBankBalance() { + return this.islandBankBalance; + } + public IslandLevel getLevel() { return islandLevel; } diff --git a/src/main/java/me/goodandevil/skyblock/visit/VisitManager.java b/src/main/java/me/goodandevil/skyblock/visit/VisitManager.java index b97ffc3c..a8a9e926 100644 --- a/src/main/java/me/goodandevil/skyblock/visit/VisitManager.java +++ b/src/main/java/me/goodandevil/skyblock/visit/VisitManager.java @@ -56,63 +56,56 @@ public class VisitManager { if (!configFile.exists()) return; - for (File fileList : configFile.listFiles()) { - if (fileList != null && fileList.getName().contains(".yml") && fileList.getName().length() > 35) { - try { - Config config = new FileManager.Config(fileManager, fileList); - FileConfiguration configLoad = config.getFileConfiguration(); + for (File fileList : configFile.listFiles()) { + if (fileList != null && fileList.getName().contains(".yml") && fileList.getName().length() > 35) { + try { + Config config = new FileManager.Config(fileManager, fileList); + FileConfiguration configLoad = config.getFileConfiguration(); - UUID islandOwnerUUID = UUID.fromString(fileList.getName().replace(".yml", "")); + UUID islandOwnerUUID = UUID.fromString(fileList.getName().replace(".yml", "")); - if (islandOwnerUUID == null) { - islandOwnerUUID = UUID.fromString(fileList.getName().replaceFirst("[.][^.]+$", "")); + if (islandOwnerUUID == null) { + islandOwnerUUID = UUID.fromString(fileList.getName().replaceFirst("[.][^.]+$", "")); - if (islandOwnerUUID == null) { - continue; - } - } + if (islandOwnerUUID == null) { + continue; + } + } - List islandSignature = new ArrayList<>(); + List islandSignature = new ArrayList<>(); - if (configLoad.getString("Visitor.Signature.Message") != null) { - islandSignature = configLoad.getStringList("Visitor.Signature.Message"); - } + if (configLoad.getString("Visitor.Signature.Message") != null) { + islandSignature = configLoad.getStringList("Visitor.Signature.Message"); + } - int division = skyblock.getFileManager() - .getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() - .getInt("Island.Levelling.Division"); + int size = 100; - if (division == 0) { - division = 1; - } + if (configLoad.getString("Size") != null) { + size = configLoad.getInt("Size"); + } - int size = 100; - - if (configLoad.getString("Size") != null) { - size = configLoad.getInt("Size"); - } - - createIsland(islandOwnerUUID, - new IslandLocation[] { - new IslandLocation(IslandWorld.Normal, null, - worldManager.getLocation(fileManager.getLocation(config, - "Location.Normal.Island", true), IslandWorld.Normal)), - new IslandLocation(IslandWorld.Nether, null, - worldManager.getLocation(fileManager.getLocation(config, - "Location.Nether.Island", true), IslandWorld.Nether)), - new IslandLocation(IslandWorld.End, null, - worldManager.getLocation(fileManager.getLocation(config, - "Location.Nether.Island", true), IslandWorld.End)) }, - size, - configLoad.getStringList("Members").size() - + configLoad.getStringList("Operators").size() + 1, - getIslandSafeLevel(islandOwnerUUID), new IslandLevel(islandOwnerUUID, skyblock), - islandSignature, configLoad.getBoolean("Visitor.Open")); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + createIsland(islandOwnerUUID, + new IslandLocation[] { + new IslandLocation(IslandWorld.Normal, null, + worldManager.getLocation(fileManager.getLocation(config, + "Location.Normal.Island", true), IslandWorld.Normal)), + new IslandLocation(IslandWorld.Nether, null, + worldManager.getLocation(fileManager.getLocation(config, + "Location.Nether.Island", true), IslandWorld.Nether)), + new IslandLocation(IslandWorld.End, null, + worldManager.getLocation(fileManager.getLocation(config, + "Location.Nether.Island", true), IslandWorld.End)) }, + size, + configLoad.getStringList("Members").size() + + configLoad.getStringList("Operators").size() + 1, + configLoad.getDouble("Bank.Balance", 0), + getIslandSafeLevel(islandOwnerUUID), new IslandLevel(islandOwnerUUID, skyblock), + islandSignature, configLoad.getBoolean("Visitor.Open")); + } catch (Exception e) { + e.printStackTrace(); + } + } + } } } @@ -218,9 +211,9 @@ public class VisitManager { } public void createIsland(UUID islandOwnerUUID, IslandLocation[] islandLocations, int islandSize, int islandMembers, - int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { + double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { visitStorage.put(islandOwnerUUID, new Visit(skyblock, islandOwnerUUID, islandLocations, islandSize, - islandMembers, safeLevel, islandLevel, islandSignature, open)); + islandMembers, islandBankBalance, safeLevel, islandLevel, islandSignature, open)); } public void addIsland(UUID islandOwnerUUID, Visit visit) { diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 405b0fb4..8d2a3d07 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -88,7 +88,7 @@ Command: Info: Message: "&f&oOpens the Leaderboard menu of the top 10 Islands." Invalid: - Message: "&bSkyBlock &8| &cError&8: &eInvalid: /island leaderboard []" + Message: "&bSkyBlock &8| &cError&8: &eInvalid: /island leaderboard []" Disabled: Message: "&bSkyBlock &8| &cError&8: &eYou cannot view that leaderboard because that leaderboard is disabled." Create: @@ -1104,6 +1104,11 @@ Placeholder: Message: "&f&oUnclaimed" Non-empty: Message: "&f[%position] %player [%level]" + fabledskyblock_leaderboard_bank: + Empty: + Message: "&f&oUnclaimed" + Non-empty: + Message: "&f[%position] %player [$%balance]" fabledskyblock_leaderboard_votes: Empty: Message: "&f&oUnclaimed" @@ -1229,6 +1234,11 @@ Placeholder: Message: "&c0" Non-empty: Message: "&f%placeholder" + fabledskyblock_island_leaderboard_bank_rank: + Empty: + Message: "&c0" + Non-empty: + Message: "&f%placeholder" fabledskyblock_island_leaderboard_votes_rank: Empty: Message: "&c0" @@ -1260,6 +1270,11 @@ Hologram: Claimed: "&8* &f&o[%position] &a%player &7- &6%level" Unclaimed: "&8* &f&o[%position] &7&oUnclaimed Position" Footer: "&ewww.example.net" + Bank: + Header: "&b&lSkyBlock &8&l| &e&lTop 10 Bank Balances" + Claimed: "&8* &f&o[%position] &a%player &7- &6$%balance" + Unclaimed: "&8* &f&o[%position] &7&oUnclaimed Position" + Footer: "&ewww.example.net" Votes: Header: "&b&lSkyBlock &8&l| &e&lTop 10 Votes" Claimed: "&8* &f&o[%position] &a%player &7- &6%votes" @@ -1707,6 +1722,14 @@ Menu: - "" - "&7Signature&8:" - "%signature" + Bank: + Lore: + - "&7Owner&8: &f%owner" + - "&7Balance&8: &f$%balance" + - "&7Members&8: &f%members" + - "" + - "&7Signature&8:" + - "%signature" Votes: Lore: - "&7Owner&8: &f%owner"