From a42d5c90a1904e060a771b8d8f90d43f4225b456 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Jul 2024 08:40:09 -0700 Subject: [PATCH 1/4] Version 2.15.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 11d21ff..14c6740 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ -LOCAL - 2.14.1 + 2.15.0 BentoBoxWorld_Level bentobox-world https://sonarcloud.io From 92a45608791dcd1e1e5a503ff2d2c25059808a6e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Jul 2024 08:40:30 -0700 Subject: [PATCH 2/4] Add placeholder that only gives level value for the owner #311 --- .../world/bentobox/level/LevelsManager.java | 19 +- .../bentobox/level/PlaceholderManager.java | 231 +++++++++--------- 2 files changed, 135 insertions(+), 115 deletions(-) diff --git a/src/main/java/world/bentobox/level/LevelsManager.java b/src/main/java/world/bentobox/level/LevelsManager.java index 46d47b3..7e6163e 100644 --- a/src/main/java/world/bentobox/level/LevelsManager.java +++ b/src/main/java/world/bentobox/level/LevelsManager.java @@ -216,15 +216,32 @@ public class LevelsManager { * * @param world - world where the island is * @param targetPlayer - target player UUID + * @param ownerOnly - return level only if the target player is the owner * @return Level of the player's island or zero if player is unknown or UUID is * null */ public long getIslandLevel(@NonNull World world, @Nullable UUID targetPlayer) { + return getIslandLevel(world, targetPlayer, false); + } + + /** + * Get level of island from cache for a player. + * + * @param world - world where the island is + * @param targetPlayer - target player UUID + * @param ownerOnly - return level only if the target player is the owner + * @return Level of the player's island or zero if player is unknown or UUID is + * null + */ + public long getIslandLevel(@NonNull World world, @Nullable UUID targetPlayer, boolean ownerOnly) { if (targetPlayer == null) return 0L; // Get the island Island island = addon.getIslands().getIsland(world, targetPlayer); - return island == null ? 0L : getLevelsData(island).getLevel(); + if (island == null || island.getOwner() == null || (ownerOnly && !island.getOwner().equals(targetPlayer))) { + return 0L; + } + return getLevelsData(island).getLevel(); } /** diff --git a/src/main/java/world/bentobox/level/PlaceholderManager.java b/src/main/java/world/bentobox/level/PlaceholderManager.java index 5f0bd17..886a1be 100644 --- a/src/main/java/world/bentobox/level/PlaceholderManager.java +++ b/src/main/java/world/bentobox/level/PlaceholderManager.java @@ -30,69 +30,72 @@ public class PlaceholderManager { private final BentoBox plugin; public PlaceholderManager(Level addon) { - this.addon = addon; - this.plugin = addon.getPlugin(); + this.addon = addon; + this.plugin = addon.getPlugin(); } protected void registerPlaceholders(GameModeAddon gm) { - if (plugin.getPlaceholdersManager() == null) - return; - PlaceholdersManager bpm = plugin.getPlaceholdersManager(); - // Island Level - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level", - user -> addon.getManager().getIslandLevelString(gm.getOverWorld(), user.getUniqueId())); - // Unformatted island level - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_raw", - user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId()))); - // Total number of points counted before applying level formula - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_total_points", user -> { - IslandLevels data = addon.getManager().getLevelsData(addon.getIslands().getIsland(gm.getOverWorld(), user)); - return data.getTotalPoints() + ""; - }); - // Points to the next level for player - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_points_to_next_level", - user -> addon.getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId())); - // Maximum level this island has ever been. Current level maybe lower. - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_max", - user -> String.valueOf(addon.getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId()))); + if (plugin.getPlaceholdersManager() == null) + return; + PlaceholdersManager bpm = plugin.getPlaceholdersManager(); + // Island Level + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level", + user -> addon.getManager().getIslandLevelString(gm.getOverWorld(), user.getUniqueId())); + // Island Level owner only + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_owner", + user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId(), true))); + // Unformatted island level + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_raw", + user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId()))); + // Total number of points counted before applying level formula + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_total_points", user -> { + IslandLevels data = addon.getManager().getLevelsData(addon.getIslands().getIsland(gm.getOverWorld(), user)); + return data.getTotalPoints() + ""; + }); + // Points to the next level for player + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_points_to_next_level", + user -> addon.getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId())); + // Maximum level this island has ever been. Current level maybe lower. + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_max", + user -> String.valueOf(addon.getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId()))); - // Visited Island Level - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_visited_island_level", - user -> getVisitedIslandLevel(gm, user)); + // Visited Island Level + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_visited_island_level", + user -> getVisitedIslandLevel(gm, user)); - // Register Top Ten Placeholders - for (int i = 1; i < 11; i++) { - final int rank = i; - // Name - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_name_" + i, - u -> getRankName(gm.getOverWorld(), rank, false)); - // Island Name - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i, - u -> getRankIslandName(gm.getOverWorld(), rank, false)); - // Members - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_members_" + i, - u -> getRankMembers(gm.getOverWorld(), rank, false)); - // Level - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_value_" + i, - u -> getRankLevel(gm.getOverWorld(), rank, false)); - // Weighted Level Name (Level / number of members) - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_name_" + i, - u -> getRankName(gm.getOverWorld(), rank, true)); - // Weighted Island Name - bpm.registerPlaceholder(addon, - gm.getDescription().getName().toLowerCase() + "_top_weighted_island_name_" + i, - u -> getRankIslandName(gm.getOverWorld(), rank, true)); - // Weighted Members - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_members_" + i, - u -> getRankMembers(gm.getOverWorld(), rank, true)); - // Weighted Level (Level / number of members) - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_value_" + i, - u -> getRankLevel(gm.getOverWorld(), rank, true)); - } + // Register Top Ten Placeholders + for (int i = 1; i < 11; i++) { + final int rank = i; + // Name + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_name_" + i, + u -> getRankName(gm.getOverWorld(), rank, false)); + // Island Name + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i, + u -> getRankIslandName(gm.getOverWorld(), rank, false)); + // Members + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_members_" + i, + u -> getRankMembers(gm.getOverWorld(), rank, false)); + // Level + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_value_" + i, + u -> getRankLevel(gm.getOverWorld(), rank, false)); + // Weighted Level Name (Level / number of members) + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_name_" + i, + u -> getRankName(gm.getOverWorld(), rank, true)); + // Weighted Island Name + bpm.registerPlaceholder(addon, + gm.getDescription().getName().toLowerCase() + "_top_weighted_island_name_" + i, + u -> getRankIslandName(gm.getOverWorld(), rank, true)); + // Weighted Members + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_members_" + i, + u -> getRankMembers(gm.getOverWorld(), rank, true)); + // Weighted Level (Level / number of members) + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_value_" + i, + u -> getRankLevel(gm.getOverWorld(), rank, true)); + } - // Personal rank - bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_rank_value", - u -> getRankValue(gm.getOverWorld(), u)); + // Personal rank + bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_rank_value", + u -> getRankValue(gm.getOverWorld(), u)); } /** @@ -104,17 +107,17 @@ public class PlaceholderManager { * @return rank name */ String getRankName(World world, int rank, boolean weighted) { - // Ensure rank is within bounds - rank = Math.max(1, Math.min(rank, Level.TEN)); - if (weighted) { - return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) - .findFirst().map(Island::getOwner).map(addon.getPlayers()::getName).orElse(""); - } - @Nullable - UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) - .findFirst().flatMap(addon.getIslands()::getIslandById).map(Island::getOwner).orElse(null); + // Ensure rank is within bounds + rank = Math.max(1, Math.min(rank, Level.TEN)); + if (weighted) { + return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) + .findFirst().map(Island::getOwner).map(addon.getPlayers()::getName).orElse(""); + } + @Nullable + UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) + .findFirst().flatMap(addon.getIslands()::getIslandById).map(Island::getOwner).orElse(null); - return addon.getPlayers().getName(owner); + return addon.getPlayers().getName(owner); } /** @@ -126,14 +129,14 @@ public class PlaceholderManager { * @return name of island or nothing if there isn't one */ String getRankIslandName(World world, int rank, boolean weighted) { - // Ensure rank is within bounds - rank = Math.max(1, Math.min(rank, Level.TEN)); - if (weighted) { - return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) - .findFirst().map(Island::getName).orElse(""); - } - return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst() - .flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse(""); + // Ensure rank is within bounds + rank = Math.max(1, Math.min(rank, Level.TEN)); + if (weighted) { + return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) + .findFirst().map(Island::getName).orElse(""); + } + return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst() + .flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse(""); } /** @@ -145,27 +148,27 @@ public class PlaceholderManager { * @return comma separated string of island member names */ String getRankMembers(World world, int rank, boolean weighted) { - // Ensure rank is within bounds - rank = Math.max(1, Math.min(rank, Level.TEN)); - if (weighted) { - return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) - .findFirst() - .map(is -> is.getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK) - .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey) - .map(addon.getPlayers()::getName).collect(Collectors.joining(","))) - .orElse(""); - } + // Ensure rank is within bounds + rank = Math.max(1, Math.min(rank, Level.TEN)); + if (weighted) { + return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L) + .findFirst() + .map(is -> is.getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK) + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey) + .map(addon.getPlayers()::getName).collect(Collectors.joining(","))) + .orElse(""); + } - Optional island = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L) - .limit(1L).findFirst().flatMap(addon.getIslands()::getIslandById); + Optional island = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L) + .limit(1L).findFirst().flatMap(addon.getIslands()::getIslandById); - if (island.isPresent()) { - // Sort members by rank - return island.get().getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK) - .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey) - .map(addon.getPlayers()::getName).collect(Collectors.joining(",")); - } - return ""; + if (island.isPresent()) { + // Sort members by rank + return island.get().getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK) + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey) + .map(addon.getPlayers()::getName).collect(Collectors.joining(",")); + } + return ""; } /** @@ -177,14 +180,14 @@ public class PlaceholderManager { * @return level for the rank requested */ String getRankLevel(World world, int rank, boolean weighted) { - // Ensure rank is within bounds - rank = Math.max(1, Math.min(rank, Level.TEN)); - if (weighted) { - return addon.getManager().formatLevel(addon.getManager().getWeightedTopTen(world, Level.TEN).values() - .stream().skip(rank - 1L).limit(1L).findFirst().orElse(null)); - } - return addon.getManager().formatLevel(addon.getManager().getTopTen(world, Level.TEN).values().stream() - .skip(rank - 1L).limit(1L).findFirst().orElse(null)); + // Ensure rank is within bounds + rank = Math.max(1, Math.min(rank, Level.TEN)); + if (weighted) { + return addon.getManager().formatLevel(addon.getManager().getWeightedTopTen(world, Level.TEN).values() + .stream().skip(rank - 1L).limit(1L).findFirst().orElse(null)); + } + return addon.getManager().formatLevel(addon.getManager().getTopTen(world, Level.TEN).values().stream() + .skip(rank - 1L).limit(1L).findFirst().orElse(null)); } /** @@ -195,21 +198,21 @@ public class PlaceholderManager { * @return rank where 1 is the top rank. */ private String getRankValue(World world, User user) { - if (user == null) { - return ""; - } - // Get the island level for this user - long level = addon.getManager().getIslandLevel(world, user.getUniqueId()); - return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen() - .values().stream().filter(l -> l > level).count() + 1); + if (user == null) { + return ""; + } + // Get the island level for this user + long level = addon.getManager().getIslandLevel(world, user.getUniqueId()); + return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen() + .values().stream().filter(l -> l > level).count() + 1); } String getVisitedIslandLevel(GameModeAddon gm, User user) { - if (user == null || !gm.inWorld(user.getWorld())) - return ""; - return addon.getIslands().getIslandAt(user.getLocation()) - .map(island -> addon.getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner())) - .orElse("0"); + if (user == null || !gm.inWorld(user.getWorld())) + return ""; + return addon.getIslands().getIslandAt(user.getLocation()) + .map(island -> addon.getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner())) + .orElse("0"); } } From 8255073706aaba270f90f316a346790244c9a574 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Jul 2024 09:23:09 -0700 Subject: [PATCH 3/4] Makes the default block tab show blocks with value only #302 --- .../bentobox/level/panels/DetailsPanel.java | 34 ++++++++++++++++--- src/main/resources/locales/en-US.yml | 5 +++ src/main/resources/panels/detail_panel.yml | 28 +++++++++++++-- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/main/java/world/bentobox/level/panels/DetailsPanel.java b/src/main/java/world/bentobox/level/panels/DetailsPanel.java index fad4988..222174d 100644 --- a/src/main/java/world/bentobox/level/panels/DetailsPanel.java +++ b/src/main/java/world/bentobox/level/panels/DetailsPanel.java @@ -59,7 +59,7 @@ public class DetailsPanel { } // By default no-filters are active. - this.activeTab = Tab.ALL_BLOCKS; + this.activeTab = Tab.VALUE_BLOCKS; this.activeFilter = Filter.NAME; this.materialCountList = new ArrayList<>(Material.values().length); @@ -111,6 +111,28 @@ public class DetailsPanel { this.materialCountList.clear(); switch (this.activeTab) { + case VALUE_BLOCKS -> { + Map materialCountMap = new EnumMap<>(Material.class); + + materialCountMap.putAll(this.levelsData.getMdCount()); + + // Add underwater blocks. + this.levelsData.getUwCount().forEach((material, count) -> materialCountMap.put(material, + materialCountMap.computeIfAbsent(material, key -> 0) + count)); + + // Remove zero value blocks + materialCountMap.entrySet().removeIf(en -> { + Integer value = this.addon.getBlockConfig().getValue(world, en.getKey()); + return value == null || value == 0; + }); + + materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).forEachOrdered(entry -> { + if (entry.getValue() > 0) { + this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())); + } + }); + + } case ALL_BLOCKS -> { Map materialCountMap = new EnumMap<>(Material.class); @@ -220,7 +242,7 @@ public class DetailsPanel { builder.description(this.user.getTranslation(this.world, template.description())); } - Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.ALL_BLOCKS); + Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.VALUE_BLOCKS); // Get only possible actions, by removing all inactive ones. List activeActions = new ArrayList<>(template.actions()); @@ -605,8 +627,12 @@ public class DetailsPanel { */ ALL_BLOCKS, /** - * Above Sea level Tab. - */ + * Blocks that have value + */ + VALUE_BLOCKS, + /** + * Above Sea level Tab. + */ ABOVE_SEA_LEVEL, /** * Underwater Tab. diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index b389a69..3d2b1bf 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -112,6 +112,11 @@ level: limit: "&7 Block limit: &e [number]" count: "&7 Number of blocks: &e [number]" calculated: "&7 Calculated value: &e [number]" + value_blocks: + name: "&f&l All Blocks With Value" + description: |- + &7 Display all blocks + &7 with value on island. all_blocks: name: "&f&l All Blocks" description: |- diff --git a/src/main/resources/panels/detail_panel.yml b/src/main/resources/panels/detail_panel.yml index 74fb90e..5a33da6 100644 --- a/src/main/resources/panels/detail_panel.yml +++ b/src/main/resources/panels/detail_panel.yml @@ -24,6 +24,28 @@ detail_panel: 1: # Column number 2: + # Icon is a Bukkit Material. + icon: ICE + # Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file + title: level.gui.buttons.value_blocks.name + # Description of the button shown to the user in the lore. This is a reference and the reference will be translatable in the locale file + description: level.gui.buttons.value_blocks.description + # The data section is a key-value list of data relavent for this button. It is interpreted by the code implemented the panel. + # The convention is to specify the type and the panel tab that will open if pressed. These are Enums in the code. + data: + # Type button will go to the ALL_BLOCKS tab when clicked. + type: TAB + tab: VALUE_BLOCKS + # Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different + # click-types. + actions: + # Each action has an arbitrary descriptive name to define it. + view: + # The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default. + click-type: unknown + # tooltip is a locale reference that will be translated for the user and shown when they hover over the button. + tooltip: level.gui.tips.click-to-view + 3: # Icon is a Bukkit Material. icon: STONE # Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file @@ -45,7 +67,7 @@ detail_panel: click-type: unknown # tooltip is a locale reference that will be translated for the user and shown when they hover over the button. tooltip: level.gui.tips.click-to-view - 3: + 4: icon: GRASS_BLOCK title: level.gui.buttons.above_sea_level.name description: level.gui.buttons.above_sea_level.description @@ -56,7 +78,7 @@ detail_panel: view: click-type: unknown tooltip: level.gui.tips.click-to-view - 4: + 5: icon: WATER_BUCKET title: level.gui.buttons.underwater.name description: level.gui.buttons.underwater.description @@ -67,7 +89,7 @@ detail_panel: view: click-type: unknown tooltip: level.gui.tips.click-to-view - 5: + 6: icon: SPAWNER title: level.gui.buttons.spawner.name description: level.gui.buttons.spawner.description From fb107038cad5462dce984930b28dbfdce610c3ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Jul 2024 10:15:08 -0700 Subject: [PATCH 4/4] Adds the number placed and limit to the value hand command #273 --- .../level/commands/IslandValueCommand.java | 16 ++++++++++++++++ .../bentobox/level/objects/IslandLevels.java | 6 +++++- src/main/resources/locales/en-US.yml | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/level/commands/IslandValueCommand.java b/src/main/java/world/bentobox/level/commands/IslandValueCommand.java index e6de8e4..82f49b4 100644 --- a/src/main/java/world/bentobox/level/commands/IslandValueCommand.java +++ b/src/main/java/world/bentobox/level/commands/IslandValueCommand.java @@ -8,11 +8,14 @@ import java.util.Optional; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.PlayerInventory; +import org.eclipse.jdt.annotation.NonNull; import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; import world.bentobox.level.Level; +import world.bentobox.level.objects.IslandLevels; import world.bentobox.level.panels.ValuePanel; import world.bentobox.level.util.Utils; @@ -112,6 +115,19 @@ public class IslandValueCommand extends CompositeCommand "[value]", (underWater * value) + ""), MATERIAL, Utils.prettifyObject(material, user)); } + + // Show how many have been placed and how many are allowed + @NonNull + IslandLevels lvData = this.addon.getManager() + .getLevelsData(getIslands().getPrimaryIsland(getWorld(), user.getUniqueId())); + int count = lvData.getMdCount().getOrDefault(material, 0) + lvData.getUwCount().getOrDefault(material, 0); + user.sendMessage("level.conversations.you-have", TextVariables.NUMBER, + String.valueOf(count)); + int limit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(material, -1); + if (limit > 0) { + user.sendMessage("level.conversations.you-can-place", TextVariables.NUMBER, + String.valueOf(limit)); + } } else { diff --git a/src/main/java/world/bentobox/level/objects/IslandLevels.java b/src/main/java/world/bentobox/level/objects/IslandLevels.java index 816376d..15e2a1e 100644 --- a/src/main/java/world/bentobox/level/objects/IslandLevels.java +++ b/src/main/java/world/bentobox/level/objects/IslandLevels.java @@ -62,7 +62,7 @@ public class IslandLevels implements DataObject { private Map uwCount; /** - * MaterialData count - count of all blocks + * MaterialData count - count of all blocks excluding under water */ @Expose private Map mdCount; @@ -162,6 +162,7 @@ public class IslandLevels implements DataObject { } /** + * The count of underwater blocks * @return the uwCount */ public Map getUwCount() { @@ -169,6 +170,7 @@ public class IslandLevels implements DataObject { } /** + * Underwater blocks * @param uwCount the uwCount to set */ public void setUwCount(Map uwCount) { @@ -176,6 +178,7 @@ public class IslandLevels implements DataObject { } /** + * All blocks count except for underwater blocks * @return the mdCount */ public Map getMdCount() { @@ -183,6 +186,7 @@ public class IslandLevels implements DataObject { } /** + * All blocks except for underwater blocks * @param mdCount the mdCount to set */ public void setMdCount(Map mdCount) { diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 3d2b1bf..e5e90f5 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -216,3 +216,7 @@ level: value-underwater: "&7 The value of '[material]' below sea-level: &e[value]" # Message that is sent to user when he does not hold any items in hand. empty-hand: "&c There are no blocks in your hand" + # Message when showing how many have been placed of a block + you-have: "&7 You have [number] at last count." + # Message about the limit + you-can-place: "&7 You can place up to [number] and have them count"