Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import world.bentobox.level.Level;
import world.bentobox.level.calculators.Results.Result;
import world.bentobox.level.config.BlockConfig;
import world.bentobox.level.util.Utils;

public class IslandLevelCalculator {
private final UUID calcId = UUID.randomUUID(); // ID for hashing
Expand Down Expand Up @@ -305,10 +306,15 @@ private List<String> getReport() {
donatedBlocks.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
.forEach(entry -> {
Integer value = Objects.requireNonNullElse(addon.getBlockConfig().getValue(island.getWorld(), entry.getKey().toLowerCase(java.util.Locale.ENGLISH)), 0);
long totalValue = (long) value * entry.getValue();
String key = entry.getKey().toLowerCase(java.util.Locale.ENGLISH);
Integer value = Objects.requireNonNullElse(addon.getBlockConfig().getValue(island.getWorld(), key), 0);
// Cap at the current blockconfig limit so the lines sum to the donated total
Integer limit = addon.getBlockConfig().getLimit(key);
int counted = limit == null ? entry.getValue() : Math.min(entry.getValue(), limit);
long totalValue = (long) value * counted;
reportLines.add(" " + Util.prettifyText(entry.getKey()) + " x "
+ String.format("%,d", entry.getValue())
+ (counted < entry.getValue() ? " (capped at " + String.format("%,d", counted) + ")" : "")
+ " = " + String.format("%,d", totalValue) + " points");
});
reportLines.add(LINE_BREAK);
Expand Down Expand Up @@ -735,19 +741,8 @@ public void tidyUp() {
// level always reflects the current configuration, even if block values changed since donation.
// Also apply the current block limit: if the limit was lowered after donation, only count
// up to the current limit (donated blocks over the limit are silently ignored).
Map<String, Integer> donatedBlocksMap = addon.getManager().getDonatedBlocks(island);
long donatedPoints = donatedBlocksMap.entrySet().stream()
.mapToLong(entry -> {
String key = entry.getKey().toLowerCase(java.util.Locale.ENGLISH);
Integer value = addon.getBlockConfig().getValue(island.getWorld(), key);
int count = entry.getValue();
Integer limit = addon.getBlockConfig().getLimit(key);
if (limit != null) {
count = Math.min(count, limit);
}
return (long) Objects.requireNonNullElse(value, 0) * count;
})
.sum();
long donatedPoints = Utils.calculateDonatedPoints(addon.getBlockConfig(), island.getWorld(),
addon.getManager().getDonatedBlocks(island));
results.rawBlockCount.addAndGet(donatedPoints);
results.donatedPoints.set(donatedPoints);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ private boolean handleInvDonation(User user, Island island) {
MATERIAL_PLACEHOLDER, Utils.prettifyObject(displayKey, user),
POINTS_PLACEHOLDER, Utils.formatNumber(user, points)));
}
if (totalPoints == 0 && limited) {
// Everything offered is already at its donation limit — nothing to confirm
user.sendMessage("island.donate.limit-reached-all");
return false;
}
if (limited) {
// The limit-notice locale uses '|' as a lore line-break for the GUI;
// translate to '\n' here so the chat confirmation prompt wraps cleanly.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/world/bentobox/level/config/BlockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public BlockConfig(Level addon, YamlConfiguration blockValuesConfig, File file)
for (String key : limits.getKeys(false)) {
// Convert old materials to namespaced keys
key = convertKey(limits, key);
blockLimits.put(key, limits.getInt(key));
// Store lowercased so lookups are case-insensitive, matching blockValues
blockLimits.put(key.toLowerCase(Locale.ENGLISH), limits.getInt(key));
}
}
// The blocks section can include blocks, spawners, and namespacedIDs
Expand Down Expand Up @@ -199,7 +200,7 @@ public Integer getLimit(Object obj) {
return blockLimits.get(et.name().toLowerCase(Locale.ENGLISH).concat(SPAWNER));
}
if (obj instanceof String s) {
return blockLimits.get(s);
return blockLimits.get(s.toLowerCase(Locale.ENGLISH));
}

return null;
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/world/bentobox/level/panels/DonationPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ private DonationPanel(Level addon, World world, User user, Island island) {
// Place decorative items from the template (non-button, non-border entries)
layout.decorativeItems.forEach(inventory::setItem);

// Info pane
long currentDonated = addon.getManager().getDonatedPoints(island);
// Info pane — show the effective donated points (current values, limits applied),
// the same figure tidyUp() adds to the level, not the stored donation-time total.
long currentDonated = Utils.calculateDonatedPoints(addon.getBlockConfig(), world,
addon.getManager().getDonatedBlocks(island));
ItemStack info = createNamedItem(layout.infoMaterial,
user.getTranslation("island.donate.gui-info",
POINTS_PLACEHOLDER, Utils.formatNumber(user, currentDonated)));
Expand Down Expand Up @@ -148,6 +150,7 @@ private DonationTotals computeDonationTotals() {
DonationTotals result = new DonationTotals();
Map<String, Integer> rawTotals = new HashMap<>();
Map<String, Integer> values = new HashMap<>();
Map<String, Object> blockObjs = new HashMap<>();
for (int slot : layout.donationSlots) {
ItemStack item = inventory.getItem(slot);
if (item == null || item.getType().isAir()) continue;
Expand All @@ -158,14 +161,13 @@ private DonationTotals computeDonationTotals() {
if (value == null || value <= 0) continue;
rawTotals.merge(donationId, item.getAmount(), Integer::sum);
values.putIfAbsent(donationId, value);
blockObjs.putIfAbsent(donationId, blockObj);
}
Map<String, Integer> donated = addon.getManager().getDonatedBlocks(island);
for (Map.Entry<String, Integer> e : rawTotals.entrySet()) {
String donationId = e.getKey();
int total = e.getValue();
Object blockObj = donationId.contains(":") ? donationId : Material.matchMaterial(donationId);
if (blockObj == null) blockObj = donationId;
Integer limit = addon.getBlockConfig().getLimit(blockObj);
Integer limit = addon.getBlockConfig().getLimit(blockObjs.get(donationId));
int accept = total;
if (limit != null) {
int already = donated.getOrDefault(donationId, 0);
Expand Down Expand Up @@ -367,8 +369,10 @@ private void handleCancel(InventoryClickEvent event, Player player) {

private void handleConfirm(InventoryClickEvent event, Player player) {
event.setCancelled(true);
if (computeDonationTotals().acceptedPoints <= 0) {
user.sendMessage("island.donate.empty");
DonationTotals totals = computeDonationTotals();
if (totals.acceptedPoints <= 0) {
// Distinguish "nothing offered" from "everything offered is at its limit"
user.sendMessage(totals.limited ? "island.donate.limit-reached-all" : "island.donate.empty");
return;
}
confirmed = true;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/world/bentobox/level/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
Expand All @@ -25,6 +29,7 @@
import world.bentobox.bentobox.hooks.LangUtilsHook;
import world.bentobox.bentobox.hooks.OraxenHook;
import world.bentobox.level.Level;
import world.bentobox.level.config.BlockConfig;


public class Utils
Expand All @@ -39,6 +44,33 @@ public static String formatNumber(User user, long value) {
return NumberFormat.getInstance(user.getLocale()).format(value);
}

/**
* Calculate the effective point value of a donated-blocks map using current block config
* values (world-specific where set) and capping each block type at its current blockconfig
* limit. This is the single source of truth for how donated blocks contribute to the level;
* the level calculation and any display of the donated total must use it so they agree.
*
* @param blockConfig the block config to read values and limits from
* @param world the world whose value overrides apply
* @param donatedBlocks map of donation id (Material name or custom block id) to count
* @return total donated points after value lookup and limit capping
*/
public static long calculateDonatedPoints(BlockConfig blockConfig, World world,
Map<String, Integer> donatedBlocks) {
return donatedBlocks.entrySet().stream()
.mapToLong(entry -> {
String key = entry.getKey().toLowerCase(Locale.ENGLISH);
Integer value = blockConfig.getValue(world, key);
int count = entry.getValue();
Integer limit = blockConfig.getLimit(key);
if (limit != null) {
count = Math.min(count, limit);
}
return (long) Objects.requireNonNullElse(value, 0) * count;
})
.sum();
}

/**
* This method sends a message to the user with appended "prefix" text before message.
* @param user User who receives message.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Limit darování pro [material] byl dosažen."
limit-reached-all: "<red>Všechny tyto bloky dosáhly svých limitů darování."
limit-notice: "<gold>Některé bloky podléhají limitům|<gold>a nebudou darovány"
hand:
keyword: "ruka"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Das Spendenlimit für [material] wurde erreicht."
limit-reached-all: "<red>Alle diese Blöcke haben ihre Spendenlimits erreicht."
limit-notice: "<gold>Einige Blöcke unterliegen Limits|<gold>und werden nicht gespendet"
hand:
keyword: "hand"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>The donation limit for [material] has been reached."
limit-reached-all: "<red>All of these blocks have reached their donation limits."
limit-notice: "<gold>Some blocks are subject to limits|<gold>and will not be donated"
hand:
keyword: "hand"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Se ha alcanzado el límite de donación para [material]."
limit-reached-all: "<red>Todos estos bloques han alcanzado sus límites de donación."
limit-notice: "<gold>Algunos bloques están sujetos a límites|<gold>y no serán donados"
hand:
keyword: "mano"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>La limite de don pour [material] a été atteinte."
limit-reached-all: "<red>Tous ces blocs ont atteint leur limite de don."
limit-notice: "<gold>Certains blocs sont soumis à des limites|<gold>et ne seront pas donnés"
hand:
keyword: "main"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>A(z) [material] adományozási limitje elérve."
limit-reached-all: "<red>Ezek a blokkok mind elérték az adományozási limitjüket."
limit-notice: "<gold>Néhány blokkra korlátozás vonatkozik|<gold>és nem lesznek adományozva"
hand:
keyword: "kez"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Batas donasi untuk [material] telah tercapai."
limit-reached-all: "<red>Semua blok ini telah mencapai batas donasinya."
limit-notice: "<gold>Beberapa blok memiliki batasan|<gold>dan tidak akan didonasikan"
hand:
keyword: "tangan"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>[material]의 기부 한도에 도달했습니다."
limit-reached-all: "<red>이 블록들은 모두 기부 한도에 도달했습니다."
limit-notice: "<gold>일부 블록에는 제한이 있으며|<gold>기부되지 않습니다"
hand:
keyword: "hand"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>[material] ziedošanas limits ir sasniegts."
limit-reached-all: "<red>Visi šie bloki ir sasnieguši savus ziedošanas limitus."
limit-notice: "<gold>Dažiem blokiem ir ierobežojumi|<gold>un tie netiks ziedoti"
hand:
keyword: "roka"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>De donatielimiet voor [material] is bereikt."
limit-reached-all: "<red>Al deze blokken hebben hun donatielimiet bereikt."
limit-notice: "<gold>Sommige blokken zijn onderworpen aan limieten|<gold>en worden niet gedoneerd"
hand:
keyword: "hand"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Limit darowizn dla [material] został osiągnięty."
limit-reached-all: "<red>Wszystkie te bloki osiągnęły swoje limity darowizn."
limit-notice: "<gold>Niektóre bloki podlegają limitom|<gold>i nie zostaną przekazane"
hand:
keyword: "reka"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>O limite de doação para [material] foi atingido."
limit-reached-all: "<red>Todos estes blocos atingiram os seus limites de doação."
limit-notice: "<gold>Alguns blocos estão sujeitos a limites|<gold>e não serão doados"
hand:
keyword: "mao"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Лимит пожертвования для [material] достигнут."
limit-reached-all: "<red>Все эти блоки достигли своих лимитов пожертвования."
limit-notice: "<gold>Некоторые блоки подлежат ограничениям|<gold>и не будут пожертвованы"
hand:
keyword: "рука"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>[material] için bağış limitine ulaşıldı."
limit-reached-all: "<red>Bu blokların tümü bağış limitlerine ulaştı."
limit-notice: "<gold>Bazı bloklar limitlere tabidir|<gold>ve bağışlanmayacaktır"
hand:
keyword: "el"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ island:
gui-info: "<gold>Пожертвуйте блоки своєму острову|<gray>Пожертвовано: <gold>[points]<gray> очок|<red>Увага: пожертвувані предмети|<red>знищуються і не можуть бути повернуті!"
preview: "<yellow>Очок буде додано: <gold>[points]|<red>Ці предмети будуть знищені!"
limit-reached: "<red>Ліміт пожертвування для [material] досягнуто."
limit-reached-all: "<red>Усі ці блоки досягли своїх лімітів пожертвування."
limit-notice: "<gold>Деякі блоки підлягають обмеженням|<gold>і не будуть пожертвувані"
hand:
keyword: "рука"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/vi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ island:
gui-info: "<gold>Donate blocks to your island|<gray>Currently donated: <gold>[points]<gray> points|<red>Warning: donated items are|<red>destroyed and cannot be returned!"
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
limit-reached: "<red>Đã đạt đến giới hạn quyên góp cho [material]."
limit-reached-all: "<red>Tất cả các khối này đã đạt đến giới hạn quyên góp."
limit-notice: "<gold>Một số khối có giới hạn|<gold>và sẽ không được quyên góp"
hand:
keyword: "tay"
Expand Down
Loading
Loading