Skip to content

Commit 4ae01bb

Browse files
tastybentoclaude
andcommitted
Confirm hand donations and localize point totals
Require a re-run confirmation before /island donate hand destroys items, fix tab completion to offer "hand" and the held stack size, route "help" through the standard help handler, and format [points] placeholders via the player's locale so large totals render with thousands separators. Sync the new confirm-prompt key plus spacing and typo fixes across every locale file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f0fc85d commit 4ae01bb

21 files changed

Lines changed: 131 additions & 81 deletions

File tree

src/main/java/world/bentobox/level/commands/IslandDonateCommand.java

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package world.bentobox.level.commands;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54
import java.util.Optional;
65

76
import org.bukkit.Material;
87
import org.bukkit.inventory.ItemStack;
98

109
import world.bentobox.bentobox.api.commands.CompositeCommand;
10+
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
1111
import world.bentobox.bentobox.api.localization.TextVariables;
1212
import world.bentobox.bentobox.api.user.User;
1313
import world.bentobox.bentobox.database.objects.Island;
14+
import world.bentobox.bentobox.util.Util;
1415
import world.bentobox.level.Level;
1516
import world.bentobox.level.panels.DonationPanel;
1617
import world.bentobox.level.util.Utils;
@@ -21,7 +22,7 @@
2122
*
2223
* @author tastybento
2324
*/
24-
public class IslandDonateCommand extends CompositeCommand {
25+
public class IslandDonateCommand extends ConfirmableCommand {
2526

2627
private final Level addon;
2728

@@ -79,56 +80,79 @@ private boolean handleHandDonation(User user, Island island, List<String> args)
7980
return false;
8081
}
8182

82-
Material material = hand.getType();
83-
Integer blockValue = addon.getBlockConfig().getValue(getWorld(), material);
83+
final Material material = hand.getType();
84+
final Integer blockValue = addon.getBlockConfig().getValue(getWorld(), material);
8485
if (blockValue == null || blockValue <= 0) {
8586
user.sendMessage("island.donate.no-value");
8687
return false;
8788
}
8889

89-
// Determine amount
90-
int amount = hand.getAmount();
90+
int requested = hand.getAmount();
9191
if (args.size() > 1) {
92+
if ("help".equalsIgnoreCase(args.get(1))) {
93+
showHelp(this, user);
94+
return true;
95+
}
9296
try {
93-
amount = Integer.parseInt(args.get(1));
94-
if (amount < 1) {
97+
requested = Integer.parseInt(args.get(1));
98+
if (requested < 1) {
9599
user.sendMessage("island.donate.invalid-amount");
96100
return false;
97101
}
98-
amount = Math.min(amount, hand.getAmount());
99102
} catch (NumberFormatException e) {
100103
user.sendMessage("island.donate.invalid-amount");
101104
return false;
102105
}
103106
}
104107

105-
// Calculate points
108+
final int previewAmount = Math.min(requested, hand.getAmount());
109+
final long previewPoints = (long) previewAmount * blockValue;
110+
final int finalRequested = requested;
111+
112+
String prompt = user.getTranslation("island.donate.hand.confirm-prompt",
113+
TextVariables.NUMBER, String.valueOf(previewAmount),
114+
"[material]", Utils.prettifyObject(material, user),
115+
"[points]", Utils.formatNumber(user, previewPoints));
116+
117+
askConfirmation(user, prompt, () -> performHandDonation(user, island, material, blockValue, finalRequested));
118+
return true;
119+
}
120+
121+
private void performHandDonation(User user, Island island, Material material, int blockValue, int requested) {
122+
ItemStack currentHand = user.getPlayer().getInventory().getItemInMainHand();
123+
if (currentHand.getType() != material || currentHand.getAmount() == 0) {
124+
user.sendMessage("island.donate.hand.not-block");
125+
return;
126+
}
127+
int amount = Math.min(requested, currentHand.getAmount());
106128
long points = (long) amount * blockValue;
107129

108-
// Remove items from hand
109-
if (amount >= hand.getAmount()) {
130+
if (amount >= currentHand.getAmount()) {
110131
user.getPlayer().getInventory().setItemInMainHand(null);
111132
} else {
112-
hand.setAmount(hand.getAmount() - amount);
133+
currentHand.setAmount(currentHand.getAmount() - amount);
113134
}
114135

115-
// Record the donation
116136
addon.getManager().donateBlocks(island, user.getUniqueId(), material.name(), amount, points);
117137

118-
// Notify the player
119138
user.sendMessage("island.donate.hand.success",
120139
TextVariables.NUMBER, String.valueOf(amount),
121140
"[material]", Utils.prettifyObject(material, user),
122-
"[points]", String.valueOf(points));
123-
124-
return true;
141+
"[points]", Utils.formatNumber(user, points));
125142
}
126143

127144
@Override
128145
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
129-
if (args.size() == 1) {
130-
return Optional.of(List.of("hand"));
146+
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : "";
147+
if (args.size() <= 2) {
148+
return Optional.of(Util.tabLimit(List.of("hand"), lastArg));
149+
}
150+
if (args.size() == 3 && "hand".equalsIgnoreCase(args.get(1)) && user.isPlayer()) {
151+
int held = user.getPlayer().getInventory().getItemInMainHand().getAmount();
152+
if (held > 0) {
153+
return Optional.of(Util.tabLimit(List.of(String.valueOf(held)), lastArg));
154+
}
131155
}
132-
return Optional.of(new ArrayList<>());
156+
return Optional.of(List.of());
133157
}
134158
}

