Skip to content

Commit

Permalink
Drop items that could not be stored
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied committed Jul 27, 2024
1 parent dd179b0 commit fd1b698
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class AdminItemsCommandHandler implements CommandHandler {

Expand Down Expand Up @@ -91,9 +92,15 @@ public void handle(CommandSender sender, String[] args) {
amount = Integer.parseInt(args[5]);
}
item.setAmount(amount);

// if we got this far, all was well.
// just give the item to the player already ;)
targetPlayer.getInventory().addItem(item);
Map<Integer, ItemStack> itemsToDrop = targetPlayer.getInventory().addItem(item);

// drop items that could not be stored
for (ItemStack itemToDrop : itemsToDrop.values()) {
targetPlayer.getWorld().dropItem(targetPlayer.getLocation(), itemToDrop);
}
}
}

Expand Down

0 comments on commit fd1b698

Please sign in to comment.