From 0327eb37c4700c82ebedb2df7786f8766970d886 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 2 Feb 2021 23:26:01 +0100 Subject: [PATCH] Add Support for Itemstack --- .../de/steamwar/inventory/SWInventory.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java index c96c3c4..7de1c87 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java @@ -28,11 +28,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class SWInventory implements Listener { @@ -55,9 +53,13 @@ public class SWInventory implements Listener { callbacks.put(-1, c); } + public void setItem(int pos, ItemStack itemStack, InvCallback c){ + inventory.setItem(pos, itemStack); + callbacks.put(pos, c); + } + public void setItem(int pos, SWItem item){ - inventory.setItem(pos, item.getItemStack()); - callbacks.put(pos, item.getCallback()); + setItem(pos, item.getItemStack(), item.getCallback()); } public void setItem(int pos, Material m, String name, InvCallback c){ @@ -91,9 +93,10 @@ public class SWInventory implements Listener { if(!player.equals(e.getWhoClicked())) return; - e.setCancelled(true); - if(callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) + if(callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) { + e.setCancelled(true); callbacks.get(e.getRawSlot()).clicked(e.getClick()); + } } @EventHandler