diff --git a/src/main/java/world/bentobox/level/commands/IslandDonateCommand.java b/src/main/java/world/bentobox/level/commands/IslandDonateCommand.java index 80af368..2a432d6 100644 --- a/src/main/java/world/bentobox/level/commands/IslandDonateCommand.java +++ b/src/main/java/world/bentobox/level/commands/IslandDonateCommand.java @@ -151,6 +151,23 @@ private void performHandDonation(User user, Island island, Material material, St return; } int amount = Math.min(requested, currentHand.getAmount()); + + // Apply blockconfig donation limit + String donationId = customId != null ? customId : material.name(); + Object blockObj = customId != null ? (Object) customId : material; + Object displayKey = customId != null ? customId : material; + Integer limit = addon.getBlockConfig().getLimit(blockObj); + if (limit != null) { + int currentDonated = addon.getManager().getDonatedBlocks(island).getOrDefault(donationId, 0); + int remaining = Math.max(0, limit - currentDonated); + if (remaining == 0) { + user.sendMessage("island.donate.limit-reached", + MATERIAL_PLACEHOLDER, Utils.prettifyObject(displayKey, user)); + return; + } + amount = Math.min(amount, remaining); + } + long points = (long) amount * blockValue; if (amount >= currentHand.getAmount()) { @@ -159,11 +176,9 @@ private void performHandDonation(User user, Island island, Material material, St currentHand.setAmount(currentHand.getAmount() - amount); } - String donationId = customId != null ? customId : material.name(); addon.getManager().donateBlocks(island, user.getUniqueId(), donationId, amount, points); addon.getManager().recalculateAfterDonation(island); - Object displayKey = customId != null ? customId : material; user.sendMessage("island.donate.hand.success", TextVariables.NUMBER, String.valueOf(amount), MATERIAL_PLACEHOLDER, Utils.prettifyObject(displayKey, user), @@ -223,14 +238,35 @@ private void performInvDonation(User user, Island island) { if (value == null) { continue; } - int amount = item.getAmount(); - long points = (long) value * amount; String customId = addon.getCustomBlockId(item); String donationId = customId != null ? customId : item.getType().name(); + Object blockObj = customId != null ? (Object) customId : item.getType(); + + // Apply blockconfig donation limit: only take up to the remaining capacity + int amount = item.getAmount(); + Integer limit = addon.getBlockConfig().getLimit(blockObj); + if (limit != null) { + // getDonatedBlocks returns the live cached map, already updated by earlier donateBlocks calls + int alreadyDonated = addon.getManager().getDonatedBlocks(island).getOrDefault(donationId, 0); + int remaining = Math.max(0, limit - alreadyDonated); + if (remaining == 0) { + // Limit already reached for this material — leave item in inventory + continue; + } + amount = Math.min(amount, remaining); + } + + // Remove accepted amount from inventory slot + if (amount >= item.getAmount()) { + contents[i] = null; + } else { + item.setAmount(item.getAmount() - amount); + } + + long points = (long) value * amount; donated.merge(donationId, amount, Integer::sum); totalPoints += points; addon.getManager().donateBlocks(island, user.getUniqueId(), donationId, amount, points); - contents[i] = null; } pInv.setStorageContents(contents); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index e18ba4a..9103c64 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -67,6 +67,7 @@ island: gui-title: "Donate Blocks" gui-info: "Donate blocks to your island|Currently donated: [points] points|Warning: donated items are|destroyed and cannot be returned!" preview: "Points to add: [points]|These items will be destroyed!" + limit-reached: "The donation limit for [material] has been reached." hand: keyword: "hand" success: "Donated [number] x [material] for [points] permanent points!"