From ca13e3236ca44893381385c6c501bd71c1dd2a44 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 3 Apr 2021 21:47:58 +0200 Subject: [PATCH] Fix ItemFrameListener with Item in ItemFrame --- BauSystem_API/src/de/steamwar/bausystem/SWUtils.java | 3 +++ .../src/de/steamwar/bausystem/world/ItemFrameListener.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java index 693cd1f..5f22d5b 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java @@ -29,6 +29,9 @@ import java.util.List; public class SWUtils { public static void giveItemToPlayer(Player player, ItemStack itemStack) { + if (itemStack == null || itemStack.getType() == Material.AIR) { + return; + } for (int i = 0; i < player.getInventory().getSize(); i++) { ItemStack current = player.getInventory().getItem(i); if (current != null && current.isSimilar(itemStack)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ItemFrameListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ItemFrameListener.java index 645a078..eefcd23 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ItemFrameListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ItemFrameListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.world; +import de.steamwar.bausystem.SWUtils; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -36,7 +37,9 @@ public class ItemFrameListener implements Listener { return; } event.setCancelled(true); - event.getEntity().remove(); + ItemFrame itemFrame = (ItemFrame) event.getEntity(); + SWUtils.giveItemToPlayer((Player) event.getDamager(), itemFrame.getItem()); + itemFrame.remove(); } }