diff --git a/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java b/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java index 7dd067f8..9e7bfd6d 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java @@ -1,21 +1,5 @@ package net.Indyuce.mmoitems.gui; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -28,6 +12,22 @@ import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.item.NBTItem; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ItemBrowser extends PluginInventory { private final Map cached = new HashMap<>(); @@ -271,7 +271,10 @@ public class ItemBrowser extends PluginInventory { } else { if (event.getAction() == InventoryAction.PICKUP_ALL) { - player.getInventory().addItem(removeLastLoreLines(item, 3)); + ItemStack generatedItem = (NBTItem.get(item).getBoolean("UNSTACKABLE")) // this refreshes the item if it's unstackable + ? MMOItems.plugin.getItems().getMMOItem(type, id).clone().newBuilder().build() + : item; + player.getInventory().addItem(removeLastLoreLines(generatedItem, 3)); player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); } diff --git a/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java b/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java index 987b6e0d..133766b4 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java @@ -1,13 +1,5 @@ package net.Indyuce.mmoitems.gui.listener; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.api.item.MMOItem; import net.Indyuce.mmoitems.gui.ItemBrowser; @@ -16,7 +8,15 @@ import net.Indyuce.mmoitems.gui.edition.CraftingEdition; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import net.Indyuce.mmoitems.gui.edition.RecipeEdition; +import net.mmogroup.mmolib.api.item.NBTItem; import net.mmogroup.mmolib.api.util.AltChar; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; public class GuiListener implements Listener { @EventHandler @@ -42,9 +42,15 @@ public class GuiListener implements Listener { if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.fourEdgedClub + " Get the Item! " + AltChar.fourEdgedClub)) { // simply give the item if left click - if (event.getAction() == InventoryAction.PICKUP_ALL) + if (event.getAction() == InventoryAction.PICKUP_ALL){ for (ItemStack drop : player.getInventory().addItem(event.getInventory().getItem(4)).values()) player.getWorld().dropItemNaturally(player.getLocation(), drop); + if (NBTItem.get(event.getInventory().getItem(4)).getBoolean("UNSTACKABLE")) { // this refreshes the item if it's unstackable + ((EditionInventory) inventory).updateCachedItem(); + event.getInventory().setItem(4, ((EditionInventory) inventory).getCachedItem()); + } + } + // reroll stats if right click else if (event.getAction() == InventoryAction.PICKUP_HALF) { diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Unstackable.java b/src/main/java/net/Indyuce/mmoitems/stat/Unstackable.java new file mode 100644 index 00000000..22ec9a04 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/Unstackable.java @@ -0,0 +1,26 @@ +package net.Indyuce.mmoitems.stat; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.data.BooleanData; +import net.Indyuce.mmoitems.stat.data.type.StatData; +import net.Indyuce.mmoitems.stat.type.BooleanStat; +import net.mmogroup.mmolib.api.item.ItemTag; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.UUID; + +public class Unstackable extends BooleanStat { + + public Unstackable() { + super("UNSTACKABLE", new ItemStack(Material.CHEST_MINECART), "Unstackable", new String[] { "This will make the item unable", "to be stacked with itself."}, new String[] { "all" }); + } + + @Override + public void whenApplied(MMOItemBuilder item, StatData data) { + if (((BooleanData) data).isEnabled()) { + item.addItemTag(new ItemTag("UNSTACKABLE", true)); + item.addItemTag(new ItemTag("UNSTACKABLE_UUID", UUID.randomUUID().toString())); + } + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java index cffd7903..8d9fb93a 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java @@ -157,7 +157,7 @@ public abstract class ItemStat { VersionMaterial.SKELETON_SKULL.toItem(), "Undead Damage", new String[] { "Deals additional damage to undead.", "In %." }); public static final ItemStat UNBREAKABLE = new Unbreakable(), TIER = new ItemTierStat(), SET = new ItemSetStat(), - ARMOR = new Armor(), ARMOR_TOUGHNESS = new ArmorToughness(), MAX_HEALTH = new MaxHealth(); + ARMOR = new Armor(), ARMOR_TOUGHNESS = new ArmorToughness(), MAX_HEALTH = new MaxHealth(), UNSTACKABLE = new Unstackable(); public static final ItemStat MAX_MANA = new DoubleStat("MAX_MANA", VersionMaterial.LAPIS_LAZULI.toItem(), "Max Mana", new String[] { "Adds mana to your max mana bar." }); public static final ItemStat KNOCKBACK_RESISTANCE = new KnockbackResistance(), MOVEMENT_SPEED = new MovementSpeed();