From fb107038cad5462dce984930b28dbfdce610c3ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Jul 2024 10:15:08 -0700 Subject: [PATCH] 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"