233 lines
6.6 KiB
Java
233 lines
6.6 KiB
Java
package com.rsscripting.rswarehouse.item;
|
|
|
|
import com.rsscripting.rswarehouse.dao.DamagedVariantsDAO;
|
|
import com.rsscripting.rswarehouse.dao.EnchantedVariantsDAO;
|
|
import com.rsscripting.rswarehouse.dao.PartiallyFilledVariantsDAO;
|
|
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
|
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
|
import com.rsscripting.rswarehouse.constants.RSKeys;
|
|
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.Damageable;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.enchantments.Enchantment;
|
|
import org.bukkit.inventory.ItemFlag;
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
|
|
public class TransactionVariantBuilder {
|
|
|
|
public static void addVariantButtons(
|
|
Inventory menu,
|
|
WarehouseItem warehouseItem
|
|
) {
|
|
|
|
/*
|
|
| Enchanted Variants Button
|
|
*/
|
|
|
|
if (
|
|
warehouseItem != null
|
|
&& warehouseItem.inventoryId() != null
|
|
) {
|
|
|
|
if (
|
|
EnchantedVariantsDAO.hasEnchantedVariants(
|
|
warehouseItem.inventoryId()
|
|
)
|
|
) {
|
|
|
|
ItemStack enchantedIcon =
|
|
ItemStackUtils.deserialize(
|
|
warehouseItem.serializedItem()
|
|
);
|
|
|
|
if (enchantedIcon != null) {
|
|
|
|
ItemMeta meta =
|
|
enchantedIcon.getItemMeta();
|
|
|
|
if (meta != null) {
|
|
|
|
meta.addEnchant(
|
|
Enchantment.UNBREAKING,
|
|
1,
|
|
true
|
|
);
|
|
|
|
meta.addItemFlags(
|
|
ItemFlag.HIDE_ENCHANTS
|
|
);
|
|
|
|
enchantedIcon.setItemMeta(
|
|
meta
|
|
);
|
|
|
|
}
|
|
|
|
ItemStack menuIcon =
|
|
RSMenuUtils.createMenuItem(
|
|
enchantedIcon,
|
|
"§eView Enchanted Variants"
|
|
);
|
|
|
|
ItemMeta menuMeta =
|
|
menuIcon.getItemMeta();
|
|
|
|
menuMeta.getPersistentDataContainer().set(
|
|
RSKeys.ENCHANTED_VARIANT_ID,
|
|
PersistentDataType.INTEGER,
|
|
warehouseItem.inventoryId()
|
|
);
|
|
|
|
if (menuMeta != null) {
|
|
|
|
menuMeta.addItemFlags(
|
|
ItemFlag.HIDE_ATTRIBUTES
|
|
);
|
|
|
|
menuIcon.setItemMeta(
|
|
menuMeta
|
|
);
|
|
|
|
}
|
|
|
|
menu.setItem(
|
|
1,
|
|
menuIcon
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
else if (
|
|
PartiallyFilledVariantsDAO.hasPartiallyFilledVariants(
|
|
warehouseItem.inventoryId()
|
|
)
|
|
) {
|
|
|
|
ItemStack partiallyFilledIcon =
|
|
ItemStackUtils.deserialize(
|
|
warehouseItem.serializedItem()
|
|
);
|
|
|
|
if (partiallyFilledIcon != null) {
|
|
|
|
ItemStack menuIcon =
|
|
RSMenuUtils.createMenuItem(
|
|
partiallyFilledIcon,
|
|
"§eView Partially Filled Variants"
|
|
);
|
|
|
|
ItemMeta menuMeta =
|
|
menuIcon.getItemMeta();
|
|
|
|
menuMeta.getPersistentDataContainer().set(
|
|
RSKeys.PARTIALLY_FILLED_VARIANT_ID,
|
|
PersistentDataType.INTEGER,
|
|
warehouseItem.inventoryId()
|
|
);
|
|
|
|
if (menuMeta != null) {
|
|
|
|
menuMeta.addItemFlags(
|
|
ItemFlag.HIDE_ATTRIBUTES,
|
|
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
|
);
|
|
|
|
menuIcon.setItemMeta(
|
|
menuMeta
|
|
);
|
|
|
|
}
|
|
|
|
menu.setItem(
|
|
2,
|
|
menuIcon
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| VARIANTS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
if (
|
|
warehouseItem != null
|
|
&& warehouseItem.inventoryId() != null
|
|
&& DamagedVariantsDAO.hasDamagedVariants(
|
|
warehouseItem.inventoryId()
|
|
)
|
|
) {
|
|
|
|
ItemStack damagedIcon =
|
|
ItemStackUtils.deserialize(
|
|
warehouseItem.serializedItem()
|
|
);
|
|
|
|
if (damagedIcon == null) {
|
|
|
|
damagedIcon = new ItemStack(Material.ANVIL);
|
|
|
|
}
|
|
|
|
if (damagedIcon.getItemMeta() instanceof Damageable damageable) {
|
|
|
|
int maxDurability = damagedIcon.getType().getMaxDurability();
|
|
|
|
damageable.setDamage(maxDurability / 2);
|
|
|
|
damagedIcon.setItemMeta(damageable);
|
|
|
|
} else {
|
|
|
|
damagedIcon = new ItemStack(Material.ANVIL);
|
|
|
|
}
|
|
|
|
ItemStack menuIcon =
|
|
RSMenuUtils.createMenuItem(
|
|
damagedIcon,
|
|
"§eView Damaged Variants"
|
|
);
|
|
|
|
ItemMeta menuMeta =
|
|
menuIcon.getItemMeta();
|
|
|
|
if (menuMeta != null) {
|
|
|
|
menuMeta.addItemFlags(
|
|
ItemFlag.HIDE_ATTRIBUTES
|
|
);
|
|
|
|
menuMeta.getPersistentDataContainer().set(
|
|
RSKeys.DAMAGED_VARIANT_ID,
|
|
PersistentDataType.INTEGER,
|
|
warehouseItem.inventoryId()
|
|
);
|
|
|
|
menuIcon.setItemMeta(
|
|
menuMeta
|
|
);
|
|
|
|
}
|
|
|
|
menu.setItem(
|
|
0,
|
|
menuIcon
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|