Initial release v1.0.0
This commit is contained in:
commit
3fef65b903
314 files changed
+27448
No files matched your search
@@ -0,0 +1,232 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.variants.dao.DamagedVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.variants.dao.EnchantedVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.variants.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
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user