Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit b6e03de

Browse files
committed
fix item duplication bug with sendchest
1 parent 07a1c16 commit b6e03de

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/main/java/cat/nyaa/nyaautils/mailbox/MailboxCommands.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
261261

262262
plugin.mailboxListener.registerRightClickCallback(p, 100,
263263
(Location boxLocation) -> {
264-
if (boxLocation.equals(toLocationFinal)) {
265-
msg(p, "user.mailbox.same_src_dst");
266-
return;
267-
}
268264
if (!plugin.vaultUtil.enoughMoney(p, plugin.cfg.mailChestFee)) {
269265
msg(p, "user.mailbox.money_insufficient");
270266
return;
@@ -279,12 +275,14 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
279275

280276
Inventory fromInventory = ((InventoryHolder) b.getState()).getInventory();
281277
Inventory toInventory = ((InventoryHolder) toLocationFinal.getBlock().getState()).getInventory();
282-
ItemStack[] from = fromInventory.getStorageContents();
278+
ItemStack[] fromBefore = fromInventory.getStorageContents();
279+
ItemStack[] fromAfter = new ItemStack[fromBefore.length];
280+
fromInventory.setStorageContents(fromAfter);
283281
ItemStack[] to = toInventory.getStorageContents();
284282
int nextSlot = 0;
285283
boolean itemMoved = false;
286-
for (int i = 0; i < from.length; i++) {
287-
if (from[i] != null && from[i].getType() != Material.AIR) {
284+
for (int i = 0; i < fromBefore.length; i++) {
285+
if (fromBefore[i] != null && fromBefore[i].getType() != Material.AIR) {
288286
while (nextSlot < to.length && to[nextSlot] != null && to[nextSlot].getType() != Material.AIR) {
289287
nextSlot++;
290288
}
@@ -293,16 +291,15 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
293291
if (recpFinal != null) {
294292
msg(recpFinal, "user.mailbox.mailbox_no_space", sender.getName());
295293
}
294+
fromInventory.setStorageContents(fromBefore);
296295
return;
297296
}
298-
to[nextSlot] = from[i].clone();
297+
to[nextSlot] = fromBefore[i].clone();
299298
itemMoved = true;
300-
from[i] = new ItemStack(Material.AIR);
301299
nextSlot++;
302300
}
303301
}
304302
if (itemMoved) {
305-
fromInventory.setStorageContents(from);
306303
toInventory.setStorageContents(to);
307304
msg(sender, "user.mailbox.mail_sent", toPlayer, (float) plugin.cfg.mailChestFee);
308305
if (recpFinal != null) {

0 commit comments

Comments
 (0)