src/main/java/world/bentobox/level/commands/IslandLevelCommand.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import world.bentobox.level.Level;
1212
import world.bentobox.level.calculators.Results;
1313
import world.bentobox.level.calculators.Results.Result;
14+
import world.bentobox.level.util.Utils;
1415

1516
public class IslandLevelCommand extends CompositeCommand {
1617

@@ -112,9 +113,9 @@ private void showResult(User user, UUID playerUUID, Island island, long oldLevel
112113
// Send player how many points are required to reach next island level
113114
if (results.getPointsToNextLevel() >= 0) {
114115
user.sendMessage("island.level.required-points-to-next-level",
115-
"[points]", String.valueOf(results.getPointsToNextLevel()),
116-
"[progress]", String.valueOf(this.addon.getSettings().getLevelCost()-results.getPointsToNextLevel()),
117-
"[levelcost]", String.valueOf(this.addon.getSettings().getLevelCost())
116+
"[points]", Utils.formatNumber(user, results.getPointsToNextLevel()),
117+
"[progress]", Utils.formatNumber(user, this.addon.getSettings().getLevelCost() - results.getPointsToNextLevel()),
118+
"[levelcost]", Utils.formatNumber(user, this.addon.getSettings().getLevelCost())
118119
);
119120
}
120121
// Tell other team members

src/main/java/world/bentobox/level/panels/DonationPanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private DonationPanel(Level addon, World world, User user, Island island) {
8787
long currentDonated = addon.getManager().getDonatedPoints(island);
8888
ItemStack info = createNamedItem(Material.BOOK,
8989
user.getTranslation("island.donate.gui-info",
90-
"[points]", String.valueOf(currentDonated)));
90+
"[points]", Utils.formatNumber(user, currentDonated)));
9191
inventory.setItem(INFO_SLOT, info);
9292

9393
// Cancel button
@@ -135,7 +135,7 @@ private void updatePreview() {
135135
long points = calculateDonationValue();
136136
ItemStack preview = createNamedItem(Material.EXPERIENCE_BOTTLE,
137137
user.getTranslation("island.donate.preview",
138-
"[points]", String.valueOf(points)));
138+
"[points]", Utils.formatNumber(user, points)));
139139
inventory.setItem(PREVIEW_SLOT, preview);
140140
}
141141

@@ -178,7 +178,7 @@ private void processDonation() {
178178
user.sendMessage("island.donate.empty");
179179
} else {
180180
user.sendMessage("island.donate.success",
181-
"[points]", String.valueOf(totalPoints),
181+
"[points]", Utils.formatNumber(user, totalPoints),
182182
TextVariables.NUMBER, String.valueOf(donations.values().stream().mapToInt(Integer::intValue).sum()));
183183
}
184184
}

src/main/java/world/bentobox/level/util/Utils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package world.bentobox.level.util;
88

99

10+
import java.text.NumberFormat;
1011
import java.util.List;
1112

1213
import org.bukkit.Material;
@@ -22,6 +23,13 @@ public class Utils
2223

2324
private Utils() {} // Private constructor as this is a utility class only with static methods
2425

