From 613b5d3f7539eb202a2181afd7bb5a404024c679 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 23:00:00 +0200 Subject: [PATCH] Improve SWUtils.giveItemToPlayer --- BauSystem_API/src/de/steamwar/bausystem/SWUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java index e5b2468..693cd1f 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java @@ -29,6 +29,14 @@ import java.util.List; public class SWUtils { public static void giveItemToPlayer(Player player, ItemStack itemStack) { + for (int i = 0; i < player.getInventory().getSize(); i++) { + ItemStack current = player.getInventory().getItem(i); + if (current != null && current.isSimilar(itemStack)) { + player.getInventory().setItem(i, null); + itemStack = current; + break; + } + } ItemStack current = player.getInventory().getItemInMainHand(); player.getInventory().setItemInMainHand(itemStack); if (current.getType() != Material.AIR) {