From 368c7af0efb2294563f1e72ce7e01511ca78bc63 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Wed, 6 Mar 2024 11:15:47 -0500 Subject: [PATCH 1/4] added more placeholders - modified the fetch for online and offline members to run a single stream to create both lists - added ``island_visitors`` and ``island_visitors_amount`` placeholders to get the list of player names visiting an island and the amount of current visitors to said island - added ``island_booster`` and ``island_upgrade`` placeholders, to get whether they're active, the level of the enhancement, and the time remaining --- .../IslandPlaceholderBuilder.java | 80 ++++++++++++++++--- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java index 84b8f423a..ec879964f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java +++ b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java @@ -9,14 +9,16 @@ import com.iridium.iridiumteams.Rank; import com.iridium.iridiumteams.TemporaryCache; import com.iridium.iridiumteams.bank.BankItem; +import com.iridium.iridiumteams.database.TeamEnhancement; +import com.iridium.iridiumteams.enhancements.Enhancement; +import com.iridium.iridiumteams.enhancements.EnhancementType; +import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import java.time.Duration; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; public class IslandPlaceholderBuilder implements PlaceholderBuilder { @@ -28,14 +30,15 @@ public class IslandPlaceholderBuilder implements PlaceholderBuilder { public List getPlaceholders(Island island) { return cache.get(island, Duration.ofSeconds(1), () -> { List users = IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island); - List onlineUsers = users.stream() - .filter(u -> u.getPlayer() != null) - .map(User::getName) - .collect(Collectors.toList()); - List offlineUsers = users.stream() - .filter(u -> u.getPlayer() == null) - .map(User::getName) - .collect(Collectors.toList()); + + List onlineUsers = new ArrayList<>(Collections.emptyList()); + List offlineUsers = new ArrayList<>(Collections.emptyList()); + + for(User user : users) { + if(user.getPlayer() != null) + onlineUsers.add(user.getName()); + offlineUsers.add(user.getName()); + } List placeholderList = new ArrayList<>(Arrays.asList( new Placeholder("island_name", island.getName()), @@ -57,6 +60,35 @@ public List getPlaceholders(Island island) { new Placeholder("island_members_offline_count", String.valueOf(offlineUsers.size())), new Placeholder("island_members_count", String.valueOf(users.size())) )); + + List visitingPlayers = Bukkit.getOnlinePlayers().stream() + .map(Player::getPlayer) + .filter(player -> island.isInIsland(player.getLocation())) + .collect(Collectors.toList()); + + placeholderList.add(new Placeholder("island_visitors", visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")))); + placeholderList.add(new Placeholder("island_visitors_amount", String.valueOf(visitingPlayers.size()))); + + for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { + TeamEnhancement teamEnhancement = IridiumSkyblock.getInstance().getIslandManager().getTeamEnhancement(island, enhancement.getKey()); + + if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.BOOSTER) { + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", String.valueOf(teamEnhancement.isActive()))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", String.valueOf(teamEnhancement.getLevel()))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); + } + + if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.UPGRADE) { + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", String.valueOf(teamEnhancement.isActive()))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", String.valueOf(teamEnhancement.getLevel()))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); + } + } + for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island, bankItem.getName()).getNumber()))); } @@ -71,6 +103,7 @@ public List getPlaceholders(Island island) { } private List initializeDefaultPlaceholders() { + List placeholderList = new ArrayList<>(Arrays.asList( new Placeholder("island_name", "N/A"), new Placeholder("island_owner", "N/A"), @@ -85,8 +118,29 @@ private List initializeDefaultPlaceholders() { new Placeholder("island_members_online_count", "N/A"), new Placeholder("island_members_offline", "N/A"), new Placeholder("island_members_offline_count", "N/A"), - new Placeholder("island_members_count", "N/A") + new Placeholder("island_members_count", "N/A"), + new Placeholder("island_visitors", "N/A"), + new Placeholder("island_visitors_amount", "N/A") )); + + for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { + if(enhancement.getValue().type == EnhancementType.BOOSTER) { + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", "N/A")); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", "N/A")); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", "N/A")); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", "N/A")); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", "N/A")); + } + + if(enhancement.getValue().type == EnhancementType.UPGRADE) { + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", "N/A")); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", "N/A")); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", "N/A")); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", "N/A")); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", "N/A")); + } + } + for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), "N/A")); } From bd2609b04df1ea486ab2b4c591c3022d880d111b Mon Sep 17 00:00:00 2001 From: Shyanne Date: Thu, 7 Mar 2024 01:49:27 -0500 Subject: [PATCH 2/4] applied supplier - also removed members from the list of visitors --- .../IslandPlaceholderBuilder.java | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java index ec879964f..4d263cc22 100644 --- a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java +++ b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java @@ -35,30 +35,29 @@ public List getPlaceholders(Island island) { List offlineUsers = new ArrayList<>(Collections.emptyList()); for(User user : users) { - if(user.getPlayer() != null) - onlineUsers.add(user.getName()); + if(user.getPlayer() != null) onlineUsers.add(user.getName()); offlineUsers.add(user.getName()); } List placeholderList = new ArrayList<>(Arrays.asList( - new Placeholder("island_name", island.getName()), - new Placeholder("island_owner", IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island).stream() + new Placeholder("island_name", () -> island.getName()), + new Placeholder("island_owner", () -> IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island).stream() .filter(user -> user.getUserRank() == Rank.OWNER.getId()) .findFirst() .map(User::getName) .orElse("N/A")), - new Placeholder("island_create", island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))), - new Placeholder("island_description", island.getDescription()), - new Placeholder("island_value", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamValue(island))), - new Placeholder("island_level", String.valueOf(island.getLevel())), - new Placeholder("island_experience", String.valueOf(island.getExperience())), - new Placeholder("island_value_rank", String.valueOf(IridiumSkyblock.getInstance().getTop().valueTeamSort.getRank(island, IridiumSkyblock.getInstance()))), - new Placeholder("island_experience_rank", String.valueOf(IridiumSkyblock.getInstance().getTop().experienceTeamSort.getRank(island, IridiumSkyblock.getInstance()))), - new Placeholder("island_members_online", String.join(", ", onlineUsers)), - new Placeholder("island_members_online_count", String.valueOf(onlineUsers.size())), - new Placeholder("island_members_offline", String.join(", ", offlineUsers)), - new Placeholder("island_members_offline_count", String.valueOf(offlineUsers.size())), - new Placeholder("island_members_count", String.valueOf(users.size())) + new Placeholder("island_create", () -> island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))), + new Placeholder("island_description", () -> island.getDescription()), + new Placeholder("island_value", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamValue(island))), + new Placeholder("island_level", () -> String.valueOf(island.getLevel())), + new Placeholder("island_experience", () -> String.valueOf(island.getExperience())), + new Placeholder("island_value_rank", () -> String.valueOf(IridiumSkyblock.getInstance().getTop().valueTeamSort.getRank(island, IridiumSkyblock.getInstance()))), + new Placeholder("island_experience_rank", () -> String.valueOf(IridiumSkyblock.getInstance().getTop().experienceTeamSort.getRank(island, IridiumSkyblock.getInstance()))), + new Placeholder("island_members_online", () -> String.join(", ", onlineUsers)), + new Placeholder("island_members_online_count", () -> String.valueOf(onlineUsers.size())), + new Placeholder("island_members_offline", () -> String.join(", ", offlineUsers)), + new Placeholder("island_members_offline_count", () -> String.valueOf(offlineUsers.size())), + new Placeholder("island_members_count", () -> String.valueOf(users.size())) )); List visitingPlayers = Bukkit.getOnlinePlayers().stream() @@ -66,37 +65,42 @@ public List getPlaceholders(Island island) { .filter(player -> island.isInIsland(player.getLocation())) .collect(Collectors.toList()); - placeholderList.add(new Placeholder("island_visitors", visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")))); - placeholderList.add(new Placeholder("island_visitors_amount", String.valueOf(visitingPlayers.size()))); + visitingPlayers.removeIf(player -> onlineUsers.contains(player.getName())); + + placeholderList.add(new Placeholder("island_visitors", () -> visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")))); + placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size()))); + + placeholderList.add(new Placeholder("island_visitors", () -> visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")))); + placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size()))); for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { TeamEnhancement teamEnhancement = IridiumSkyblock.getInstance().getIslandManager().getTeamEnhancement(island, enhancement.getKey()); if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.BOOSTER) { - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", String.valueOf(teamEnhancement.isActive()))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", String.valueOf(teamEnhancement.getLevel()))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel()))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); } if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.UPGRADE) { - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", String.valueOf(teamEnhancement.isActive()))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", String.valueOf(teamEnhancement.getLevel()))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel()))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); } } for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { - placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island, bankItem.getName()).getNumber()))); + placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island, bankItem.getName()).getNumber()))); } for (XMaterial xMaterial : XMaterial.values()) { - placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBlock(island, xMaterial).getAmount()))); + placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBlock(island, xMaterial).getAmount()))); } for (EntityType entityType : EntityType.values()) { - placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamSpawners(island, entityType).getAmount()))); + placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamSpawners(island, entityType).getAmount()))); } return placeholderList; }); From 1159cbbcdad137c1bd19dd67920503a1e9780b55 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Sat, 16 Mar 2024 10:23:52 -0400 Subject: [PATCH 3/4] Merged enhancement placeholders - fixed an error in loop logic --- .../IslandPlaceholderBuilder.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java index 4d263cc22..dc375931f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java +++ b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java @@ -36,7 +36,7 @@ public List getPlaceholders(Island island) { for(User user : users) { if(user.getPlayer() != null) onlineUsers.add(user.getName()); - offlineUsers.add(user.getName()); + else offlineUsers.add(user.getName()); } List placeholderList = new ArrayList<>(Arrays.asList( @@ -74,23 +74,14 @@ public List getPlaceholders(Island island) { placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size()))); for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { + if(!enhancement.getValue().enabled) continue; TeamEnhancement teamEnhancement = IridiumSkyblock.getInstance().getIslandManager().getTeamEnhancement(island, enhancement.getKey()); - if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.BOOSTER) { - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel()))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); - } - - if(enhancement.getValue().enabled && enhancement.getValue().type == EnhancementType.UPGRADE) { - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel()))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); - } + placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); + placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel()))); + placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0)))); + placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0)))); + placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0)))); } for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { From 40e148ec57c456adbb3e56071e235b1cad4026e7 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Fri, 10 May 2024 19:49:33 +0100 Subject: [PATCH 4/4] Formatting and nullPlaceholder --- .../IslandPlaceholderBuilder.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java index dc375931f..3e5e8f997 100644 --- a/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java +++ b/src/main/java/com/iridium/iridiumskyblock/placeholders/IslandPlaceholderBuilder.java @@ -34,20 +34,23 @@ public List getPlaceholders(Island island) { List onlineUsers = new ArrayList<>(Collections.emptyList()); List offlineUsers = new ArrayList<>(Collections.emptyList()); - for(User user : users) { - if(user.getPlayer() != null) onlineUsers.add(user.getName()); - else offlineUsers.add(user.getName()); + for (User user : users) { + if (user.getPlayer() != null) { + onlineUsers.add(user.getName()); + } else { + offlineUsers.add(user.getName()); + } } List placeholderList = new ArrayList<>(Arrays.asList( - new Placeholder("island_name", () -> island.getName()), + new Placeholder("island_name", island::getName), new Placeholder("island_owner", () -> IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island).stream() .filter(user -> user.getUserRank() == Rank.OWNER.getId()) .findFirst() .map(User::getName) - .orElse("N/A")), + .orElse(IridiumSkyblock.getInstance().getMessages().nullPlaceholder)), new Placeholder("island_create", () -> island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))), - new Placeholder("island_description", () -> island.getDescription()), + new Placeholder("island_description", island::getDescription), new Placeholder("island_value", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamValue(island))), new Placeholder("island_level", () -> String.valueOf(island.getLevel())), new Placeholder("island_experience", () -> String.valueOf(island.getExperience())), @@ -62,6 +65,7 @@ public List getPlaceholders(Island island) { List visitingPlayers = Bukkit.getOnlinePlayers().stream() .map(Player::getPlayer) + .filter(Objects::nonNull) .filter(player -> island.isInIsland(player.getLocation())) .collect(Collectors.toList()); @@ -73,8 +77,8 @@ public List getPlaceholders(Island island) { placeholderList.add(new Placeholder("island_visitors", () -> visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")))); placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size()))); - for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { - if(!enhancement.getValue().enabled) continue; + for (Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { + if (!enhancement.getValue().enabled) continue; TeamEnhancement teamEnhancement = IridiumSkyblock.getInstance().getIslandManager().getTeamEnhancement(island, enhancement.getKey()); placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive()))); @@ -100,50 +104,50 @@ public List getPlaceholders(Island island) { private List initializeDefaultPlaceholders() { List placeholderList = new ArrayList<>(Arrays.asList( - new Placeholder("island_name", "N/A"), - new Placeholder("island_owner", "N/A"), - new Placeholder("island_description", "N/A"), - new Placeholder("island_create", "N/A"), - new Placeholder("island_value", "N/A"), - new Placeholder("island_level", "N/A"), - new Placeholder("island_experience", "N/A"), - new Placeholder("island_value_rank", "N/A"), - new Placeholder("island_experience_rank", "N/A"), - new Placeholder("island_members_online", "N/A"), - new Placeholder("island_members_online_count", "N/A"), - new Placeholder("island_members_offline", "N/A"), - new Placeholder("island_members_offline_count", "N/A"), - new Placeholder("island_members_count", "N/A"), - new Placeholder("island_visitors", "N/A"), - new Placeholder("island_visitors_amount", "N/A") + new Placeholder("island_name", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_owner", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_description", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_create", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_value", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_experience", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_value_rank", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_experience_rank", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_members_online", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_members_online_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_members_offline", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_members_offline_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_members_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_visitors", IridiumSkyblock.getInstance().getMessages().nullPlaceholder), + new Placeholder("island_visitors_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder) )); - for(Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { - if(enhancement.getValue().type == EnhancementType.BOOSTER) { - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", "N/A")); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", "N/A")); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", "N/A")); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", "N/A")); - placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", "N/A")); + for (Map.Entry> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) { + if (enhancement.getValue().type == EnhancementType.BOOSTER) { + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); } - if(enhancement.getValue().type == EnhancementType.UPGRADE) { - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", "N/A")); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", "N/A")); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", "N/A")); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", "N/A")); - placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", "N/A")); + if (enhancement.getValue().type == EnhancementType.UPGRADE) { + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); + placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); } } for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { - placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), "N/A")); + placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); } for (XMaterial xMaterial : XMaterial.values()) { - placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", "N/A")); + placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); } for (EntityType entityType : EntityType.values()) { - placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", "N/A")); + placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)); } return placeholderList; }