mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Adds unstackable boolean stat.
This commit is contained in:
parent
8543632a2f
commit
515bfc48e2
@ -1,21 +1,5 @@
|
|||||||
package net.Indyuce.mmoitems.gui;
|
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.MMOItems;
|
||||||
import net.Indyuce.mmoitems.MMOUtils;
|
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.item.NBTItem;
|
||||||
import net.mmogroup.mmolib.api.util.AltChar;
|
import net.mmogroup.mmolib.api.util.AltChar;
|
||||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
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 {
|
public class ItemBrowser extends PluginInventory {
|
||||||
private final Map<String, ItemStack> cached = new HashMap<>();
|
private final Map<String, ItemStack> cached = new HashMap<>();
|
||||||
@ -271,7 +271,10 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
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);
|
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
package net.Indyuce.mmoitems.gui.listener;
|
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.MMOUtils;
|
||||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||||
import net.Indyuce.mmoitems.gui.ItemBrowser;
|
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.EditionInventory;
|
||||||
import net.Indyuce.mmoitems.gui.edition.ItemEdition;
|
import net.Indyuce.mmoitems.gui.edition.ItemEdition;
|
||||||
import net.Indyuce.mmoitems.gui.edition.RecipeEdition;
|
import net.Indyuce.mmoitems.gui.edition.RecipeEdition;
|
||||||
|
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||||
import net.mmogroup.mmolib.api.util.AltChar;
|
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 {
|
public class GuiListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -42,9 +42,15 @@ public class GuiListener implements Listener {
|
|||||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.fourEdgedClub + " Get the Item! " + AltChar.fourEdgedClub)) {
|
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.fourEdgedClub + " Get the Item! " + AltChar.fourEdgedClub)) {
|
||||||
|
|
||||||
// simply give the item if left click
|
// 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())
|
for (ItemStack drop : player.getInventory().addItem(event.getInventory().getItem(4)).values())
|
||||||
player.getWorld().dropItemNaturally(player.getLocation(), drop);
|
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
|
// reroll stats if right click
|
||||||
else if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
else if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||||
|
26
src/main/java/net/Indyuce/mmoitems/stat/Unstackable.java
Normal file
26
src/main/java/net/Indyuce/mmoitems/stat/Unstackable.java
Normal file
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -157,7 +157,7 @@ public abstract class ItemStat {
|
|||||||
VersionMaterial.SKELETON_SKULL.toItem(), "Undead Damage",
|
VersionMaterial.SKELETON_SKULL.toItem(), "Undead Damage",
|
||||||
new String[] { "Deals additional damage to undead.", "In %." });
|
new String[] { "Deals additional damage to undead.", "In %." });
|
||||||
public static final ItemStat UNBREAKABLE = new Unbreakable(), TIER = new ItemTierStat(), SET = new ItemSetStat(),
|
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(),
|
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." });
|
"Max Mana", new String[] { "Adds mana to your max mana bar." });
|
||||||
public static final ItemStat KNOCKBACK_RESISTANCE = new KnockbackResistance(), MOVEMENT_SPEED = new MovementSpeed();
|
public static final ItemStat KNOCKBACK_RESISTANCE = new KnockbackResistance(), MOVEMENT_SPEED = new MovementSpeed();
|
||||||
|
Loading…
Reference in New Issue
Block a user