26+
/**
27+
* Formats a number using the user's locale (e.g. 10500 → "10,500" in en-US, "10.500" in de).
28+
*/
29+
public static String formatNumber(User user, long value) {
30+
return NumberFormat.getInstance(user.getLocale()).format(value);
31+
}
32+
2533
/**
2634
* This method sends a message to the user with appended "prefix" text before message.
2735
* @param user User who receives message.

src/main/resources/locales/cs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ island:
5555
invalid-amount: "<red>Invalid amount. Use a positive number."
5656
empty: "<red>There are no valid blocks to donate."
5757
cancelled: "<yellow>Donation cancelled. Items returned."
58-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
58+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
5959
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
6060
cancel: "<green><bold>Cancel - Return Items"
6161
gui-title: "<black><bold>Donate Blocks"
62-
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!"
62+
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!"
6363
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6464
hand:
65-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
65+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
6666
not-block: "<red>You must be holding a placeable block to donate."
67+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
6768
detail:
6869
description: "zobrazit podrobnosti o blocích vašeho ostrova"
6970
top:
@@ -183,7 +184,7 @@ level:
183184
[id]
184185
id: '<gray> Block id: <yellow> [id]'
185186
value: '<gray> Hodnota bloku: <yellow> [number]'
186-
underwater: '<gray> Hladina moře Bellow: <yellow> [number]'
187+
underwater: '<gray> Hladina moře Below: <yellow> [number]'
187188
limit: '<gray> Limit bloku: <yellow> [number]'
188189
previous:
189190
name: Předchozí stránka

src/main/resources/locales/de.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ island:
5656
invalid-amount: "<red>Invalid amount. Use a positive number."
5757
empty: "<red>There are no valid blocks to donate."
5858
cancelled: "<yellow>Donation cancelled. Items returned."
59-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
59+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
6060
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
6161
cancel: "<green><bold>Cancel - Return Items"
6262
gui-title: "<black><bold>Donate Blocks"
63-
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!"
63+
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!"
6464
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6565
hand:
66-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
66+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
6767
not-block: "<red>You must be holding a placeable block to donate."
68+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
6869
detail:
6970
description: "zeigt Details der Blöcke deiner Insel"
7071
top:

src/main/resources/locales/en-US.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ island:
6060
invalid-amount: "<red>Invalid amount. Use a positive number."
6161
empty: "<red>There are no valid blocks to donate."
6262
cancelled: "<yellow>Donation cancelled. Items returned."
63-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
63+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
6464
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
6565
cancel: "<green><bold>Cancel - Return Items"
6666
gui-title: "<black><bold>Donate Blocks"
67-
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!"
67+
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!"
6868
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6969
hand:
70-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
70+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
7171
not-block: "<red>You must be holding a placeable block to donate."
72+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
7273
detail:
7374
description: "shows detail of your island blocks"
7475
top:
@@ -164,7 +165,7 @@ level:
164165
name: "<white><bold>Blocks Under Sea level"
165166
description: |-
166167
<gray>Display only blocks
167-
<gray>that are bellow sea
168+
<gray>that are below sea
168169
<gray>level.
169170
spawner:
170171
name: "<white><bold>Spawners"
@@ -199,7 +200,7 @@ level:
199200
[id]
200201
id: "<gray>Block id: <yellow>[id]"
201202
value: "<gray>Block value: <yellow>[number]"
202-
underwater: "<gray>Bellow sea level: <yellow>[number]"
203+
underwater: "<gray>Below sea level: <yellow>[number]"
203204
limit: "<gray>Block limit: <yellow>[number]"
204205
# Button that is used in multi-page GUIs which allows to return to previous page.
205206
previous:

src/main/resources/locales/es.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ island:
5353
invalid-amount: "<red>Invalid amount. Use a positive number."
5454
empty: "<red>There are no valid blocks to donate."
5555
cancelled: "<yellow>Donation cancelled. Items returned."
56-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
56+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
5757
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
5858
cancel: "<green><bold>Cancel - Return Items"
5959
gui-title: "<black><bold>Donate Blocks"
60-
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!"
60+
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!"
6161
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6262
hand:
63-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
63+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
6464
not-block: "<red>You must be holding a placeable block to donate."
65+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
6566
detail:
6667
description: "muestra el detalle de los bloques de tu isla"
6768
top:

src/main/resources/locales/fr.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ island:
5555
invalid-amount: "<red>Invalid amount. Use a positive number."
5656
empty: "<red>There are no valid blocks to donate."
5757
cancelled: "<yellow>Donation cancelled. Items returned."
58-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
58+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
5959
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
6060
cancel: "<green><bold>Cancel - Return Items"
6161
gui-title: "<black><bold>Donate Blocks"
62-
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!"
62+
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!"
6363
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6464
hand:
65-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
65+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
6666
not-block: "<red>You must be holding a placeable block to donate."
67+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
6768
top:
6869
description: affiche le top 10
6970
gui-title: "<green>Top 10"

src/main/resources/locales/hu.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ island:
5656
invalid-amount: "<red>Invalid amount. Use a positive number."
5757
empty: "<red>There are no valid blocks to donate."
5858
cancelled: "<yellow>Donation cancelled. Items returned."
59-
success: "<green>Donated [number] blocks for <aqua>[points]<green>points! These points are permanent."
59+
success: "<green>Donated [number] blocks for <aqua>[points]<green> points! These points are permanent."
6060
confirm: "<red><bold>Confirm - Items will be DESTROYED!"
6161
cancel: "<green><bold>Cancel - Return Items"
6262
gui-title: "<black><bold>Donate Blocks"
63-
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!"
63+
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!"
6464
preview: "<yellow>Points to add: <gold>[points]|<red>These items will be destroyed!"
6565
hand:
66-
success: "<green>Donated [number] x [material] for <aqua>[points]<green>permanent points!"
66+
success: "<green>Donated [number] x [material] for <aqua>[points]<green> permanent points!"
6767
not-block: "<red>You must be holding a placeable block to donate."
68+
confirm-prompt: "<red>About to DESTROY <gold>[number] x [material]<red> for <aqua>[points]<red> permanent points."
6869
detail:
6970
description: "megmutatja a szigeted blokkjainak részleteit"
7071
top:

0 commit comments

Comments
 (0)