From 074c786c35c14638019591332a2001f87c5a7c1c Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:36:38 +0000 Subject: [PATCH] Don't allow purchase if inv if full --- .../mineplex/gemhunters/shop/TraderNPC.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 47576c345..4db8482fe 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -1,5 +1,6 @@ package mineplex.gemhunters.shop; +import java.util.List; import java.util.Set; import org.bukkit.Location; @@ -16,6 +17,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.gemhunters.economy.EconomyModule; @@ -102,9 +104,25 @@ public class TraderNPC extends SimpleNPC player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); return; } + + if (!UtilInv.HasSpace(player, itemStack.getType(), itemStack.getAmount())) + { + player.sendMessage(F.main(_entity.getCustomName(), "I'm sorry you don't have enough space to hold that.")); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); + return; + } _economy.removeFromStore(player, cost); + // Remove cost lore + ItemBuilder builder = new ItemBuilder(itemStack); + + List lore = builder.getLore(); + lore.remove(lore.size() - 1); + builder.setLore(lore.toArray(new String[0])); + + itemStack = builder.build(); + String itemName = ItemStackFactory.Instance.GetName(itemStack, true); player.sendMessage(F.main(_entity.getCustomName(), "Purchased " + F.elem(itemName) + "!"));