33import com .google .common .collect .Lists ;
44import net .kyori .adventure .text .Component ;
55import org .bukkit .Bukkit ;
6+ import org .bukkit .Location ;
67import org .bukkit .Material ;
8+ import org .bukkit .World ;
79import org .bukkit .enchantments .Enchantment ;
810import org .bukkit .entity .Player ;
911import org .bukkit .inventory .Inventory ;
@@ -589,7 +591,7 @@ public static ItemStack getEnchantedBook(Map<Enchantment, Integer> map) {
589591 * @param player 玩家
590592 * @param items 物品列表
591593 */
592- public static void giveItemToPlayer (final Player player , final List <ItemStack > items ) {
594+ public static void giveItemToPlayer (Player player , List <ItemStack > items ) {
593595 giveItemToPlayer (player , items .toArray (new ItemStack [0 ]));
594596 }
595597
@@ -598,7 +600,7 @@ public static void giveItemToPlayer(final Player player, final List<ItemStack> i
598600 * @param player 玩家
599601 * @param items 物品列表
600602 */
601- public static void giveItemToPlayer (final Player player , final ItemStack ... items ) {
603+ public static void giveItemToPlayer (Player player , ItemStack ... items ) {
602604 giveItemToPlayer (player , "" , "" , items );
603605 }
604606
@@ -609,8 +611,7 @@ public static void giveItemToPlayer(final Player player, final ItemStack... item
609611 * @param msgFull 玩家背包已满时,发送的额外消息
610612 * @param items 物品列表
611613 */
612- public static void giveItemToPlayer (final Player player , final String msg , final String msgFull ,
613- final List <ItemStack > items ) {
614+ public static void giveItemToPlayer (Player player , String msg , String msgFull , List <ItemStack > items ) {
614615 giveItemToPlayer (player , msg , msgFull , items .toArray (new ItemStack [0 ]));
615616 }
616617
@@ -621,15 +622,23 @@ public static void giveItemToPlayer(final Player player, final String msg, final
621622 * @param msgFull 玩家背包已满时,发送的额外消息
622623 * @param items 物品列表
623624 */
624- public static void giveItemToPlayer (final Player player , final String msg , final String msgFull ,
625- final ItemStack ... items ) {
626- final Collection <ItemStack > last = player .getInventory ().addItem (items ).values ();
625+ public static void giveItemToPlayer (Player player , String msg , String msgFull , ItemStack ... items ) {
626+ Collection <ItemStack > last = player .getInventory ().addItem (items ).values ();
627627 if (!msg .isEmpty () || (!last .isEmpty () && !msgFull .isEmpty ())) {
628628 t (player , msg + (last .isEmpty () ? "" : ("\n &r" + msgFull )));
629629 }
630- for (final ItemStack item : last ) {
631- player .getWorld ().dropItem (player .getLocation (), item );
632- }
630+ if (last .isEmpty ()) return ;
631+ World world = player .getWorld ();
632+ Location location = player .getLocation ();
633+ Location loc = new Location (world , location .getBlockX () + 0.5 , location .getY () + 1.0 , location .getBlockZ () + 0.5 );
634+ BukkitPlugin .getInstance ().getScheduler ().runAtLocation (loc , () -> {
635+ for (ItemStack item : last ) {
636+ if (item == null || item .getType ().equals (Material .AIR ) || item .getAmount () <= 0 ) {
637+ continue ;
638+ }
639+ world .dropItem (loc , item );
640+ }
641+ });
633642 }
634643
635644}
0 commit comments