diff --git a/src/main/java/xyz/mackan/Slabbo/GUI/ShopCreationGUI.java b/src/main/java/xyz/mackan/Slabbo/GUI/ShopCreationGUI.java index c6a77bc..0a544d2 100644 --- a/src/main/java/xyz/mackan/Slabbo/GUI/ShopCreationGUI.java +++ b/src/main/java/xyz/mackan/Slabbo/GUI/ShopCreationGUI.java @@ -201,9 +201,9 @@ public void onInventoryClick(final InventoryClickEvent e) { } - ItemUtil.dropShopItem(slabLocation, shopItem); + ItemUtil.dropShopItem(slabLocation, shopItem, quantity); } else { - ItemUtil.dropShopItem(slabLocation, shopItem); + ItemUtil.dropShopItem(slabLocation, shopItem, quantity); } p.playSound(this.slabLocation, SlabboSound.MODIFY_SUCCESS.sound, SoundCategory.BLOCKS, 1, 1); diff --git a/src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java b/src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java index eddecde..398836e 100644 --- a/src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java +++ b/src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java @@ -70,7 +70,7 @@ public void onReload (Player player) { String key = shopEntry.getKey(); Shop shop = shopEntry.getValue(); - ItemUtil.dropShopItem(shop.location, shop.item); + ItemUtil.dropShopItem(shop.location, shop.item, shop.quantity); Slabbo.shopUtil.put(key, shop); } @@ -176,7 +176,7 @@ public void onImportShops(Player player, String type, String file) { } for (Shop shop : result.shops) { - ItemUtil.dropShopItem(shop.location, shop.item); + ItemUtil.dropShopItem(shop.location, shop.item, shop.quantity); Slabbo.shopUtil.put(shop.getLocationString(), shop); } diff --git a/src/main/java/xyz/mackan/Slabbo/listeners/InventoryClickListener.java b/src/main/java/xyz/mackan/Slabbo/listeners/InventoryClickListener.java index b48b34b..b0d0c67 100644 --- a/src/main/java/xyz/mackan/Slabbo/listeners/InventoryClickListener.java +++ b/src/main/java/xyz/mackan/Slabbo/listeners/InventoryClickListener.java @@ -111,7 +111,16 @@ public void run () { @EventHandler public void onInventoryDrag (InventoryDragEvent e) { - Block chestBlock = e.getInventory().getLocation().getBlock(); // TODO check this + Inventory inv = e.getInventory(); + + if (inv == null) return; + + Location invLocation = inv.getLocation(); + + if (invLocation == null) return; + + + Block chestBlock = invLocation.getBlock(); // TODO check this if (chestBlock == null) return; diff --git a/src/main/java/xyz/mackan/Slabbo/utils/ItemUtil.java b/src/main/java/xyz/mackan/Slabbo/utils/ItemUtil.java index 2dd9d19..62a593c 100644 --- a/src/main/java/xyz/mackan/Slabbo/utils/ItemUtil.java +++ b/src/main/java/xyz/mackan/Slabbo/utils/ItemUtil.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import xyz.mackan.Slabbo.Slabbo; import xyz.mackan.Slabbo.types.AttributeKey; import java.util.Collection; @@ -39,7 +40,7 @@ public static double getSlabYOffset (Location location) { } } - public static void dropShopItem (Location location, ItemStack item) { + public static void dropShopItem (Location location, ItemStack item, int quantity) { Location dropLocation = location.clone(); dropLocation.add(0.5, getSlabYOffset(location), 0.5); @@ -47,7 +48,16 @@ public static void dropShopItem (Location location, ItemStack item) { ItemStack clonedItem = item.clone(); ItemMeta meta = clonedItem.getItemMeta(); - clonedItem.setAmount(64); + String displayType = Slabbo.getInstance().getConfig().getString("itemdisplay", "quantity"); + + if (displayType.equalsIgnoreCase("quantity")) { + if (quantity < 1) quantity = 1; + if (quantity > 64) quantity = 64; + + clonedItem.setAmount(quantity); + } else { + clonedItem.setAmount(64); + } meta.getPersistentDataContainer().set(AttributeKey.NO_PICKUP.getKey(), PersistentDataType.INTEGER, 1); meta.getPersistentDataContainer().set(AttributeKey.NO_DESPAWN.getKey(), PersistentDataType.INTEGER, 1); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a1e929b..6718b21 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,4 +10,6 @@ chestlinks: # Linking chests enabled: true savetime: 5 -checkupdates: true \ No newline at end of file +itemdisplay: quantity # Quantity (The amount the shop sells) / Full (A full stack (64 items)) + +checkupdates: true